Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.
Forum Updated to NodeBB v4.3 + New Features

Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
18 Posts 5 Posters 4.3k Views 3 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    There is a way to force each string to be updated when you change the language.

    Define "empty" property and attach it to all your strings.

    // C++ side. Expose this property to QML via root context, or QML singleton - whatever
    Q_PROPERTY(int empty READ empty NOTIFY emptyChanged)
    // QML side
    text: qsTr("Some translatable text") + empty
    

    Now, when you change the translation (.qm file), just emit EmptyChanged() signal. You don't need to change it's value, just emit the signal. All strings will be reloaded.

    (Z(:^

    Akshay SinghA ekkescornerE 2 Replies Last reply
    2
    • sierdzioS sierdzio

      There is a way to force each string to be updated when you change the language.

      Define "empty" property and attach it to all your strings.

      // C++ side. Expose this property to QML via root context, or QML singleton - whatever
      Q_PROPERTY(int empty READ empty NOTIFY emptyChanged)
      // QML side
      text: qsTr("Some translatable text") + empty
      

      Now, when you change the translation (.qm file), just emit EmptyChanged() signal. You don't need to change it's value, just emit the signal. All strings will be reloaded.

      Akshay SinghA Offline
      Akshay SinghA Offline
      Akshay Singh
      wrote on last edited by
      #3

      @sierdzio wow, Thank you so much...This is one of the best and simplest way to the same.........

      I will apply the changes and reply you back.
      Thanks.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        Well, I'm not saying it is the best solution, but definitely a simple one and it works (I've seen it in one project, but I am not the author). It would be cool if Qt included some official solution to this.

        (Z(:^

        Akshay SinghA 1 Reply Last reply
        0
        • sierdzioS sierdzio

          Well, I'm not saying it is the best solution, but definitely a simple one and it works (I've seen it in one project, but I am not the author). It would be cool if Qt included some official solution to this.

          Akshay SinghA Offline
          Akshay SinghA Offline
          Akshay Singh
          wrote on last edited by Akshay Singh
          #5

          @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.Its lengthy but works. I applied and its working fine. Thanks mate. It helped a lot.

          Its just same as including a .ts and .qm file in project. There it automatically pics the lines you have to change and here You have to go through your project for getting the lines to be changed.

          E 1 Reply Last reply
          1
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #6

            Cool, thanks for feedback. Happy coding! (and if the issue is indeed solved, please mark this thread as solved, too. Maybe it will help somebody else, too)

            (Z(:^

            Akshay SinghA 1 Reply Last reply
            0
            • sierdzioS sierdzio

              Cool, thanks for feedback. Happy coding! (and if the issue is indeed solved, please mark this thread as solved, too. Maybe it will help somebody else, too)

              Akshay SinghA Offline
              Akshay SinghA Offline
              Akshay Singh
              wrote on last edited by
              #7

              Sure :)

              1 Reply Last reply
              0
              • Akshay SinghA Akshay Singh

                @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.Its lengthy but works. I applied and its working fine. Thanks mate. It helped a lot.

                Its just same as including a .ts and .qm file in project. There it automatically pics the lines you have to change and here You have to go through your project for getting the lines to be changed.

                E Offline
                E Offline
                Eeli K
                wrote on last edited by
                #8

                @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                Why it needs distinct property for each text?

                Akshay SinghA sierdzioS 3 Replies Last reply
                0
                • sierdzioS sierdzio

                  There is a way to force each string to be updated when you change the language.

                  Define "empty" property and attach it to all your strings.

                  // C++ side. Expose this property to QML via root context, or QML singleton - whatever
                  Q_PROPERTY(int empty READ empty NOTIFY emptyChanged)
                  // QML side
                  text: qsTr("Some translatable text") + empty
                  

                  Now, when you change the translation (.qm file), just emit EmptyChanged() signal. You don't need to change it's value, just emit the signal. All strings will be reloaded.

                  ekkescornerE Offline
                  ekkescornerE Offline
                  ekkescorner
                  Qt Champions 2016
                  wrote on last edited by
                  #9

                  @sierdzio curios:
                  BlackBerry10 Cascades did something similar ;-)
                  https://developer.blackberry.com/native/reference/cascades/bb__cascades__qmlretranslate.html

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                  5.15 --> 6.9 https://t1p.de/ekkeChecklist
                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                  1 Reply Last reply
                  0
                  • E Eeli K

                    @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                    @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                    Why it needs distinct property for each text?

                    Akshay SinghA Offline
                    Akshay SinghA Offline
                    Akshay Singh
                    wrote on last edited by
                    #10
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • E Eeli K

                      @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                      @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                      Why it needs distinct property for each text?

                      Akshay SinghA Offline
                      Akshay SinghA Offline
                      Akshay Singh
                      wrote on last edited by Akshay Singh
                      #11

                      @Eeli-K said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                      @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                      @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                      Why it needs distinct property for each text?

                      Hey thanks for pointing out the mistake. Now everyone will find me fool....but anyway
                      here is what I was doing->I was using QProperty as a String and using signal to change the text. Giving that string property a already translated text. And changing on a click of a button.

                      Thanks for pointing out the mistake sir. Now only empty property is to be added for every qsTr() string. I used the changes and project is working fine.

                      But on thing is remaining there. 0 number is added automatically at the end of the text,this is because I am using int property. Well I will do my own experiments and update when It will be working properly.

                      Am sorry for my mistake.Thanks again

                      Akshay SinghA sierdzioS 2 Replies Last reply
                      0
                      • Akshay SinghA Akshay Singh

                        @Eeli-K said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                        @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                        @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                        Why it needs distinct property for each text?

                        Hey thanks for pointing out the mistake. Now everyone will find me fool....but anyway
                        here is what I was doing->I was using QProperty as a String and using signal to change the text. Giving that string property a already translated text. And changing on a click of a button.

                        Thanks for pointing out the mistake sir. Now only empty property is to be added for every qsTr() string. I used the changes and project is working fine.

                        But on thing is remaining there. 0 number is added automatically at the end of the text,this is because I am using int property. Well I will do my own experiments and update when It will be working properly.

                        Am sorry for my mistake.Thanks again

                        Akshay SinghA Offline
                        Akshay SinghA Offline
                        Akshay Singh
                        wrote on last edited by Akshay Singh
                        #12

                        Using QString in place of int for Q_PROPERTY, it worked. Thanks to all.

                        1 Reply Last reply
                        0
                        • E Eeli K

                          @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                          @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                          Why it needs distinct property for each text?

                          sierdzioS Offline
                          sierdzioS Offline
                          sierdzio
                          Moderators
                          wrote on last edited by
                          #13

                          @Eeli-K said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                          Why it needs distinct property for each text?

                          It does not. You can use the same "empty" property for all strings.

                          (Z(:^

                          E 1 Reply Last reply
                          0
                          • Akshay SinghA Akshay Singh

                            @Eeli-K said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                            @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                            @sierdzio Yeah.....But this simple method is very easy to implement. You just have to note that..every text in qml should change according to the corresponding property. Every distinct text should have distinct property.

                            Why it needs distinct property for each text?

                            Hey thanks for pointing out the mistake. Now everyone will find me fool....but anyway
                            here is what I was doing->I was using QProperty as a String and using signal to change the text. Giving that string property a already translated text. And changing on a click of a button.

                            Thanks for pointing out the mistake sir. Now only empty property is to be added for every qsTr() string. I used the changes and project is working fine.

                            But on thing is remaining there. 0 number is added automatically at the end of the text,this is because I am using int property. Well I will do my own experiments and update when It will be working properly.

                            Am sorry for my mistake.Thanks again

                            sierdzioS Offline
                            sierdzioS Offline
                            sierdzio
                            Moderators
                            wrote on last edited by
                            #14

                            @Akshay-Singh said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                            0 number is added automatically at the end of the text,this is because I am using int property.

                            Yeah, I used int to save me some typing ;-) Using an empty string is much better, indeed, it won't give you an "0" appended to all texts.

                            (Z(:^

                            1 Reply Last reply
                            0
                            • sierdzioS sierdzio

                              @Eeli-K said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                              Why it needs distinct property for each text?

                              It does not. You can use the same "empty" property for all strings.

                              E Offline
                              E Offline
                              Eeli K
                              wrote on last edited by
                              #15

                              @sierdzio said in Is it possible to Dynamically change the language of Qt Control 2 app using Linguistic, lupdate, .qm,.ts files.:

                              It does not. You can use the same "empty" property for all strings.

                              I knew that already, I just wondered why Akshay said so, and he then noticed it, too :)

                              1 Reply Last reply
                              0
                              • sierdzioS Offline
                                sierdzioS Offline
                                sierdzio
                                Moderators
                                wrote on last edited by
                                #16

                                Ah, ok, sorry :-)

                                (Z(:^

                                1 Reply Last reply
                                0
                                • LorenzL Offline
                                  LorenzL Offline
                                  Lorenz
                                  wrote on last edited by
                                  #17

                                  Hi,

                                  For a simple tutorial on this issue, have a look at this: https://v-play.net/doc/howto-multi-language/

                                  The tutorial uses the V-Play SDK, but it works the same way for standard Qt apps.

                                  Cheers,
                                  Lorenz

                                  Developer @ V-Play Engine - http://v-play.net/qt

                                  V-Play simplifies

                                  • Game Development with Qt
                                  • Mobile App Dev with Qt esp. iOS & Android

                                  What others say
                                  V-Play scored #1 in Cross-Platform App Development Tools Report - see why: https://goo.gl/rgp3rq

                                  1 Reply Last reply
                                  0
                                  • Akshay SinghA Offline
                                    Akshay SinghA Offline
                                    Akshay Singh
                                    wrote on last edited by Akshay Singh
                                    #18

                                    Thanks Everyone for helping me out. Now am having a running project. This is a topic whose solution can not be found easily. So here I uploaded my project in Github. So the beginners can have a look at it. It is the most simplest project that I can make.

                                    Sorry for the naming of the project and files. :p

                                    https://github.com/AkshaySingh0294/QT-Language-Translation-with-QObject-class.git

                                    Refer my .md file for understanding it more correctly

                                    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