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 get current application language
QtWS25 Last Chance

How to get current application language

Scheduled Pinned Locked Moved General and Desktop
20 Posts 9 Posters 16.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.
  • Q Offline
    Q Offline
    qtforet
    wrote on 27 Jan 2015, 01:17 last edited by
    #10

    [quote author="koplersky" date="1421693019"]Thank you Dheerendra, but I don't think that helps.
    I'm using QTranslator::load() and QCoreApplication::​installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.

    I already have a workaround for this, but I was just wondering if there is a direct way to get this information.[/quote]

    What workaround did you use?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qtforet
      wrote on 27 Jan 2015, 01:17 last edited by
      #11

      [quote author="koplersky" date="1421693019"]Thank you Dheerendra, but I don't think that helps.
      I'm using QTranslator::load() and QCoreApplication::​installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.

      I already have a workaround for this, but I was just wondering if there is a direct way to get this information.[/quote]

      What workaround did you use?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 27 Jan 2015, 07:55 last edited by
        #12

        a little trick would be to add a translation for e.g. APP_LANGUAGE to every translation file and to translate it to the language's native name for each.

        Then you simply can use
        @
        QObject::tr("APP_LANGUAGE")
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1
        • R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 27 Jan 2015, 07:55 last edited by
          #13

          a little trick would be to add a translation for e.g. APP_LANGUAGE to every translation file and to translate it to the language's native name for each.

          Then you simply can use
          @
          QObject::tr("APP_LANGUAGE")
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qtforet
            wrote on 27 Jan 2015, 20:05 last edited by
            #14

            It turns out to be very simple:
            http://stackoverflow.com/questions/28161888/how-to-find-current-qlocale-in-qt-pyqt-pyside

            Just enter
            x=QtCore.QLocale()

            and then all the QLocale methods apply to x. E.g.,
            x.language()

            That's Python, probably similar in c++

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qtforet
              wrote on 27 Jan 2015, 20:05 last edited by
              #15

              It turns out to be very simple:
              http://stackoverflow.com/questions/28161888/how-to-find-current-qlocale-in-qt-pyqt-pyside

              Just enter
              x=QtCore.QLocale()

              and then all the QLocale methods apply to x. E.g.,
              x.language()

              That's Python, probably similar in c++

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on 28 Jan 2015, 07:47 last edited by
                #16

                The current locale is not the same as the current application language. We allow switching the application language manually for instance (though the default is based on the locale).

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on 28 Jan 2015, 07:47 last edited by
                  #17

                  The current locale is not the same as the current application language. We allow switching the application language manually for instance (though the default is based on the locale).

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kumararajas
                    wrote on 28 Jan 2015, 10:51 last edited by
                    #18

                    How about managing it logically?

                    Example: Maintain a member variable called m_currentLanguage to contain the information about current language and refer it whenever required.

                    --Kumar

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kumararajas
                      wrote on 28 Jan 2015, 10:51 last edited by
                      #19

                      How about managing it logically?

                      Example: Maintain a member variable called m_currentLanguage to contain the information about current language and refer it whenever required.

                      --Kumar

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        WolfgangGriech
                        wrote on 24 Mar 2025, 01:04 last edited by
                        #20

                        10 years later, but it was an issue for me too. So here's the simple solution, the QLocale() default constructor returns the current application settings, so the following returns the current application language as a string:

                        QLocale::languageToString ( QLocale().language() )

                        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