Results 1 to 1 of 1

Thread: Changing standard items in Application Menu in Mac dynamically

  1. #1
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Changing standard items in Application Menu in Mac dynamically

    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/solv...slation-on-mac and here: https://forum.qt.io/topic/37492/solv...not-translated. Based on these, I added this to my .ts files for all languages I need to translate:

    Qt Code:
    1. <name>MAC_APPLICATION_MENU</name>
    2. <message>
    3. <source>Services</source>
    4. <translation>Yippie</translation>
    5. </message>
    6. <message>
    7. <source>Hide %1</source>
    8. <translation>Goo %1</translation>
    9. </message>
    10. <message>
    11. <source>Hide Others</source>
    12. <translation>Check Others</translation>
    13. </message>
    14. <message>
    15. <source>Show All</source>
    16. <translation>Cool</translation>
    17. </message>
    18. <message>
    19. <source>Quit %1</source>
    20. <translation>What %1</translation>
    21. </message>
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. fTranslator.load(QString::fromStdString("locale/app_"+fAppData->getAppLocale())); //a 'pt' locale has a corresponding 'app_pt.qm' file
    2. QApplication::instance()->installTranslator(&fTranslator);
    3. emit reTranslateUIEvent();
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by Cupidvogel; 17th January 2016 at 06:43.

Similar Threads

  1. extend the standard context menu of qtextedit
    By cai in forum Qt Programming
    Replies: 9
    Last Post: 10th November 2011, 12:16
  2. Replies: 2
    Last Post: 28th September 2010, 10:34
  3. Changing the name of the application menu on OSX
    By bishop123b in forum Qt Programming
    Replies: 4
    Last Post: 27th December 2008, 02:48
  4. Dynamically changing QFrame color
    By Doug Broadwell in forum Newbie
    Replies: 6
    Last Post: 16th October 2008, 08:22
  5. Dynamically changing QGroupBox size
    By T4ng10r in forum Qt Programming
    Replies: 5
    Last Post: 30th March 2007, 15:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.