Qt Translations
Jul 16, 2015
The first thing you will need to do is wrap all strings that you want to be translated with the tr()
function. This will allow you to export the strings to a .ts file where you can make the translations using Linguist.
Afterwards follow these steps:
-
Move to your Qt project folder where your *.pro file exists.
-
Create the translation file.
lupdate -pro project_name.pro -ts translation_output_name.ts
-
Open the new translation file with Qt Linguist.
-
Click on a “Source text” item and you should be able to set a translation string in the middle of the window.
-
When you are done translating your project, save it.
-
Convert the file to a .qm (binary) file.
lrelease translation.ts
-
Import this file into a qrc so you do not need to bring the .qm translation file along with your application.
-
In
main
QTranslator translator; translator.load(":/translation.qm"); a.installTranslator(&translator);
You will need to create a .qm file for each language (as far as I know) and load it dynamically based on user choice or determine the system’s locale using QLocale.