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.qrc
    /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:

    <RCC>
        <qresource prefix="/translations">
            <file>translations/app_it.ts</file>
            <file>translations/app_it.qm</file>
            <file>translations/app_en.ts</file>
            <file>translations/app_en.qm</file>
        <qresource>
    <RCC>
    

    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:

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

    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

    Hi,

    What exactly doesn't work ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.