Several techniques allow the internationalization of Qt-program.
I have worked out the procedure explained on this page, to embed translations in an executable file, so that they will be immediately available without having to keep track of the locations of *.qm files on an end-users system.
I cannot say, that my procedure were special
in any
way, because I am only using what the Qt development
environment proposes anyway. I am – however – not following the
recommendations that you find on the Web and in the help-files
that accompany the translation-tools, mainly because I do not
understand them!
You should probably compare my explanations here to those that you find elsewhere, then do as you please...
My Qt-version is at the time of this writing: 6.4
These are steps which I will not explain further. For more details see the QtLinguist manual.
lupdate-proshould achieve the same, but I know nothing about that)
The one step which is missing to make translations available to the application, concerns the compilation of each *.ts file into a binary Qt message (*.qm) file. This will be part of the following procedure.
In the project file, you name the original translation-files:
TRANSLATIONS += project_name_fr_FR.ts \ project_name_de_DE.ts
The compilation of the translations into *.qm files will be
done by calling the helper program lrelease. The call
of lrelease and the fact that the translations shall be
embedded in the executable, necessitate additional values in
the variable CONFIG
, in the same
project-file:
CONFIG += lrelease embed_translations TRANSLATIONS += project_name_fr_FR.ts \ project_name_de_DE.ts
To ensure that no residue of previous compilations
interferes and if a Makefile is present, run
:~/[project]$ make distclean.
Now re-create the Makefile by calling qmake:
:~/[project]$ qmake.
The changes made in the project-file will have as consequence that additional files will be created. The first one is a default resource-file qmake_qmake_qm_files.qrc that you can see after running qmake. It contains the future location of the compiled *.qm files:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file alias="project_fr_FR.qm">/project/.qm/project_fr_FR.qm</file> <file alias="project_de_DE.qm">/project/.qm/project_de_DE.qm</file> </qresource> </RCC>
The hidden directory .qm will be created upon running make, as will the *.qm-files which correspond to the translations. The resource-prefix "i18n" is the same that serves as second parameter to the method QTranslator::load() (see above).
Now that the Makefile and the resource-file are created, you
can build the program by calling
:~/[project]$ make.
This will first find the lrelease tool, compile the *.qm-files and store them in the hidden directory .qm, then create one new file *.cpp and one new header *.h in the source-directory of the project. Eventually the translations will thus be compiled and linked in the executable program-file.
Much of the above procedure relies on the defaults provided by the Qt framework. If you prefer, you can modify some of the parameters to
I will though not help you with that.