Translate a single QString
-
Hello,
how can i translate a single QString in an Qt Console application. I just can find examples with gui. But it doesnt work....
I am working on an embedded linux systeem and some error messages have to be translated.
for example (just an primitive example)#include "translate.h" #include <QCoreApplication> #include <QDebug> #include <QTranslator> Translate::Translate(QObject *parent) : QObject(parent) { translate(); } void Translate::translate() { QString message = tr("Hello"); QTranslator translator; translator.load("ConsoleTranslationExample_de_DE"); qApp->installTranslator(&translator); QTextStream o(stdout); o << message; }Can anybody please help me. Wasted yesterday the whole day to find a solution :-(
-
Hello,
how can i translate a single QString in an Qt Console application. I just can find examples with gui. But it doesnt work....
I am working on an embedded linux systeem and some error messages have to be translated.
for example (just an primitive example)#include "translate.h" #include <QCoreApplication> #include <QDebug> #include <QTranslator> Translate::Translate(QObject *parent) : QObject(parent) { translate(); } void Translate::translate() { QString message = tr("Hello"); QTranslator translator; translator.load("ConsoleTranslationExample_de_DE"); qApp->installTranslator(&translator); QTextStream o(stdout); o << message; }Can anybody please help me. Wasted yesterday the whole day to find a solution :-(
-
No, still doent work...
TranslationFile:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1" language="de_DE"> <context> <name>Translate</name> <message> <source>Hello</source> <translation>Hallo</translation> </message> </context> </TS>cpp:
void Translate::translate() { QTranslator translator; translator.load("ConsoleTranslationExample_de_DE"); qApp->installTranslator(&translator); QString message = tr("Hello"); QTextStream o(stdout); o << message; }Output: Hello
-
No, still doent work...
TranslationFile:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1" language="de_DE"> <context> <name>Translate</name> <message> <source>Hello</source> <translation>Hallo</translation> </message> </context> </TS>cpp:
void Translate::translate() { QTranslator translator; translator.load("ConsoleTranslationExample_de_DE"); qApp->installTranslator(&translator); QString message = tr("Hello"); QTextStream o(stdout); o << message; }Output: Hello
-
@eyllanesc said in Translate a single QString:
qDebug() << translator.load("ConsoleTranslationExample_de_DE");
It is false. Mh creator cant fiond the translation file
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dir -
@eyllanesc said in Translate a single QString:
qDebug() << translator.load("ConsoleTranslationExample_de_DE");
It is false. Mh creator cant fiond the translation file
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dir -
@eyllanesc said in Translate a single QString:
qDebug() << translator.load("ConsoleTranslationExample_de_DE");
It is false. Mh creator cant fiond the translation file
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dir@d-rein said in Translate a single QString:
It is false. Mh creator cant fiond the translation file
the ts file is located in the src folder of my project and the qm files are located inside the .qm dir of the build dirso the qm file is inside a folder, and not on the same lvl as your executable ?
you'll have to specify that to the load command
-
@d-rein Just for testing use the fullpath:
translator.load("/path/of/ConsoleTranslationExample_de_DE.qm");@eyllanesc Thank you. I got it. With the full path it works
void Translate::translate() { QTranslator translator; if(!translator.load(qApp->applicationDirPath() + "/ConsoleTranslationExample_de_DE.qm")){ qDebug() << "Cant find translation file"; return; } qApp->installTranslator(&translator); QString message = tr("Hello"); QTextStream o(stdout); o << message; }