Qt just loads the translations of UI strings but not strings in the code -


i have lot of form , strings in project translatable strings boxed in tr() function. translated of strings linguist, when load correspond qm file, strings in ui being translated.

for example, if had form containing label "hello world!" text, translated "olleh dlrow!"(just say). in code if wrote:

if ( condition )     ui.settitle(tr("mainwindow")); else     ui.settitle(tr("secondarywindow")); 

no translation of mainwindow or secondarywindow done , original text shown.

any idea? in advanced.

i want explain solution in situation me. consider have class named myform. defined namspace project called mynmespace.

/*    myform.cpp    */  using namespace mynmespace;  myform::myform(qwidget* parent):qmainwindow(parent) {} 

1) if user wraps strings in tr() function, won't translated. enabling translation, must use qapplication::translate("classname", "str", 0, qapplication::unicodeutf8) like:

/*    myform.cpp approach 1   */  using namespace mynmespace;  myform::myform(qwidget* parent):qmainwindow(parent) {     bool condition; /* sth */      if ( condition )         // ui.setwindowtitle(tr("mainwindow"));  <= won't work         ui.setwindowtitle(qapplication::translate("myform", "mainwindow", 0, qapplication::unicodeutf8));     else         // ui.setwindowtitle(tr("secondarywindow"));  <= won't work         ui.setwindowtitle(qapplication::translate("myform", "secondarywindow", 0, qapplication::unicodeutf8)); } 

in approach translations in .ts file written myform in each entry.

2) remove using namespace mynmespace; beggining of myform.cpp , specify scope like:

/*    myform.cpp approach 2   */  mynmespace::myform::myform(qwidget* parent):qmainwindow(parent) {     bool condition; /* sth */      if ( condition )         ui.setwindowtitle(tr("mainwindow"));  // works     else         ui.setwindowtitle(tr("secondarywindow"));  // works } 

in approach translations in .ts file written mynmespace::myform in each entry.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -