Internationalization and Localization with Qt Quick Ultralite
The functionality in Qt Quick Ultralite is based on Internationalization and Localization in Qt Quick and Qt Linguist. This document describes the differences, enhancements, and limitations compared to Qt Quick.
qsTr() function in QML files to mark string literals for translation. All such marked string literals are found by the Qt Linguist tool, which generates the translation source file (
.ts) containing those strings.
Once translations are made, there will a
.ts file for each language. These files are compiled to translation release files (
.qm) and passed to the QML compiler, which will replace each
qsTr() call with a lookup of the correct string based on the
Qul.uiLanguage property can also be used in other bindings to make decisions based on the active language. Frequently this is used for choosing localized images.
examples/translation example shows use of
qsTr() and the
List the translation source files for the target languages in the
qul_target_embed_translations() CMake function. This has two effects:
- It creates a
update_translationsCMake target which is not included in the default build. Trigger a build of this target to create or update the
.tsfiles with new and changed translatable strings from the source code.
- It sets up the build system to embed the translations from the
.tsfiles in the program binary.
.ts file introduces a translated language that can be switched to at runtime by setting the
Qul.uiLanguage property. The name of the language is derived from the name of the
.ts file. For example, the "app.nb_NO.ts" file defines the translations for
nb_NO, which is the ISO language code for Norwegian Bokmål.
In addition to the languages defined by the
.ts files, there is a default language called "source". When the "source" language is active, the untranslated source code strings are used.
If an application does not support multiple languages, use the
OMIT_SOURCE_LANGUAGE option in the
qul_target_embed_translations() CMake function and pass the
.ts file for the target language.
The following functionality is not currently supported:
- Translation of strings in C++ files
- Translation functions other than
- The plural disambiguation argument in
Available under certain Qt licenses.
Find out more.