Qt Localization with a variable -


i translate weather conditions in code having little trouble.

example:

english - cloudy

french - nuageux

weatherstring = hash["weather"]; weatherbytes = weatherstring.tolocal8bit(); weatherchararray = weatherbytes.data();  qdebug() << "current weather: " << qobject::tr(weatherchararray); 

the weather comes in web service it's different. knew code above not create entries automatically in .ts files known @ runtime, tried manually enter them.

<message> <source>cloudy</source> <translation>nuageux</translation> </message> 

but everytime compile puts in:

type="obsolete" 

in translation tag, should do??

here 1 of ways have implemented solution problem.

// setup (in constructor before use of mytr function this->availabletranslations(); 

in cpp file...

qmap <qstring, qstring> settingswidget::trmap;  void settingswidget::availabletranslations() {      if(trmap.size() != 0)           return;      trmap["true"] = tr("true","settings option");      trmap["false"] = tr("false","settings option");      trmap["auto"] = tr("auto","settings option");      trmap["none"] = tr("none","settings option");      trmap["smallest"] = tr("smallest","settings option");      trmap["very small"] = tr("very small","settings option");      trmap["small"] = tr("small","settings option");      trmap["medium"] = tr("medium","settings option");      trmap["large"] = tr("large","settings option");      trmap["very large"] = tr("very large","settings option");      trmap["advanced"] = tr("advanced","settings option");      trmap["basic"] = tr("basic","settings option"); }  qstring settingswidget::mytr(qstring s) {      if(trmap.contains(s))           return trmap[s];//qapp->translate("settingswidget",qprintable(s));      else           return s; } 

then when using above on fly looks this:

// in use mytr(list.at(currindex)); 

you notice setup, can translation based on variable instead of char *, , puts in translation file without work or maintenance.

hope helps.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -