Deploy QML app to devices with languages files
-
Yes, use Qt Resource Files for your translations (QM files).
-
-
@sharath
I do use the qm files for translation, and I have followed the post you gave.
But on the target it is look for the qm file on the target but as I deploy them from Qt creator they are not deployed on the target. I'm looking for a way to deploy them as well. My translation is working nicely -
As said, use QRC. Your QM files will be compiled into the executable - they will always be there, without any need to search for them in directory tree.
-
Here is the .pro side :
RESOURCES += qml.qrc \ image.qrc \ font.qrc \ #this is the one with my qm files language.qrc TRANSLATIONS = Langues/lang_en_US.ts \ Langues/lang_fr_FR.ts \ Langues/lang_de_DE.ts \ Langues/lang_da_DA.ts \ Langues/lang_es_ES.ts \ Langues/lang_pl_PL.ts \ Langues/lang_cz_CZ.ts lupdate_only{ *.qml }
The cpp side is the quite the same as the one in the link provided by sharath (the empty string as well because I use Qt 5.6.3 can't upgrade it)
-
@DavidM29 said in Deploy QML app to devices with languages files:
Then I don't understand why it does not work. I do have the qrc file, the qm file and the translator cpp side. Everything works fine when I add manually the files.
You need to put QM files inside your QRC file. You have to do it yourself, Qt won't magically do it for you. Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).
-
@sierdzio
I did here is my qrc file :<RCC> <qresource prefix="/"> <file>Langues/lang_fr_FR.qm</file> <file>Langues/lang_en_US.qm</file> <file>Langues/lang_cz_CZ.qm</file> <file>Langues/lang_da_DA.qm</file> <file>Langues/lang_de_DE.qm</file> <file>Langues/lang_es_ES.qm</file> <file>Langues/lang_pl_PL.qm</file> </qresource> </RCC>
-
@J.Hilk said in Deploy QML app to devices with languages files:
@DavidM29 please show us how you load the translation file
@sierdzio said in Deploy QML app to devices with languages files:
Then you need to use proper QRC paths to load the translations (so `":/path/to/file.qm" instead of normal filesystem path).
-
@DavidM29 said in Deploy QML app to devices with languages files:
@sierdzio
I did here is my qrc file :<RCC> <qresource prefix="/"> <file>Langues/lang_fr_FR.qm</file> <file>Langues/lang_en_US.qm</file> <file>Langues/lang_cz_CZ.qm</file> <file>Langues/lang_da_DA.qm</file> <file>Langues/lang_de_DE.qm</file> <file>Langues/lang_es_ES.qm</file> <file>Langues/lang_pl_PL.qm</file> </qresource> </RCC>
OK great. Now the paths in your .cpp code have to refer to these files instead of OS filesystem.
-
It's been a while now, but I will add things on this topic.
All proposed solutions made me sceptic as .tr are the sources file (as .cpp) and .qm are binary (as .o). So you're supposed to save the sources on a git, and not theirs binaries (dynamically generated).Based on this assumption, version 5 of Qt introduce :
CONFIG += lrelease embed_translations
All generated translation binary are then loaded under the prefix "i18n".
Best regards