I try to use translation in QML. I opened a new project QtQuick project, I chose QtQuick Componenets for Symbian as a QtQuick Application Type. Qt Creator created a application source tree with all 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 looks after implementation of QTranslator 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 have used linguist to translate the POSIX expression "Hello world!" to something else just test that it is translating. Then I created inter_en.qm file with linguist.
But when I run the application on simulator I dont get "Hello world!" translated, although the translator is loaded successfully (I get "Translating: true" in qDebug).
Translator is working correctly I am sure, because when I deremark part of the code with QPushButton , (again I repeat the lupdate and linguist things for this purpose) , then the "Hello world!" expression in QPushButton is translated correctly.
It is only the QmlApplicationViewer and QML file that is not performing translation correctly. Any quesses?????
Thanks
UPDATE
I found out the following: MainPage.qml is imported as reusable component into main.qml. If I use qsTr() in main.qml then the text is translated correctly in main.qml. However text in MainPage.qml is not tranlated correcty. I guess due to importing it as reusable component. Any comments? Experiences?
UPDATE2 - SOLUTION
Translation files need to be created case sensitively:
lupdate mainpage.qml -ts myapp_sk.ts is wrong
lupdate MainPage.qml -ts myapp_sk.ts is correct