質問

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?

役に立ちましたか?

解決

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.

他のヒント

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

When we talk about correct detection of country actually set in user preferences (Control Panel/Location on Windows, Preferences/Region on OS X), you should be using https://github.com/crystalidea/qt-detect-user-country

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top