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>
This commit is contained in:
parent
536b38c1d3
commit
dc3e7e45eb
@ -48,6 +48,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WINRT
|
#ifdef Q_OS_WINRT
|
||||||
|
#include <qfunctions_winrt.h>
|
||||||
|
|
||||||
#include <wrl.h>
|
#include <wrl.h>
|
||||||
#include <windows.foundation.h>
|
#include <windows.foundation.h>
|
||||||
#include <windows.foundation.collections.h>
|
#include <windows.foundation.collections.h>
|
||||||
@ -644,21 +646,53 @@ QVariant QSystemLocalePrivate::uiLanguages()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ComPtr<ABI::Windows::Foundation::Collections::IVectorView<HSTRING> > languageList;
|
ComPtr<ABI::Windows::Foundation::Collections::IVectorView<HSTRING> > languageList;
|
||||||
appLanguagesStatics->get_ManifestLanguages(&languageList);
|
// 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.
|
||||||
if (!languageList)
|
HRESULT hr = appLanguagesStatics->get_Languages(&languageList);
|
||||||
return QStringList();
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
|
||||||
unsigned int size;
|
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) {
|
for (unsigned int i = 0; i < size; ++i) {
|
||||||
HString language;
|
HString language;
|
||||||
languageList->GetAt(i, language.GetAddressOf());
|
hr = languageList->GetAt(i, language.GetAddressOf());
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
UINT32 length;
|
UINT32 length;
|
||||||
PCWSTR rawString = language.GetRawBuffer(&length);
|
PCWSTR rawString = language.GetRawBuffer(&length);
|
||||||
result << QString::fromWCharArray(rawString, 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;
|
return result;
|
||||||
#endif // Q_OS_WINRT
|
#endif // Q_OS_WINRT
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user