Definition of a country code and language

I need to define the user language and country code in Qt. These codes must comply with the standards http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html .

I tried QLocale, but it returned the full name of the country and language in countryToString and languageToString. (I need a short code, such as "en", not "English".)

One way is to create a map of QLocale :: Language and QString. But is there a faster and easier way?

+4
source share
3 answers

See QLocale :: name ()

Returns the language and country of this language as the string form "language_country", where the language is a lowercase, two-letter ISO 639 language code, and the country is a capital, two- or three-letter ISO 3166 country code.

+6
source

In addition to Paul's answer, there are QLocale :: uiLanguages ​​() and QLocale :: bcp47Name () , which should give the changes.

+2
source

When we talk about the correct detection of the country that is really set in the user settings (Control Panel / Location in Windows, Preferences / Region in OS X), you should use https://github.com/crystalidea/qt-detect-user-country

0
source

All Articles