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 use tr () for ui widgets

How to use tr () for ui widgets

Scheduled Pinned Locked Moved General and Desktop
27 Posts 4 Posters 10.2k 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.
  • P Offline
    P Offline
    pragati
    wrote on last edited by
    #1

    Hi all,

    I want a multilingual application, in which language of the app changes as we select respective option from the drop down menu.
    Noticeable thing here is that is I have used ui file in my code instead of creating it in the code, hence confused how to use tr()??
    Thought of including in ui_Filename.h file...but I have to do it again and again when i remake the code, which I don't want.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      In the Designer, you can find and set the property text->"translatable".


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pragati
        wrote on last edited by
        #3

        With this, i don't have to put tr() everywhere like i would do if i have created in source code?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          Th uic places a method called retranslateUI in the UI class. Just call that method.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pragati
            wrote on last edited by
            #5

            still will when have to define retranslateui function, I have to use ui widgets and put tr() in it....How it helps??

            Please help,
            Thanks

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rahul Das
              wrote on last edited by
              #6

              Using tr() is same as checking "translatable". You don't need to use tr() inside Designer - text property.

              Just check ui->retranslateUi(mainWindow*) is there or not. ;) I dont think you need to re implement!


              Declaration of (Platform) independence.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                Note that user-visible strings in properties in Designer/Creator are by default already marked translatable. They will appear in your strings-to-be-translated by default. If you look at the code generated by uic, you will also see that these strings are translatable by default.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Rahul Das
                  wrote on last edited by
                  #8

                  uic produes ui_*.h files. And If you see, retranslateUi, there, you'll find the strings that are passed to [[doc:QApplication::translate]].


                  Declaration of (Platform) independence.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pragati
                    wrote on last edited by
                    #9

                    Thanks everyone, I can now able to get all my widgets of ui in the translation file.
                    But still even after loading the translation files. language doesn't changed.....
                    I am simply doing this in main.cpp after creating Ts and qm files

                    @QTranslator translator;
                    translator.load("setup_de ");
                    app.installTranslator(&translator);
                    @

                    I know there is something wrong ;)...hope you can help.....I am finding Qlinguist very complicated...:(
                    Thanks......

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Rahul Das
                      wrote on last edited by
                      #10

                      You can "Edit" your post instead of re-posting.

                      @translator.load("setup_de ");@

                      is having an extra space at the end?

                      And do you have @TRANSLATIONS = setup_de.ts@ in your .pro file ?


                      Declaration of (Platform) independence.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pragati
                        wrote on last edited by
                        #11

                        I got this post twice by mistake...I know about the "edit" :)
                        Want to delete this post.....

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pragati
                          wrote on last edited by
                          #12

                          I have included in .ts file in my .pro file, and removed the extra space too...still didn't get language changed!!!

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            Rahul Das
                            wrote on last edited by
                            #13

                            Happens! :)
                            By the way, make sure, your executable can find your qm file.

                            EDIT :

                            Try giving absolute / relative path of your qm file. Say
                            @translator.load("../setup_de");@ And whats the result ?


                            Declaration of (Platform) independence.

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              pragati
                              wrote on last edited by
                              #14

                              okay I am here little bit confused...Here I want my ui to change its language from english to say german.
                              Now, I have created a .ts file and saved each text written in my ui (Forms) with a german translation. Then I created a .qm file.
                              And in code (main.cpp) simply wrote :
                              @QTranslator translator;
                              translator.load("setup_de");
                              app.installTranslator(&translator);
                              @

                              All this and done.....what was the use of retranslateUi()

                              Even though I am not able to make this happen, the other requirements of my code is I need to change same Ui in 5 lnguages each one happening on a click on a lineedit....Anyway this is the later part...I am facing problem in just changing into a single language...:(

                              What's missing?

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Rahul Das
                                wrote on last edited by
                                #15

                                lets do the basic steps first. At the moment, just dont worry about the retranslateUi.

                                Assume, your Ui texts are English.

                                1. in pro file : TRANSLATIONS = setup_de.ts

                                2. Install translator
                                  @
                                  QTranslator translator;
                                  translator.load("/path/to/setup_de");
                                  app.installTranslator(&translator);
                                  @

                                3.lupdate *.pro

                                4.Open *.ts in Linguist. And give translation for each source texts.

                                5.lrelease *.pro

                                Now, you run your executable :)

                                EDIT : Note that path to setup_de is the path to setup_de.qm


                                Declaration of (Platform) independence.

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  pragati
                                  wrote on last edited by
                                  #16

                                  Exactly followed these steps....:(

                                  Tried giving absolute path to .qm file also still nothing....

                                  My code is having many ui forms...I have translated only single screen's ui into german....expecting that after run, that screen only will show in german....
                                  This cant be any reason for my problem??

                                  1 Reply Last reply
                                  0
                                  • R Offline
                                    R Offline
                                    Rahul Das
                                    wrote on last edited by
                                    #17

                                    You are installing [[doc:QTranslator]] to app. Not just a class.

                                    whats the result of
                                    @qDebug()<< translator.load("/path/to/setup_de");@ ?


                                    Declaration of (Platform) independence.

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      pragati
                                      wrote on last edited by
                                      #18

                                      Will check..... :)

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        pragati
                                        wrote on last edited by
                                        #19

                                        Result is "True"
                                        :P

                                        1 Reply Last reply
                                        0
                                        • P Offline
                                          P Offline
                                          pragati
                                          wrote on last edited by
                                          #20

                                          :(

                                          Followed the steps for a new project in which there is just one form and one main.cpp and nothing else ....(just to try changing ui in other language)
                                          It was working fine....But not happening in the code where there are so many Ui forms....what could be the reason?

                                          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