Saturday, April 3, 2010

QML i18n

Like as this article, we can do i18n for QML applications.

(1) Wrap all characters with qsTr() like below:
import Qt 4.7

Rectangle {
    width: 200
    height: 200
    Text {
        x: 66
        y: 93
        text: qsTr("Hello World")

(2) Create or update translation source files from .qml file.
> /opt/Qt-4.7.0/bin/lupdate hello_world.qml -ts hello_world_ja_JP.ts

(3) Edit translation source file with Qt Linguist.
> /opt/Qt-4.7.0/bin/linguist hello_world_ja_JP.ts

(4) Save as message file (e.g. hello_world_ja_JP.qm).

(5) Run with message file like below:
> /opt/Qt-4.7.0/bin/qml -translation hello_world_ja_JP.qm hello_world.qml

No comments:

Post a Comment