Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] QTranslator not working?



  • Hi guys,

    I'm trying out the translator system in QT for the first time.
    I fallowed the guide :
    http://qt-project.org/doc/qt-5.0/qtdoc/internationalization.html

    -First genereted the .ts file
    -Edited the .ts file with Qt Linguist (completed the translation 100%)
    -Compiled the .ts file into .qm file in QtCreator

    The .qm file and .ts file are in the root on my project, here's a screenshot:
    https://www.dropbox.com/s/gv2wraan7au8o75/folderProject.png

    I specify in my main to load a specific .ts file just for testing, but it still show the english text. (see code below)
    Anything I forgot to do?
    Thanks in advance /Merci à l'avance :)

    @int main(int argc, char *argv[]) {

    QApplication a(argc, argv);
    
    QString locale = QLocale::system().name();
    qDebug() << "LOCALE : " << locale;
    
    QTranslator translator;
    translator.load("powervelo_fr");
    a.installTranslator(&translator);
    
    MainWindow w;
    w.show();
    
    return a.exec(&#41;;
    

    }@


  • Lifetime Qt Champion

    Hi,

    Without the rest of your code, it's difficult to say what could be wrong. The first guess is: did you surround all your visible texts with tr() ?



  • I set the text directly in QtCreator interface

    An example of generated code looks like this :
    @groupBox->setTitle(QApplication::translate("MainWindow", "Filter", 0));@

    I think it's good syntax cause the generated .ts file make an entry for it

    Thanks



  • Hmm probably a problem with the path of the file

    the boolean return false when I load the file

    @ QTranslator translator;

    bool test = translator.load("powervelo_fr");
    qDebug() << "LOADED? " << test;
    //return false
    a.installTranslator(&translator);@

  • Lifetime Qt Champion

    Are you sure your file is in the same folder as your executable ?



  • Include in your pro file:
    @
    TRANSLATIONS = HD120_en.ts
    HD120_nl.ts
    HD120_cn.ts
    HD120_pt.ts
    @
    Of at least the ts files you need. That's needed for QtLinguist. Also check if your using a shadow build that your files are in the same as the executable file! Not in your project, but in your debug/release folders!!



  • That was the problem, the files were in the project instead of the release/debug folder

    Thanks guys!



  • If that fixed it, place [SOLVED] in front of your first post!!


Log in to reply