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

Can't translate Qt texts



  • Hi,

    I make an multi language application, then I use QTranslator.
    QFile dialog is not translated so I try to load qt_fr.qm like

    qtTranslator.load(":/translations/qt_fr.qm");
    

    return always false. (the file is in my qrc)
    (it works with my own translation file)

    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(),
    QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);
    

    works but only if Qt is installed.
    How can I fix this ?

    thanks,
    sorry fo my english.


  • Lifetime Qt Champion

    Hi,

    Might be a silly question but are you sure you are using the correct path to your resources translation file ?



  • Hi,
    Yes, I had the same idea but even

    QTranslator qtTranslator;
        bool bLoaded = qtTranslator.load("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
        application.installTranslator(&qtTranslator);
    

    return false.


  • Qt Champions 2019

    You mean installTranslator returns false? Then you should check with QFileInfo (exits, isReadable)



  • Yes I mean load return false.

    QFileInfo info("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
        bool bExist = info.exists();
        bool bReadable = info.isReadable();
    

    bExist and bReadable are true.
    The only explanation i see, is "C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm" is not a correct qm file.
    So what's the difference between

    QTranslator qtTranslator;
    qtTranslator.load("qt_" + QLocale::system().name(),
    QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    app.installTranslator(&qtTranslator);
    

    and

    QTranslator qtTranslator;
    qtTranslator.load("C:/Qt/5.10.0/msvc2015/translations/qt_fr.qm");
    app.installTranslator(&qtTranslator);
    

    both codes load the same file (in french OS)?


  • Qt Champions 2019

    Ah, you are using the load() function in a wrong way: http://doc.qt.io/qt-5/qtranslator.html#load
    --> const QString &filename, const QString &directory = QString() , at least this would be my next guess :)



  • it works if I do

    qtTranslator.load("qt_fr",  "C:/Qt/5.10.0/msvc2015/translations");
    

    but not for

    m_QtTranslator.load("qt_fr", ":/translations/qm");
    

    before compile my script copy .qm in the correct path. qt_ files are in my qrc but I can't load them...
    Do qt_*.qm need some other files ?
    sorry for my english



  • I think qt_fr.qm does need other qm files, if I use only qtbase_fr.qm I have my translations.


  • Moderators

    hi @Roy44
    did you do a complete clean/rebuild of your project after adding the qm files to your resources ?
    IIRC the binary file qmake creates out of your ressource file is not updated automatically when you add new ressources, therefore the translation files may not be included in your executable.


Log in to reply