PDA

View Full Version : Changing standard items in Application Menu in Mac dynamically



Cupidvogel
17th January 2016, 06:33
All Qt apps (any app, for that matter) in Mac come with a Application Menu which contains standard menu items like Preferences, Show All, Quit <app>, Services, etc. I read through some solutions here: https://forum.qt.io/topic/20626/solved-application-menu-translation-on-mac and here: https://forum.qt.io/topic/37492/solved-mac-application-menu-items-not-translated. Based on these, I added this to my .ts files for all languages I need to translate:



<name>MAC_APPLICATION_MENU</name>
<message>
<source>Services</source>
<translation>Yippie</translation>
</message>
<message>
<source>Hide %1</source>
<translation>Goo %1</translation>
</message>
<message>
<source>Hide Others</source>
<translation>Check Others</translation>
</message>
<message>
<source>Show All</source>
<translation>Cool</translation>
</message>
<message>
<source>Quit %1</source>
<translation>What %1</translation>
</message>


When my app launches, I pick up from my app data file what locale did the user select last time, and launch the translator with that locale:



fTranslator.load(QString::fromStdString("locale/app_"+fAppData->getAppLocale())); //a 'pt' locale has a corresponding 'app_pt.qm' file
QApplication::instance()->installTranslator(&fTranslator);
emit reTranslateUIEvent();


I have connected the reTranslateUIEvent signal to a slot where I am manually retranslating all menus and other items I have added. Note, I am not doing anything to retranslate the system provided application menu items like Show All, Quit <app>, etc. They are picked up automatically from the .qm file being loaded on app launch, so Quit %1, which translates to What %1 in my qm file successfully becomes What <app> in the Application menu on app launch if the last saved locale was that locale.

However, when the user changes language mid way through an option we provide, we call the above code again, and it successfully changes the locale everywhere. Except..the Application Menu items. They remain in the same locale as the one in which the app launched originally. I don't know what extra thing do I need to do to change them, since I am not doing anything to them on app launch, and then they translate correctly.

How do I make those items retranslate dynamically as well?