Important: Please read the Qt Code of Conduct -

[SOLVED] Mac application menu items not translated

  • Hi all,

    I'm having problems localizing the Application menu items on Mac OS. The rest of the application translates just fine, the application menu is translated when I launch the application from Qt Creator, but when the application is "on its own" after running macdeployqt on a release bundle, it's reverted to the original language (english).

    I've added the necessary directories/files within the bundle:

    @<bundle dir>/Contents

    (in this case for Danish), where locversion.plist contains

    @<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    <plist version="1.0">

    Even though this may not be necessary(?), I've added strings like this in my application as a desperate resort:

    @QCoreApplication::translate("Mac Application Menu", "Services");
    QCoreApplication::translate("Mac Application Menu", "Hide %1");@

    and translated them of course. Still, no Danish application menu. What is the secret of this seemingly black art? Looking around the net, it seems like others are struggling too.

  • Really? :-(

  • Thanks for the suggestion, however, I already came across that thread, and did as suggested (although programmatically):

    QCoreApplication::translate("Mac Application Menu", "Services");
    QCoreApplication::translate("Mac Application Menu", "Hide %1");

    These strings do show up in the .ts files when running lupdate.

  • Lifetime Qt Champion


    Can you provide a sample project that reproduce the behavior ?

  • But doesn't QCA.translate() return the translation for the given string? What good does it do your program, since Qt is building the menu, on behalf of your app? Oh, I see, you just want to force the translation into your .ts files.

    I would guess that your programmatic translation doesn't work because you misspelled the context, which is something like MAC_APPLICATION_MENU in the Qt code. So if you use that exact context in your code snippet, run lupdate, use linguist to translate, etc. and your app installs a translator for the resulting .qm file, then the Qt library, when building the mac app menu and using that context, will find your translations.

    I could be wrong, and I am struggling too.

  • bootchk: Thanks for your input - it does indeed work when changing the context string to "MAC_APPLICATION_MENU"! I didn't put too much importance in the context name, but it's obviously necessary in this case.


  • Great. Ideally, one would not need this hack, but instead contribute a translation to the Qt project. (I haven't done it myself, but it would be something like this: enroll as a Qt contributor, clone the latest source repository, run linguist on qttranslations/qt_da.ts and translate the strings for the main menu context, and submit a patch.)

    I learned that Qt project relies on third parties to contribute translations. In my case 'Undo %1' is untranslated in qt_es.ts (Spanish) for at least a year. I hope Qt is recovering and getting more traction now.

Log in to reply