Qt Reference Documentation

QML Internationalization

Overview

Strings in QML can be marked for translation using the qsTr(), qsTranslate(), QT_TR_NOOP(), and QT_TRANSLATE_NOOP() functions.

For example:

 Text { text: qsTr("Pictures") }

These functions are standard QtScript functions; for more details see QScriptEngine::installTranslatorFunctions().

QML relies on the core internationalization capabilities provided by Qt. These capabilities are described more fully in:

You can test a translation with the QML Viewer using the -translation option.

Example

First we create a simple QML file with text to be translated. The string that needs to be translated is enclosed in a call to qsTr().

hello.qml:

 import Qt 4.7

 Rectangle {
     width: 200; height: 200
     Text { text: qsTr("Hello"); anchors.centerIn: parent }
 }

Next we create a translation source file using lupdate:

 lupdate hello.qml -ts hello.ts

Then we open hello.ts in Linguist, provide a translation and create the release file hello.qm.

Finally, we can test the translation:

 qmlviewer -translation hello.qm hello.qml

You can see a complete example and source code in the QML Internationalization example.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.