Qt Translation returns the same string instead of translation

I am having a weird Qt translation problem.

Due to reasons that I cannot change that are related to outdated translation table databases, our "natural language" is Enumerations.

QString myString = tr("OUR_APP_MY_STRING");

I have a script that creates * .TS files from our databases that Qt will use.

The entry in * .TS files for English is as follows:

<message>
    <source>OUR_APP_MY_STRING</source>
    <translation>My String</translation>
</message>

The * .TS file is uploaded to Qt Linguist. Everything looks great there. "OUR_APP_MY_STRING" is found and its "English translation" looks fine.

The QT project file has * .TS files in TRANSLATION sections. I use lRelease to create .QM files and place them in the application resource file (.qrc).

( main() ) :

// initialize translator
this->currentTranslator = new QTranslator(instance());

if (this->currentTranslator->load(":/translation/myApp_en.qm"))
{
  this->installTranslator(this->currentTranslator);
  QString test = tr("OUR_APP_MY_STRING");  // <<----- problem. output is always "OUR_APP_MY_STRING"

}

?

+3
1

, instance()

 this->currentTranslator = new QTranslator(instance());

, , :

  • - YourProjectName.pro?
RESOURCES += \
   resources.qrc 

(resources.qrc - , . , .)

  • resources.qrc? , translation/? :
  <RCC>
    <qresource prefix="/">
      <file>translation/YourProjectName_en.qm</file>
      <!-- other resources here -->
    </qresource>
  </RCC>

YourProjectName_en.qm translation/.

, ;:

main.cpp:

 QApplication app(argc, argv);
 QApplication::setApplicationName("MyApplication");
 QApplication::setApplicationVersion("4.4");
 QApplication::setOrganizationName("FUBAR");
 QApplication::setOrganizationDomain("www.fu.bar");

 QTranslator translator;
 translator.load(app.applicationName() + "_" + QLocale::system().name(), ":/ts");
 app.installTranslator(&translator);

resources.qrc:

<RCC>
   <qresource prefix="/">
     <file>resources/pixmaps/exit.png</file>
     <!-- ... -->
     <file>ts/MyApplication_en.qm</file>
     <file>ts/MyApplication_es.qm</file>
   </qresource>
</RCC>

in MyApplication.pro:

 TRANSLATIONS += \
   ts/MyApplication_en.ts \
   ts/MyApplication_es.ts

 RESOURCES += \
   resources.qrc

 win32 {
   RC_FILE = win32.rc
 }

 OTHER_FILES += \
     win32.rc \
     TODO.txt

:

MyApplication
 β”œβ”€β”€ resources
 β”‚   β”œβ”€β”€ pixmaps
 β”‚   └── ...
 β”œβ”€β”€ (sources are here)
 β”œβ”€β”€ MyApplication.pro
 β”œβ”€β”€ resources.qrc
 β”œβ”€β”€ TODO.txt
 β”œβ”€β”€ ts
 β”‚   β”œβ”€β”€ MyApplication_en.qm
 β”‚   β”œβ”€β”€ MyApplication_en.ts
 β”‚   β”œβ”€β”€ MyApplication_es.qm
 β”‚   └── MyApplication_es.ts
 └── win32.rc

, .

Edit:

, , . ,

 if (this->currentTranslator->load(":/translation/myApp_en.qm"))

 if (this->currentTranslator->load("myApp_en.qm", ":/translation/"))
+6

All Articles