I am trying to use translation in QML. I opened a new project of QtQuick project, I chose QtQuick Componenets for Symbian as QtQuick Application Type. Qt Creator created an application source tree with all the standard files (main.cpp, main.qml, mainpage.qml ...)
MainPage.qml is very simple:
import QtQuick 1.1 import com.nokia.symbian 1.1 Page { id: mainPage Text { anchors.centerIn: parent text: qsTr('Hello world!') color: platformStyle.colorNormalLight font.pixelSize: 20 } }
My main.cpp file, after implementing QTranslator, looks like this:
#include "qmlapplicationviewer.h" #include <QTranslator> #include <QPushButton> #include <QDebug> Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer<QApplication> app(createApplication(argc, argv)); QTranslator* translator = new QTranslator; qDebug()<<"Translating: "<<translator->load(QString("qml/International/inter_en")); app->installTranslator(translator); //QPushButton hello(QPushButton::tr("Hello world!")); // hello.resize(100, 30); // hello.show(); QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create()); viewer->setMainQmlFile(QLatin1String("qml/International/main.qml")); viewer->showExpanded(); return app->exec(); }
Then I run lupdate mainpage.qml -ts inter_en.ts, I used a linguist to translate the POSIX expression โHello world!โ. for something else, just check that it is a translation. Then I created an inter_en.qm file with a linguist.
But when I run the application on the simulator, I do not get "Hello world!". translated, although the translator loaded successfully (I get "Translation: true" in qDebug).
The translator is working correctly. I am sure, because when I consider part of the code with QPushButton, (again I repeat lupdate and linguistic things for this purpose), then "Hello world!" the expression in QPushButton is translated correctly.
Only the QmlApplicationViewer and QML file do not translate correctly. Any quests ?????
thanks
UPDATE
I found out the following: MainPage.qml is imported as a reusable component in main.qml. If I use qsTr () in main.qml, the text will be correctly translated into main.qml. However, the text in MainPage.qml does not translate correctly. I think due to importing it as a reusable component. Any comments? Experience?
UPDATE2 - SOLUTION
Translation files should be created with the feeling:
lupdate mainpage.qml -ts myapp_sk.ts is wrong lupdate MainPage.qml -ts myapp_sk.ts is correct