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. Translate the result of QLocale::languageToString()

Translate the result of QLocale::languageToString()

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 6.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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Titles says it all.
    I am displaying a list of languages and I use QLocale::languageToString() somewhere in my code.
    I was wondering if it is possible to have it returns a string translated so when the program is in German I will get "Deutsch" and not "German"
    Thanks a lot guys!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      try

      @QString translated = tr(QLocale::languageToString().toAscii());@

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        This is what I already (and stupidly) wrote in my code (except I wrote ".toLatin1()").
        But this obviously does not generate correct translation files. lupdate would have to put all the possible strings in the *.ts files

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          It is possible that Qt already has a translation file for you there. You would have to add it to your application though.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JulienMaille
            wrote on last edited by
            #5

            "possible"? And where would I find this file?

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Franzk
              wrote on last edited by
              #6

              ${QTDIR}/translations/

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JulienMaille
                wrote on last edited by
                #7

                Already looked there. There are translation for Qt programs.
                Are you sure of your advice? From the beginning it looks like you just throw a guess and hope it will answer my question. This is not how you help people.
                Now the post count is increasing and someone who may actually know the answer won't event look at it.
                (Sorry if it sounds mean, I don't want to be rude)

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Franzk
                  wrote on last edited by
                  #8

                  Qt has pretranslated a bunch of things for their own widgets. You can (and should) add that translation file to your application if you use translations. What I'm unsure about is whether the language names are translated, but if they are, this is the place to find them.

                  "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulienMaille
                    wrote on last edited by
                    #9

                    Ok, maybe I should add manually the few language names I know I will be using.
                    I think there is a trick to add string that lupdate can find.

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      Franzk
                      wrote on last edited by
                      #10

                      Yes, "Q_TR_NOOP and Q_TRANSLATE_NOOP":http://doc.trolltech.com/latest/linguist-programmers.html#using-qt-tr-noop-and-qt-translate-noop

                      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JulienMaille
                        wrote on last edited by
                        #11

                        No, I would not call those macros a "trick". I was referring to the last section of this:
                        http://doc.qt.nokia.com/qq/qq03-swedish-chef.html

                        When tr() is Not Enough @ #if 0
                        qApp->translate( "CustomerDB", "Agency" );
                        qApp->translate( "CustomerDB", "Company" );
                        qApp->translate( "CustomerDB", "Foreign" );
                        qApp->translate( "CustomerDB", "International" );
                        #endif@

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rittk
                          wrote on last edited by
                          #12

                          QLocale::nativeLanguageName() is close to what you're looking for. It returns an endonym for the language so you'll be able to build a list like ( "English", "Deutsch", "Русский", ... )

                          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