Generating translation files (TS and QM) for a Qt Quick application.

When you run the example application, the QML runtime automatically loads a translation from the i18n subdirectory of the directory that contains the main .qml file, based on the system
language.
In the Main.qml file, use the qsTr command to mark UI text as translatable:
Text { text: qsTr("Hello")
In the main.cpp file, use QQmlApplicationEngine to automatically load translation files from a subdirectory called i18n in
the directory that contains the main QML file:
#include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine;
The translation file names in the i18n subdirectory must have the prefix qml_. For example, qml_en_AU.ts.
Add the LinguistTools module as a value of the find_package command in the CMakeLists.txt file:
find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Qml LinguistTools)
Define the translation files to generate in the qt_add_translations command:
qt_add_translations(qmli18n
RESOURCE_PREFIX /qt/qml/Translated/i18n
TS_FILE_BASE qml
TS_FILE_DIR i18n
)
Build the application to generate TS and QM files.
Note: On Android, make sure to include the QM files as resources.
To create translations for new languages, copy i18n/base.ts to i18n/qml_<lang>.ts. You can use Qt Linguist to translate the strings.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: