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 QtQuick 1.0Rectangle{
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.tsThen 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
另外,如果使用Qt Quick编译,将project文件中添加下面的话:
QT += core gui declarative
主文件main.cpp的内容为:
#include<QtCore/QTranslator>
#include<QtGui/QApplication>
#include<QtDeclarative/QDeclarativeView>
int main(int argc,char* argv[]) {
QApplication app(argc,argv);
QTranslator translator;
translator.load("displayChinese_zh_CN.qm");
app.installTranslator(&translator);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view.show();
return app.exec();
}
http://www.cnblogs.com/roymuste/p/3178444.html
http://www.linux521.com/2009/newbie/200901/337.html
http://www.linuxidc.com/Linux/2011-07/38541.htm
http://www.thisisqt.com/forum/viewthread.php?tid=348
http://blog.csdn.net/amd123linux/article/details/11868819
生成ts文件:
lupdate youker-assistant.pro
生成qm文件:
lrelease youker-assistant.pro