Qt/translations
From Attie's Wiki
(Difference between revisions)
m (→Installing translations) |
m |
||
Line 49: | Line 49: | ||
main = new MainWindow(); | main = new MainWindow(); | ||
+ | </source> | ||
+ | |||
+ | ==Running== | ||
+ | Don't forget to copy the <code>*.qm</code> files into the same directory as the application! | ||
+ | <source lang="bash"> | ||
+ | cp ../myApp/*.qm . | ||
</source> | </source> |
Revision as of 16:50, 11 June 2012
Contents |
Indicating what to translate
Include QTranslator:
#include <QTranslator>
and wrap any strings with the QApplication::translate()
or the QObject::tr()
function:
QString message = app->translate("Message displayed while the system is loading", "Loading, Please Wait...");
Providing the translations
First, add each language file to the TRANSLATIONS
variable:
TRANSLATIONS = myApp_en.ts \ myApp_fr.ts
Run lupdate
on the project:
lupdate myApp.pro
Provide the translations:
linguist *.ts
Release the translations:
lrelease myApp.pro
Installing translations
Load the translation file before loading or displaying any translated windows:
QApplication app(argc, argv); QTranslator translator; MainWindow *main; if (!translator.load(QString("myApp_") + lang + ".qm")) { qDebug("!!! translator.load -> FALSE!!! \n"); } else { app->installTranslator(&translator); } main = new MainWindow();
Running
Don't forget to copy the *.qm
files into the same directory as the application!
cp ../myApp/*.qm .