QT国际化支持

为了是我们的QT程序支持如中文等其他语言,通常的做法是在需要翻译的地方显示的用tr标记,所以你在阅读其他人编写的源程序时会看到很多字符串做了tr标记,这样做是有原因的。
1.在hello.pro文件中增加
TRANSLATIONS = hello_zh_CN.ts
2.进入工程目录,运行
lupdate hello.pro,生成hello_zh_CN.ts文件
3.使用Qt Creator打开这个文件(或者直接用vi或gedit打开都可以),对翻译部分进行翻译,比如
<source>hello!</source>
<translation type="unfinished">你好!</translation>
4.在工程目录中,运行
lrelease hello_zh_CN.ts,生成hello_zh_CN.qm文件
5.在main.cpp中添加代码
QTranslator translator;
translator.load("hello_zh_CN.qm");
a.installTranslator(&translator);

posted @ 2011-11-21 15:26  移动应用开发  阅读(181)  评论(0编辑  收藏  举报