C++ – Country and language code detecting

cfreedesktop.orglocalizationqt

I need to detect user's language and country code in Qt. That codes must be matching standards at http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html.

I've tried QLocale, but it returned full country and language name in countryToString and languageToString. (I need short code, like "en" instead of "English".)

One of the ways is creating map of QLocale::Language and QString. But is there any faster and simpler way?

Best Answer

See QLocale::name()

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