// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \title Qt Quick I18N \examplecategory {User Interface Components} \example qml-i18n \ingroup examples-linguist \brief 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 \c i18n subdirectory of the directory that contains the main .qml file, based on the system language. \section1 Marking Text as Translatable In the \c Main.qml file, use the \c qsTr command to mark UI text as translatable: \quotefromfile qml-i18n/Main.qml \skipto } \skipto Text \printuntil ) \section1 Enabling Translation In the \c main.cpp file, use \l QQmlApplicationEngine to automatically load translation files from a subdirectory called \c i18n in the directory that contains the main QML file: \quotefromfile qml-i18n/main.cpp \skipto \printuntil engine; The translation file names in the \c i18n subdirectory must have the prefix \c qml_. For example, \c qml_en_AU.ts. \section1 Creating Translation Files Add the \c LinguistTools module as a value of the \c find_package command in the \c CMakeLists.txt file: \quotefromfile qml-i18n/CMakeLists.txt \skipto find_package( \printuntil ) Define the translation files to generate in the \l qt_add_translations command: \skipto qt_add_translations \printuntil ) Build the application to generate TS and QM files. \note On Android, make sure to include the QM files as resources. \section1 Adding Translations To create translations for new languages, copy \e {i18n/base.ts} to \e {i18n/qml_.ts}. You can use \l{Qt Linguist} to translate the strings. */