Results 1 to 8 of 8

Thread: QTranslator: the menu is not translated

  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTranslator: the menu is not translated

    I'm working on a GUI that uses QTranslator and everything works fine.
    I load the language at start up and can change it on the fly.
    The only problem is that the menu (menuBar) is not translated when the language is switched.
    If I save the options and restart the GUI, then the menu is in the right language but if I
    change the language on the fly, the menu is not translated.

    I create the menu after having installed the translator.
    I create all the menus/actions with the tr("name") function.

    What am I missing ?
    thanks


    Added after 18 minutes:


    Another question: is it possible to run lupdate automatically from the makefile ?
    If yes, what should I write in the .pro file ?
    Last edited by trallallero; 26th October 2011 at 07:46.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTranslator: the menu is not translated

    Are you putting "shortcut" characters into the menu item strings? If so, it could be that the translator is not finding an exact match, so does not make a translation.

  3. #3
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTranslator: the menu is not translated

    Yes, of course I put shortcuts. Anyway, it's not nice but I've solved with an UpdateMenus() function, thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTranslator: the menu is not translated

    Do you handle LanguageChange event for the widget that adds items to the menus?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTranslator: the menu is not translated

    Yes, I do.

    Qt Code:
    1. void MainWindow::changeEvent(QEvent* event)
    2. {
    3. if (event->type() == QEvent::LanguageChange)
    4. {
    5. ui->retranslateUi(this);
    6. SetTablesFields();
    7. UpdateMenus();
    8.  
    9. if (m_DBGui)
    10. m_DBGui->Retranslate();
    11. if (m_LogGui)
    12. m_LogGui->Retranslate();
    13. if (m_PluginOptionsGui)
    14. m_PluginOptionsGui->Retranslate();
    15. }
    16. QMainWindow::changeEvent(event);
    17. }
    18. ///////////////////////////////////////////////////////////////
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTranslator: the menu is not translated

    That's the proper way of retranslating widgets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTranslator: the menu is not translated

    Good to know that it's done in a proper way, thanks... so at least I know it's not my fault

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTranslator: the menu is not translated

    Just the name "UpdateMenus()" is a bit wrong here. Call it retranslateMenus() and also call it the first time you set items to the menu. Have a look at code generated by Designer, it has a similar method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    trallallero (28th October 2011)

Similar Threads

  1. QTranslator??
    By nthung in forum Newbie
    Replies: 21
    Last Post: 15th October 2011, 03:33
  2. "About app" not getting translated on Mac app menu in Japanese
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2011, 05:12
  3. Help with QTranslator
    By aarelovich in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 22:38
  4. Want to use QTranslator
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2008, 15:13
  5. "About app" not getting translated on Mac app menu
    By sharevari in forum Qt Programming
    Replies: 0
    Last Post: 24th January 2007, 16:24

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.