Deploy QML app to devices with languages files
-
Hello,
I do have an app with some language files. I do deploy my app on a remote device.
My issue is that the language file are not deployed with the app.How can I do to deploy the language file with it ?
Thank you in advance.
-
Yes, use Qt Resource Files for your translations (QM files).
-
@sharath
The method described in that block is a bit out of date.
Since Qt 5.10 or 11 (I'm unsure when exactly) you no longer have to trick the QML engine with the "empty string" to update all texts.That now happens automatically.
-
@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.
-
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.
-
@DavidM29 please show us how you load the translation file
-
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.
-
-
!translator->load(
QString("lang_%1").arg(language),
QString(":/Langues") ) -
Thank you all for your help it was that easy ! If i knew !
It works well now that J.Hilk correct the load function. -
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