Qt 国际化 (转)

来源:互联网 发布:淘宝客建站app 编辑:程序博客网 时间:2024/04/30 15:15

在代码中用可以用英文命名各个元件,但是main.cpp中加入以下语句:
QTranslator translator;
translator.load("hellotr_la");
app.installTranslator(&translator);
然后运行qmake -project
在生成的.pro文件中加一下语句:
TRANSLATIONS=hellotr_la.ts
运行 qmake
运行 lupdate -verbose hellotr_la.pro 生成.ts文件 (.ts format is human-readable XML that can be emailed directly and is easy to put under version control)
运行 linguist hellotr_la.ts 打开QT linguist Trolltech 选中你要改名的元件,在Translation下写要改成的中文名.
然后File->Release
File->Save
最后就可以make你的程序并运行了.
其实在qt4的assistant-Tutorial and Example-QT Linguist Examples中有详细介绍.本文参考它得来的.
QT中的例子:

QApplication app(argc, argv);

     QString locale = QLocale::system().name();     QTranslator translator;     translator.load(QString("arrowpad_") + locale);     app.installTranslator(&translator);面说一下qt国际化编程的操作步骤:1、编写源代码2、在*.pro文件中添加TRANSLATIONS += *.ts ,有多少中语言就添加多少个ts文件。3、运行lupdate *.pro 生成ts文件。lupdate会根据源代码中的内容提取出待翻译的字段,然后生成ts文件,ts文件是xml格式的。4、用qt linguist打开ts文件,并翻译相应字段5、运行lrelease *.pro生成qm文件。lrelease会根据ts文件生成二进制的qm翻译文件。6、在*.qrc文件中添加qm文件的路径,并编译源代码

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/benwang_/archive/2009/03/03/3953364.aspx