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. Multi Language Application
Forum Updated to NodeBB v4.3 + New Features

Multi Language Application

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.9k Views 4 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.
  • M Offline
    M Offline
    mahd96
    wrote on 21 Jul 2018, 07:43 last edited by
    #1

    Is there a way to force re-translation after installing new translator?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 21 Jul 2018, 07:53 last edited by
      #2

      Yes. If you are using QtWidgets, see the retranslateUi() that Qt Creator automatically adds to UI classes (if it still does).

      If you are using QML, then the (current) best solution is to create a global property (for example app.empty) and use it for all translatable strings, like so:

      Text {
        text: app.empty + qsTr("My string")
      }
      

      Then after installing the new translation all you need to do is to emit mptyChanged() signal. There is a better solution in the works, but it is not ready yet. Maybe in Qt 5.12 it will become available, I'm not sure. Well, it is available now, but it forces all bindings to be recalculated, so it is not a good thing at all.

      (Z(:^

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mahd96
        wrote on 21 Jul 2018, 08:13 last edited by mahd96
        #3

        I am using QWidgets but no UI file.
        actualy i made all my ui with layouts and styles so i didn't use UI.
        and retranslateUI funstion only works with UI files not QWidgets.

        what should i do in this case?

        S 1 Reply Last reply 21 Jul 2018, 08:21
        0
        • M mahd96
          21 Jul 2018, 08:13

          I am using QWidgets but no UI file.
          actualy i made all my ui with layouts and styles so i didn't use UI.
          and retranslateUI funstion only works with UI files not QWidgets.

          what should i do in this case?

          S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 21 Jul 2018, 08:21 last edited by
          #4

          @mahd96 said in Multi Language Application:

          I am using QWidgets but no UI file.
          actualy i made all my ui with layouts and styles so i didn't use UI.
          and retranslateUI funstion only works with UI files not QWidgets.

          what should i do in this case?

          Write your own retlanslateUi() function. You can leanr about it C++ GUI programming book, for example (chapter "Making your applications translation aware").

          (Z(:^

          1 Reply Last reply
          2
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 21 Jul 2018, 08:50 last edited by
            #5

            Hi
            Just as a note
            retranslateUi is not magical by any means. it just re-sets the text for u if created via designer.

            void retranslateUi(QMainWindow *MainWindow)
            {
            MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
            pushButton->setText(QApplication::translate("MainWindow", "load", nullptr));
            pushButton_2->setText(QApplication::translate("MainWindow", "save", nullptr));
            pushButton_3->setText(QApplication::translate("MainWindow", "clear", nullptr));
            }

            So to make your own, you just have to re-set any text you have.

            M 1 Reply Last reply 12 Aug 2018, 06:51
            2
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 21 Jul 2018, 20:28 last edited by
              #6

              Hi,

              The technique to use is described in the dynamic translation part of Qt's translation documentation.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              4
              • M mrjj
                21 Jul 2018, 08:50

                Hi
                Just as a note
                retranslateUi is not magical by any means. it just re-sets the text for u if created via designer.

                void retranslateUi(QMainWindow *MainWindow)
                {
                MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
                pushButton->setText(QApplication::translate("MainWindow", "load", nullptr));
                pushButton_2->setText(QApplication::translate("MainWindow", "save", nullptr));
                pushButton_3->setText(QApplication::translate("MainWindow", "clear", nullptr));
                }

                So to make your own, you just have to re-set any text you have.

                M Offline
                M Offline
                mahd96
                wrote on 12 Aug 2018, 06:51 last edited by
                #7

                @mrjj i am talking about a project as big as Qt Creator itself!
                its not possible to reset every text!

                M 1 Reply Last reply 12 Aug 2018, 08:22
                0
                • M mahd96
                  12 Aug 2018, 06:51

                  @mrjj i am talking about a project as big as Qt Creator itself!
                  its not possible to reset every text!

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 12 Aug 2018, 08:22 last edited by
                  #8

                  @mahd96
                  Hi
                  But sadly it is the only way if you want to do it live.
                  So its much easier to require restart of restart app.

                  1 Reply Last reply
                  2
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 12 Aug 2018, 21:43 last edited by
                    #9

                    Even for big projects, if you implement changeEvent for all your custom widgets, it's completely transparent.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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