Automating generation of qm files

From Qt Wiki
Revision as of 14:00, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Automating Generation of QM Files

The Qt Linguist Manual [qt.io] and Qt reference documentation [qt.io] describe the localization process in detail. However, you can use an alternative (unofficial) way to register TS files for the languages listed in the .pro file and to generate the QM files from them. This method is used by the Qt Creator project and the Quick Forecast demo application, for example.

First, you specify the languages as values of the LANGUAGES variable using the language codes:

Second, you add a function to generate a TS file for each language. In the following code example, the application name is QuickForecast:

Third, you add the TRANSLATIONS_FILES variable and run lrelease to generate the QM files and to embed them in the application resources:

Adding qmake Targets for Convenience

You can further automate the process for creating TS files and committing them to the Git version control system by adding qmake extra targets. The following code generates a generic TS file, using the QuickForecast application as an example. You need to rename the generated QuickForecast_untranslated.ts using the appropriate language code (for example, as QuickForecast_de.ts) and add the language code as a value of the LANGUAGES variable.

The following code makes a new target for lconvert and commits the TS files. Use lconvert to remove information about the location of strings in the TS files and thus save space: