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:

  1. Move to your Qt project folder where your *.pro file exists.

  2. Create the translation file. lupdate -pro project_name.pro -ts translation_output_name.ts

  3. Open the new translation file with Qt Linguist.

  4. Click on a “Source text” item and you should be able to set a translation string in the middle of the window.

  5. When you are done translating your project, save it.

  6. Convert the file to a .qm (binary) file. lrelease translation.ts

  7. Import this file into a qrc so you do not need to bring the .qm translation file along with your application.

  8. In main

    QTranslator 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.