qt國際化

怎麼在qt4中顯示中文:
在代碼中用可以用英文命名各個元件,但是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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章