When you installed QT SDK, it came with several useful tools to do the I18N and localization, I’ll put a very basic QT program and show the basic steps to localize the app to support different local /languages.
Create a Basic QT hello world application, make sure all user-visible strings are used as translatable strings (using tr function)
Create a empty QT Project using QT creator,
then add a new source file,
#include <QtGui> int main(int argc, char * argv[]) |
then run the app by pressing F5, you will see the hello world button,
Now we are going to add the Chinese and Japanese Support to the app.
>>> go the the project folder, Run a command called Lupdate(include in the sdk ), to extract all translatable strings to a file,
here default.ts is just a xml file as the content bellows,
>>>now use the linguist tool to translate it into Japanese, run “linguist” In the qt shell or click the tool from start-menu
open the default.ts, and chose Japanese as the target language,
put the translation for hello world in Japanese, and click to mark done, then Save it as as jp.ts
Now quite the translation tool and start over again to translate it to Chinese, and export to cn.ts
>>>compile the cn.ts and jp.ts to binary format using lrelease
>>> now in the app, load those two qm files,
QApplication app(argc,argv); QTranslator translator ; QLocale curent;
QPushButton * button=new QPushButton(QObject::tr("Hello,World")); |
Now, if you setup your current locale to Japanese, you will see the JP version of helloword
or you can change the default local in code,
QLocale::setDefault(QLocale::Japanese); |
No comments:
Post a Comment