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. Is there a way to get the current default locale?
QtWS25 Last Chance

Is there a way to get the current default locale?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 13.6k 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
    philk
    wrote on last edited by
    #1

    I see there is a Locale::setDefault but I am missing the Locale:default() method?
    What I currently do, to have the default locale available for Translation loading in my projects components, I create a dynamic "locale" property on the QCoreApplication object instance.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      did you read the doc-description of the method?!
      [quote]
      Sets the global default locale to locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used.
      [/quote]

      --- 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
      • B Offline
        B Offline
        butterface
        wrote on last edited by
        #3

        @
        std::cout << QLocale::system().name().toStdString() << std::endl;
        std::cout << QLocale().name().toStdString() << std::endl;
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          philk
          wrote on last edited by
          #4

          [quote author="raven-worx" date="1375862253"]did you read the doc-description of the method?!
          [quote]
          Sets the global default locale to locale. These values are used when a QLocale object is constructed with no arguments. If this function is not called, the system's locale is used.
          [/quote][/quote]

          Of course, I missed that in the docs. Works great!

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            yhu420
            wrote on last edited by
            #5

            If you want to translate your program, check that out:

            @QString locale = QLocale::system().name().section('', 0, 0);
            QTranslator translator;
            translator.load(QString("qt
            ") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
            app.installTranslator(&translator);@

            1 Reply Last reply
            0
            • P Offline
              P Offline
              philk
              wrote on last edited by
              #6

              I know how to translate the app/plugins. Thanks

              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