QML国际化小结

http://developer.nokia.com/Community/Wiki/QML%E5%9B%BD%E9%99%85%E5%8C%96%E2%80%94%E2%80%94%E4%B8%AD%E6%96%87%E7%A4%BA%E4%BE%8B


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.0

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

另外,如果使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值