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. How to change languages online?

How to change languages online?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 422 Views
  • 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.
  • Q Offline
    Q Offline
    Qingshui Kong
    wrote on last edited by
    #1

    Hello everyone,

    I need some help.

    I design a qt application. And it contains a lot of UIs. And there are many labels and buttons (and so on) whose text is changed by C++ code in some UIs. I want it to be international. So I need to translate to many languages. That's ok.

    But I want to change languages online. I mean I hope it changes to the destination language immediately after I click change languages. I don't want to restart the application.
    What should I? Could somebody give me some advices?

    I use Qt5.9.1.

    Thanks in advance!

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @Qingshui-Kong, see https://doc.qt.io/qt-5/internationalization.html#dynamic-translation

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      Q 1 Reply Last reply
      4
      • O Offline
        O Offline
        ollarch
        wrote on last edited by
        #3

        Hi,

        You will have to create a method like retranslate() on every UI. Just set the text there using tr().

        MyWidget::retranslate() { ui.label1->setText(tr("Translate text 1")); ui.pushButton1->setText(tr("Click it!")); ... }

        Finally, on your mainWindow just call retranslate() on all of your UIs.

        1 Reply Last reply
        1
        • JKSHJ JKSH

          Hi @Qingshui-Kong, see https://doc.qt.io/qt-5/internationalization.html#dynamic-translation

          Q Offline
          Q Offline
          Qingshui Kong
          wrote on last edited by
          #4

          @jksh @ollarch
          Thank you very much!
          You mean I have to set the text for every items on all of my UIs?
          There are too many items. And some items don't belong to any UI.

          O 1 Reply Last reply
          0
          • Q Qingshui Kong

            @jksh @ollarch
            Thank you very much!
            You mean I have to set the text for every items on all of my UIs?
            There are too many items. And some items don't belong to any UI.

            O Offline
            O Offline
            ollarch
            wrote on last edited by
            #5

            Hi,

            It seems that in new Qt versions, there is a retranslateUi() that the UIC creates automatically, so basically you have to load the QTranslator with the correct file and call the retranslateUi()on all UIs.
            For the items that do not belong to any UI, and so the UIC does not do the job for you, yes, you have to call do it manually.

            What some other softwares do is that it changes the language and restart the application with the help of QProcess.

            Q 1 Reply Last reply
            1
            • O ollarch

              Hi,

              It seems that in new Qt versions, there is a retranslateUi() that the UIC creates automatically, so basically you have to load the QTranslator with the correct file and call the retranslateUi()on all UIs.
              For the items that do not belong to any UI, and so the UIC does not do the job for you, yes, you have to call do it manually.

              What some other softwares do is that it changes the language and restart the application with the help of QProcess.

              Q Offline
              Q Offline
              Qingshui Kong
              wrote on last edited by
              #6

              @ollarch
              OK. Thanks a lot!

              1 Reply Last reply
              1

              • Login

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