QLocale::system().script() always returning 0 on Windows
-
I am trying to distinguish between Serbian Latin and Serbian Cyrillic locales on Windows, but QLocale::system().script() seem to always return 0 (QLocale::Script::AnyScript).
I tried on Windows 7 and Windows 8.1, with Qt 5.4.2 as well as Qt 4.8.5, always with the same result. I also tried with other multi-script languages, but I never got anything other than QLocale::Script::AnyScript.
Is this a bug, or am I doing something wrong? Haven't found a matching QTBUG so far.
Also, the documentation for QLocale::bcp47Name() states that it "returns the dash-separated language, script and country (and possibly other BCP47 fields) of this locale as a string": http://qt-project.org/doc/qt-5.0/qtcore/qlocale.html#bcp47Name
However, for both Serbain (Cyrillic, Serbia) and Serbian (Latin, Serbia) I get "sr-RS" (with Qt 4.8.5) or just "sr" (with Qt 5.4.2, due to an already reported regression https://bugreports.qt.io/browse/QTBUG-34872). I never get the script in the result string.As a result, I couldn't find a regular way to distinguish between these locales. A possible workaround may be to examine the QLocale::system().nativeLanguageName(), but that's a very ugly hack that doesn't provide the solution for the general case, and I would rather avoid it if possible.
Thanks in advance for any help with this.
-
Hi and welcome to devnet,
Seems like there's indeed something going on. What results should you have exactly ?
-
Hello SGaist,
Thanks for your response. I expect for Serbian (Cyrillic, Serbia) to get:
- 2 (QLocale::Script::CyrillicScript) from QLocale::system().script(), and
- "sr-Cyrl-RS" from QLocale::system().bcp47Name().
Similarly, for Serbian (Latin, Serbia) I expect:
- 7 (QLocale::Script::LatinScript) from QLocale::system().script(), and
- "sr-Latn-RS" from QLocale::system().bcp47Name().
Should I open new bugs for script() and bcp47Name()?
This is the workaround I made for bcp47Name:
QString bcp47Name; #ifdef Q_OS_WIN wchar_t buffer[LOCALE_NAME_MAX_LENGTH]; ::GetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH); bcp47Name = QString::fromWCharArray(buffer); #else bcp47Name = QLocale::system().bcp47Name(); #endif
But didn't have a chance to try it on non-Windows platforms yet.
Thanks!