Monday, October 26, 2009

Memo for Qt i18n

Chapter 17 of this Qt book is for internationalization (i18n). There are some leverage points. So I write memo of these points on this article.

(1) If you force to internationalize all characters, you must define below line in .pro file:
DEFINES += QT_NO_CAST_FROM_ASCII


(2) Wrap all characters with tr() (if you want to internationalize) or QLatin1String() (if you want not to internationalize).


(3) Add translation source file entries to .pro file like below:
TRANSLATIONS = hogehoge_ja_JP.ts


(4) Create or update translation source files from .pro file.
> /opt/qtsdk-2009.04/qt/bin/lupdate hogehoge.pro

(5) Edit each translation source file with Qt Linguist.
> /opt/qtsdk-2009.04/qt/bin/linguist hogehoge_ja_JP.ts

(6) Generate translation files from translation source files via .pro file.
> /opt/qtsdk-2009.04/qt/bin/lrelease hogehoge.pro

(7) In main method, write the codes to load translation file like below:

QTranslator appTranslator;
QString translatorPath = QLatin1String("hogehoge_") + QLocale::system().name();
appTranslator.load(translatorPath, qApp->applicationDirPath());
app.installTranslator(&appTranslator);

No comments:

Post a Comment