Can't have application menu bar in english on OSX french



  • Hello,

    I would like to launch application in a other language than the OSX settings.
    So I have followed this documentation: http://doc.qt.io/qt-5/internationalization.html#enabling-translation
    It works fine for other langages like Spanish or Chinese.

    But when it comes to english, QTranslator::load fail to load the qt english translation file.
    So I have my application in english but not the OSX application menu bar.

    What I am doing wrong ?

    Here the code:

    QString lang = "en"; // Or de, es, it, ru, ...
    QTranslator *translator = new QTranslator(this);
    
    bool loadOK = translator->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    bool installOK = false;
    if (loadOK)
        installOK = qApp->installTranslator(translator);
    else
        translator->deleteLater();
    
    qDebug() << "Qt translations path: " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
    qDebug() << "Translator: " << "qt_" + lang << " - load: " << loadOK << " - install: " << installOK;
    
    /* For en, the result are:
        Qt translations path: "/Users/[username]/Qt/5.5/clang_64/translations"
        Translator: "qt_en" - load: false - install: false
        */
    

    Regards,

    nelbok


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The menu bar is a special case in OS X. Take a look here, it describes how to handle the menu bar translation.

    Hope it helps



  • Thanks SGaist,

    I have tested your link, but it doesn't work. So i tested other things and i found something strange.
    With QtWidgets, the application menu bar is translated nice. I don't have the problem.
    But with QML, i have the problem.

    So i have the problem only with QML. Actually, i have tested on :

    • Mountain Lion: Qt 5.5.1 and xcode 5.1.1
    • Mavericks: Qt 5.5.1 and xcode 5.1.1

    There are a special thing to do with QML ?

    Regards,

    nelbok


  • Lifetime Qt Champion

    Can you share a minimal sample project on e.g. github that shows that behavior ?



  • Sorry for the wait.

    Here two examples :

    For the moment, i have a work around. I create a english translation to manually set the correct values.
    I have getted the source of translations module with the Qt installer to have the key translations...

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="en">
    <context>
        <name>MAC_APPLICATION_MENU</name>
        <message>
            <source>Services</source>
            <translation>Services</translation>
        </message>
        <message>
            <source>Hide %1</source>
            <translation>Hide %1</translation>
        </message>
        <message>
            <source>Hide Others</source>
            <translation>Hide Others</translation>
        </message>
        <message>
            <source>Show All</source>
            <translation>Show All</translation>
        </message>
        <message>
            <source>Preferences...</source>
            <translation>Preferences...</translation>
        </message>
        <message>
            <source>Quit %1</source>
            <translation>Quit %1</translation>
        </message>
        <message>
            <source>About %1</source>
            <translation>About %1</translation>
        </message>
    </context>
    </TS>
    

    Regards,

    nelbok


  • Lifetime Qt Champion

    Since my system is in english I've tested both applications loading the german translation file and both worked correctly but I have Qt version that is more recent than you.

    Can you check again with the 5.6 Beta ?



  • Hello,

    After downloaded and installed qt-opensource-mac-x64-clang-5.6.0-beta.dmg.
    On my OSX french and for the QML project, it does not work, i have the application menu bar in french and not in english.

    Also, when i run the two project, they say that they can't load qt_en in the output log.

    Regards,

    nelbok


  • Lifetime Qt Champion

    Does it also fail if you change qt_en by qt_de ?



  • When i change lang to de, with Qt 5.5.1 or 5.6, it works fine.


  • Lifetime Qt Champion

    So it seems that for some reason there's something funky with the english translation going on...


  • Lifetime Qt Champion

    I just realized, Qt is already written in english so it's pretty likely that the qt_en.qm file is empty. So if you need english translation of your non-english written application, you have to provide the english translation of your application. Personally, I'd recommend writing your application in english and provide translations for the other languages.



  • Hello,

    That not the problem here.
    If i understand correctly, the OSX Application Menu is translated by Qt, not my application.
    The problem occurs only with QtQuick and on a OSX no-english.

    So why i must do give a translated file created by me for QtQuick and not for QtWidgets ? (And not the translated files qt)

    Regards,

    nelbok



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