Symbian-Developers
The Official Developers Section => Symbian Software Development Discussions => The Developers Section => Qt Application Development => Topic started by: huellif on August 21, 2013, 03:57:53 pm
-
before your start:
you have to change all stings which should be translated like this:
text: "Hello World"; to qsTr("Hello World");
1. edit your main.cpp
inlucde
#include <QtCore/QTranslator>
#include <QtCore/QLocale>
#include <QtCore/QFile>
and add the following code BEFORE you load your QDeclarativeView/QmlApplicationViewer
QString lang = QLocale::system().name().truncate(2);
QTranslator translator;
if (QFile::exists(":/i18n/App_" + lang + ".qm")) {
translator.load("App_" + lang, ":/i18n");
}
else {
translator.load("App_en", ":/i18n");
}
app->installTranslator(&translator);
2. modify your .pro file:
add (change it to the path of your QML files)
#QRC+lupdate trick:
{ SOURCES += qml\App\*.qml }
and
TRANSLATIONS = i18n\App_en.ts \
i18n\App_de.ts
here you can add more languages.
en is for 01 (english), de is for 03 (german) etc.
3. open your .pro in QtCreator,
go to Tools, External, Linguist, Update Translation (lupdate)
now it will generate the .ts files for your qsTr() strings in a single file in \i18n\ folder
in this case for english and german.
4. now translate the .ts file, open them via Qt Qt Linguist: http://qt-project.org/doc/qt-4.8/linguist-translators.html
5. go back to QtCreator and do this:
go to Tools, External, Linguist, Release Translation (lrelease)
now you have compiled App_de.qm and App_en.qm files
6. add them to QRC
7. compile and try :)
with this code the QTranslator will automaticlly load english if your language isn't translated.
And if a single string isn't translated it uses the content of qsTr("")
if you want to try a specific language which isn't in your firmware you have to modify the code, e.g. you can replace
QTranslator translator;
if (QFile::exists(":/i18n/App_" + lang + ".qm")) {
translator.load("App_" + lang, ":/i18n");
}
else {
translator.load("App_en", ":/i18n");
}
with
QTranslator translator;
translator.load("App_PASTYOURLANGUAGEHERE", ":/i18n");
have fun ;)
sources:
http://harmattan-dev.nokia.com/docs/library/html/qt4/qtranslator.html
https://github.com/dicksonleong/Tweetian
-
In translating am i suppose to do the translation myself or the phone will handle everything itself?.Example if want to translate "high" to russian,i would need to know the "high" in russian.
-
In translating am i suppose to do the translation myself or the phone will handle everything itself?.Example if want to translate "high" to russian,i would need to know the "high" in russian.
You add the translated words yourself.
-
Then translating will be bottom priority as i don't know russia.Why nokia don't make it easy like the phone system languagr.Thanks anyway for your answer.