Important: Please read the Qt Code of Conduct -

QT - Read translator file .ts/.qm on translations.qrc file

  • Hi guys, I'm trying to import translator file on my qt project (QT 5.6 on linux system), but I can't upload translation file because "load" function of "QTranslator" returns always "false".

    I have the following project structure:

    Project root: /
    /resources/translations/app_it .qm and .ts
    /resources/translations/app_en .qm and .ts

    In main.cpp file of qt application I have the following source code:

    QTranslator *translator = new QTranslator();
    bool isFileTranslatorLoaded = translator->load(":/translations/translations/app_it);

    isFileTranslatorLoaded always returns false.

    File translations.qrc:

        <qresource prefix="/translations">

    How can I solve this issue?

    Thanks in Advice

    Best Regards Daniele

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are passing an invalid path. You only need the processed version .qm there's no need for the *.ts files.

  • I have followed your suggestions but isFileTranslatorLoaded returns always false. In c++ code I wrote bool "isFileTranslatorLoaded = translator->load(":/translations/appit.qm");" and my resource file is:

    <qresource prefix="/translations" lang="it">
    <file alias="appit.qm">translations/app_it.qm</file>
    <qresource prefix="/translations" lang="en">
    <file alias="appen.qm">translations/app_en.qm</file>

    I don't know why the .qm file isn't loaded. It seems that the resource file is not loaded in the main.cpp file.

    Thanks in advice.

  • Lifetime Qt Champion

    Because you are using lang="it" this means that the file is only available if your locale is Italian. See the resources chapter in Qt's documentation for a more thorough explanation.

  • Hi @SGaist , This doesn't work for me as well. I tried with using lang=en, lang=ar and without the lang attribute.

  • Lifetime Qt Champion


    What exactly doesn't work ?

Log in to reply