summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@theqtcompany.com>2015-09-25 15:26:07 +0200
committerMaurice Kalinowski <maurice.kalinowski@theqtcompany.com>2015-11-19 19:59:33 +0000
commitdc3e7e45ebe447c139868cc161b484eac478194d (patch)
tree62a4c687188b44fdab83ef6f4c4242b01edbfe97 /src
parent536b38c1d3c2e8da78232d86416d17ce0563f1b3 (diff)
winrt: Merge Languages and ManifestLanguages for QLocale::uiLanguages
Task-number: QTBUG-48140 Change-Id: I904ad48e7bc48867a362e3f6c5ca1516e55ed872 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale_win.cpp48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/corelib/tools/qlocale_win.cpp b/src/corelib/tools/qlocale_win.cpp
index 574453f4ca..a5eb7ec058 100644
--- a/src/corelib/tools/qlocale_win.cpp
+++ b/src/corelib/tools/qlocale_win.cpp
@@ -48,6 +48,8 @@
#endif
#ifdef Q_OS_WINRT
+#include <qfunctions_winrt.h>
+
#include <wrl.h>
#include <windows.foundation.h>
#include <windows.foundation.collections.h>
@@ -644,21 +646,53 @@ QVariant QSystemLocalePrivate::uiLanguages()
}
ComPtr<ABI::Windows::Foundation::Collections::IVectorView<HSTRING> > languageList;
- appLanguagesStatics->get_ManifestLanguages(&languageList);
-
- if (!languageList)
- return QStringList();
-
+ // Languages is a ranked list of "long names" (e.g. en-US) of preferred languages, which matches
+ // languages from the manifest with languages from the user's system.
+ HRESULT hr = appLanguagesStatics->get_Languages(&languageList);
+ Q_ASSERT_SUCCEEDED(hr);
unsigned int size;
- languageList->get_Size(&size);
+ hr = languageList->get_Size(&size);
+ Q_ASSERT_SUCCEEDED(hr);
+ result.reserve(size);
for (unsigned int i = 0; i < size; ++i) {
HString language;
- languageList->GetAt(i, language.GetAddressOf());
+ hr = languageList->GetAt(i, language.GetAddressOf());
+ Q_ASSERT_SUCCEEDED(hr);
UINT32 length;
PCWSTR rawString = language.GetRawBuffer(&length);
result << QString::fromWCharArray(rawString, length);
}
+ // ManifestLanguages covers all languages given in the manifest and uses short names (like "en").
+ hr = appLanguagesStatics->get_ManifestLanguages(&languageList);
+ Q_ASSERT_SUCCEEDED(hr);
+ hr = languageList->get_Size(&size);
+ Q_ASSERT_SUCCEEDED(hr);
+ for (unsigned int i = 0; i < size; ++i) {
+ HString language;
+ hr = languageList->GetAt(i, language.GetAddressOf());
+ Q_ASSERT_SUCCEEDED(hr);
+ UINT32 length;
+ PCWSTR rawString = language.GetRawBuffer(&length);
+ const QString qLanguage = QString::fromWCharArray(rawString, length);
+ bool found = false;
+ // Since ApplicationLanguages:::Languages uses long names, we compare the "pre-dash" part of
+ // the language and filter it out, if it is already covered by a more specialized form.
+ foreach (const QString &lang, result) {
+ int dashIndex = lang.indexOf('-');
+ // There will not be any long name after the first short name was found, so we can stop.
+ if (dashIndex == -1)
+ break;
+
+ if (lang.leftRef(dashIndex) == qLanguage) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ result << qLanguage;
+ }
+
return result;
#endif // Q_OS_WINRT
}