Important: Please read the Qt Code of Conduct -

QTranslator issue

  • Hello...

    I have one minor question...

    I am trying to use QTranslator class to translate to any given language... I tried using french and polish (by forcing the use of qt_fr and qt_pl) but it seems that it doesn't translate... Here is the test code I used...


    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QTranslator qtTranslator
    qtTranslator.load("qt_fr", QLibraryInfo::location(QLibraryInfo::TranslationsPath));

    QTranslator myTranslator;

    qDebug() << QObject::tr("cancel");
    return app.exec();

    this prints the normal cancel... Don't know the French word but the polish word is Annuluj or something like that (as it says in the documentation)... Are there any other steps required for the translator to work? Tried using the lupdate from cmd but it still does nothing... Any help would be much appreciated... Also when I use lupdate it says this: "No TS files specified. Only diagnostics will be produced for *.pro"

    Using Qt 4.8.4 with MSVC2008 but the QtCreator from Qt 5... Windows 7 Proffesional 32 bits... Is it possible to be because the OS doesn't support language packs? This souldn't be an issue though because I'm forcing the translations from the Qt Translation Folder... No? Thank you in advance

  • Hi,

    I think you be a little bit confused about how QTranslator works.

    When you need a translation, you must provide a CONTEXT.
    In the global context (you use it when call the static version of tr) there's no translation for "cancel" it qt_*.ts.

    In this example
    @ int main(int argc, char *argv[])
    QApplication app(argc, argv);

     QTranslator translator;
     QPushButton hello(QPushButton::tr("Hello world!"));
     hello.resize(100, 30);
     return app.exec();


    To translate "Hello World" you need to create a translation file "hellotr_la.qm" and use it.

    No global translation for "cancel" was provided by qt_*.ts

Log in to reply