Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem about Dynamic Language Translation
Forum Updated to NodeBB v4.3 + New Features

Problem about Dynamic Language Translation

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xiazhouquan
    wrote on last edited by
    #1

    I want to implement Dynamic Language Translation in my application ,I implement the UI without qt Designer ,so I overload the changeEvent(QEvent *event) function ,but I can't switch the language ,what 's wrong with me .
    Here is my code structure :

    @
    CGameStartMenu::CGameStartMenu(QWidget *parent) :
    QWidget(parent)
    {
    NewButton = new QPushButton(tr("New Game"));
    OptionButton = new QPushButton(tr("Language"));

    translator=new QTranslator(this);
    translator->load ("zh.qm");

    retranslate ();
    changeLanguage ();
    

    }

    void CGameStartMenu::changeEvent (QEvent *event)
    {
    if(event->type ()==QEvent::LanguageChange)
    {
    retranslate ();
    }
    QWidget::changeEvent (event);

    }

    void CGameStartMenu::retranslate ()
    {
    NewButton->setText (tr("New Game"));
    OptionButton->setText (tr("Language"));

    }

    void CGameStartMenu::changeLanguage ()
    {
    // translator=new QTranslator(this);
    // translator->load ("zh");
    qApp->installTranslator (translator);
    }
    @

    Thank you !
    My regards!

    业精于勤荒于嬉,行成于思毁于随

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Probably because you install the translator (#11) after you retranslate your application (#10).

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sigrid
        wrote on last edited by
        #3

        This "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_dynamically_switch_between_languages_in_my_application_using_e.g_ contains a complete example that illustrates how you can implement dynamic translation. You can follow the setup from that example to see if that helps getting the translation to work.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved