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 can my program have 2 languages?
Forum Updated to NodeBB v4.3 + New Features

How can my program have 2 languages?

Scheduled Pinned Locked Moved General and Desktop
26 Posts 8 Posters 11.4k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    Hi! In my program i have an option at the preferences and you can change the language to English->Greek or Greek->English. I have a bool that when the language is Greek it is true and when it is English it is false. So what i am doing is at every message box or dialog i first check if the bool is greek or english and if it is true ( greek ) i translate the dialog to greek or if it is a messagebox the text is at greek.. So i am sure that this isn't the correct way to do that.. Can you tell me what is the correct way to provide my program with more than the the english language?

    I am using Ubuntu.

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

      There's a good overview at http://doc.qt.nokia.com/4.7/internationalization.html

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #3

        Qt have good integrated system for it.
        See "QTranslator":http://developer.qt.nokia.com/doc/qt-4.7/QTranslator.html

        --
        Vasiliy

        1 Reply Last reply
        0
        • V Offline
          V Offline
          valandil211
          wrote on last edited by
          #4

          Just make sure that when you write user-visible stuff (like the title of a dialog) you put the option tr("Insert text here") enabled. This will ease the translation process.

          I know you have accents in Greek, so it may be better to use

          @trUtf8("Insert text here")@

          Joey Dumont

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

            Also, you might want to re-think your design for switching. What if your application becomes a best-seller, and you'd like to expand to Turkey? Or to Italy? Even if in the UI you keep the choice simple, I'd make sure it is easy to add other languages as well in the rest of your application.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Leon
              wrote on last edited by
              #6

              [quote author="Joey Dumont" date="1309262146"]Just make sure that when you write user-visible stuff (like the title of a dialog) you put the option tr("Insert text here") enabled. This will ease the translation process.

              I know you have accents in Greek, so it may be better to use

              @trUtf8("Insert text here")@ [/quote]

              That's what am i using..

              [quote author="Vass" date="1309261862"]Qt have good integrated system for it.
              See "QTranslator":http://developer.qt.nokia.com/doc/qt-4.7/QTranslator.html[/quote]

              Could i have some tips at this? I don't know nothing about QTranslator.. Any example with a simple layer saying "Hello", i don't know something more than just a Class Reference :/

              EDIT: I am now reading Qt Linguist Manual. I hope it will help me..

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

                The following "FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_dynamically_switch_between_languages_in_my_application_using_e.g_ contains an example that can be useful.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  Leon
                  wrote on last edited by
                  #8

                  I just created my first translation file.. I will try to do it my own.. I will check the FAQ later.. Thanks :)

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    valandil211
                    wrote on last edited by
                    #9

                    If you consider your problem as solved, could you please the thread title and add [SOLVED].

                    Thanks!

                    Joey Dumont

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      soroush
                      wrote on last edited by
                      #10

                      You should read documentations carefully and you will have no problem.

                      In case that you couldn't managed to do the stuff, do these:

                      1- In your qt project file (.pro) add this line:
                      @TRANSLATIONS += program_gr.ts@
                      Of course names and number of translations are optional.

                      2- start lupdate tool (which is an executable installed with Qt SDK) given your project file name. for example:
                      @
                      lupdate ./program.pro
                      @
                      this scans your source code tree and determines translatable strings, then generates a XML-based translation file. in above example generates program_gr.ts.

                      3- Now you can perform actual translation! open your translation file with Qt Linguist and translate strings. then save the file and exit. It's easy !

                      4- Now that you have translated strings, you should make binary translation file. just call lrealease and give your ts file name:
                      @
                      lrealease program_gr.ts
                      @
                      this will generate profram_gr.qm that you can load in your program.

                      5- when application starts, load your qm file using QTranslator class. in a widget-based application it may look like this:
                      @
                      #include <QtGui/QApplication>
                      #include <QTranslator>
                      #include "mainwindow.h"

                      int main(int argc, char argv[])
                      {
                      QApplication a(argc, argv);
                      QTranslator
                      translator;
                      translator->load(a.applicationDirPath()+"/program_gr.qm"); // or other place that you put your .qm file
                      a.installTranslator(translator);
                      MainWindow w;
                      w.show();
                      return a.exec();
                      }
                      @

                      note that you can load translations dynamically and use them whenever you need. but you should be careful about calling translation method for all of dialogs.

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Leon
                        wrote on last edited by
                        #11

                        Basically i saw a tutorial here ( http://www.youtube.com/watch?v=V9Gep6-r8ns ). It is the same with yours except that i can't understant what the guy is saying at Indonesia language..

                        Also at step 5 i have this

                        @QTranslator translator;
                        translator.load("program_gr");
                        a.installTranslator(&translator);@

                        Ok so i create the gm file. BUT. As i said my program is for Ubuntu so i will make a deb file ( like setup.exe files at Windows.. ).. How can i provide the greek translation file and how after the program is installed users can translate the app to greek? ( Install my greek translation file so they can see the app translated at greek )

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          soroush
                          wrote on last edited by
                          #12

                          Ok, it looks like an "Installation and Deployment" problem...

                          In linux directories used for configuration files are:
                          /etc/program and /home/user_name/.program and /usr/share/program/

                          Due to linux file system standards I suggest put your translation files in /usr/share/program/translations.

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            Leon
                            wrote on last edited by
                            #13

                            Ok thanks for the info! I will try it.. When everything is ok i will edit my post to [SOLVED] :D

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              Leon
                              wrote on last edited by
                              #14

                              The translations at /usr/share/program/translations must be at .ts format or .qm format?

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                vsorokin
                                wrote on last edited by
                                #15

                                [quote author="Leon" date="1309285305"]The translations at /usr/share/program/translations must be at .ts format or .qm format?[/quote]

                                .qm

                                .ts format for developers (translation source)
                                .qm format for end users (translation binary)

                                --
                                Vasiliy

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  soroush
                                  wrote on last edited by
                                  #16

                                  [quote author="Leon" date="1309285305"]The translations at /usr/share/program/translations must be at .ts format or .qm format?[/quote]

                                  You need only qm files in runtime. ts files are used to translate. at runtime you want to load translated data.
                                  Also notice that there is no magic with /usr/share/program/translations. that was just a suggestion. you could put your translations in every other location...

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    Leon
                                    wrote on last edited by
                                    #17

                                    Ok thanks guys.. I am working on it..

                                    soroush i know it is a suggestion :P

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mlong
                                      wrote on last edited by
                                      #18

                                      The .qm files can also be included as resources, too.

                                      Software Engineer
                                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        Leon
                                        wrote on last edited by
                                        #19

                                        I am thinking of having english greek dutch and french language at my program.. Should i have a combobox with this 4 languages only ( using the resource file) or should i check for file existences at the path that i have my translations and then add them to the combobox?

                                        1 Reply Last reply
                                        0
                                        • V Offline
                                          V Offline
                                          vsorokin
                                          wrote on last edited by
                                          #20

                                          Second way sounds better - this allow your users adding new languages for your app without re-compilation.
                                          of course if your public .ts file.

                                          --
                                          Vasiliy

                                          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