[Qt-interest] Translation of text taken from db

KC Jones kc at asperasoft.com
Wed Oct 28 17:10:14 CET 2009


Assuming it is a fixed set of strings that is known at compile time,
you could force them to appear in code by defining a map from the
untranslated string to the localized one and use that to translate.
Costs time and RAM, but if the string table is not too large it would
work.  I have a small set of keywords in a db table that I plan to use
this approach for.

class Foo {
[...]
public:
    Foo() {
      if (xlate.isEmpty()) {
        xlate["stop"]=tr("stop");
        xlate["go"]=tr("go");
        // etc....
      }
    }
    QString xlate(const QString& dbstring) const
    {
      return xlate[dbstring]; // maybe add code to check existence of
string in table...
    }
private:
    static QHash<QString, QString> xlate;
}
QHash<QString, QString> Foo::xlate;


On Wed, Oct 28, 2009 at 3:25 AM, Ender EREL <erelender at yahoo.com> wrote:
> Hi folks,
>
> My situation is this: I have a database containing the names of certain
> criteria, which have identifier strings. What i want to achieve is when
> i take these identifiers from db, i want to translate them using
> QTranslator. But since these strings appear nowhere in the code, they
> don't come up when i run lupdate. I want to put those strings
> out-of-context in the translation file and when they are recieved from
> Db, translate them using QObject::tr().
>
> Is there a way to achieve this?
>
> Best Regards.
>
> --
> Ender EREL
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list