Qt World Summit: Register Today!

[SOLVED] Qt translation not working

  • I tried to add multilanguage support in my new program so I just added same code as in my other program where translations were working. But in this case everything remains untranslated... TRANSLATIONS += translation-pl_PL.ts added to .pro file, .ts translated, .qm generated and added to resources (/translations/translation-pl_PL.qm) so I don't think I forgot about doing something necessary...

    main.cpp where translation is loaded:
    #include "mainwindow.h"
    #include <QtGui>
    int main(int argc, char *argv[])
    QApplication a(argc, argv);

    //checking available program translations
    QFile tempFile&#40;":/translations/translation-"+QLocale::system(&#41;.name(&#41;+".qm");
        //program is translated to system default language
        qDebug("translation to system default language available");
        //Qt translations
        qDebug("loading qt translations");
        QTranslator qtTranslator;
        bool check;
        check=qtTranslator.load("qt_"+QLocale::system&#40;&#41;.name(&#41;, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
            qDebug("qtTranslator load true");
            qDebug("qtTranslator load false");
        //program translations
        qDebug("loading program translations");
        QTranslator programTranslator;
            qDebug("programTranslator load true");
            qDebug("programTranslator load false");
    MainWindow w;
    return a.exec(&#41;;


    Debug info:
    translation to system default language available
    loading qt translations
    qtTranslator load true
    loading program translations
    programTranslator load true
    So everything is loading but translation is not working...

    What can be wrong here?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure that you are not getting the english translator ?

    Did you add tr() around your texts ?

  • pl_PL translator is loaded. I have tr().

  • Lifetime Qt Champion

    The are you sure that the translation file contains the correct texts ?

  • .ts is translated - I can see translations inside it. .qm is generated from it so I think that it should be ok too.

  • Lifetime Qt Champion

    If you have the translation files from your other programs handy, can you try to use one of them to see if it behaves better ?

  • I found what was the problem... I defined qtTranslator and programTranslator in if...

  • Lifetime Qt Champion

    Great you found out !

    Don't forget to update the thread's title so that other forum users may know that a solution has been found :)

Log in to reply