[Solved] Localized strings not showing up in QML UI
-
wrote on 21 Sept 2011, 23:23 last edited by
For the first time I have gone through the bumps to get i18n support for our Qt Quick app. In short: after creating ts and qm files for Spanish the app still shows the engineering English strings.
The QML specific documentation is surprisingly dry and simplistic (just a hello qml file translated in one languagen - no mention to pro or qrc files), linking to the very extensive documentation in plain Qt where a QML dude like me gets easily lost. What I've done:
1 - Introduced qsTr() in all text strings.
2 - Created .ts file with lupdate.
3 - Translated using Qt Linguistic.
4 - Created .qm file with lrelease.The files look good, I can see the translations inserted in the .ts file and Qt Linguist identifies it as a es_Es file (Spanish from Spain).
Then I deployed to the N9 booted in Spanish(Spain). English strings would still appear.
Then I tried several things:
-
Our project has more than one .pro file. I tried adding the TRANSLATIONS entry in the generic miniature.pro or the src.pro managine the folder where the qml and ts/qm files are found. Nothing.
-
Even if the docs I found made no mention about adding the files to the qrc file I tried to add them just in case that helped. Nothing either.
At this point I'm out of ideas. Just in case you need more details, the commit with all the i18n changes can be found "here":http://gitorious.org/miniature/miniature/commit/0ee746a4dc01b4fd44b1c9ee34bdf0529560940e. Thanks!
-
-
wrote on 21 Sept 2011, 23:38 last edited by
Hi,
Typically you will need to create and install a QTranslator (in your C++ main) that uses the translation file you have created. The QTranslator docs show a very basic example of this.
In your case it also sounds like you'd like the translation to be automatically loaded based on the locale of the device. Step 7 of http://wiki.meego.com/QML/Internationalisation shows an example of this -- basically the file loaded by the translator should be based on information you can obtain from QLocale.
Regards,
Michael -
wrote on 22 Sept 2011, 05:37 last edited by
Al·leluia! Yes, that works.
Thanks mbrasser, the beer that I owe you keeps growing...
http://wiki.meego.com/QML/Internationalisation is a great page and I happen to know its author Elliot Smith. More beer to go!
1/3