Fix qlocale_unix's handling of uiLanguages to take script into account
Some languages have, in the same territory, locales for more than one script. In such cases, since we ignored the script, we got the one that is used by default, instead of the one actually asked for. Take the script into account. Added TODO comment in test listing the known examples of this; manually tested before and after the fix to verify the prior code was indeed getting it wrong and now does do it right. Change-Id: Iaf9201d6992bc39e6e9346ef8b7c69d418db7253 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
7a7f2547f3
commit
0b5b98c4ae
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2021 The Qt Company Ltd.
|
||||
** Copyright (C) 2022 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
@ -280,14 +280,15 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
|
||||
else
|
||||
lst = languages.split(u':');
|
||||
|
||||
// Inadequate for various cases of a language that's written in more
|
||||
// than one script in the same country, e.g. Sindhi in India.
|
||||
// However, can clients of the UILanguage query cope if we include script ?
|
||||
for (int i = 0; i < lst.size(); ++i) {
|
||||
QStringView lang, cntry;
|
||||
if (qt_splitLocaleName(lst.at(i), &lang, nullptr, &cntry)) {
|
||||
d->uiLanguages.append(
|
||||
cntry.size() ? lang % u'-' % cntry : lang.toString());
|
||||
QStringView language, script, territory;
|
||||
if (qt_splitLocaleName(lst.at(i), &language, &script, &territory)) {
|
||||
QString joined = language.isEmpty() ? u"und"_qs : language.toString();
|
||||
if (!script.isEmpty())
|
||||
joined += u'-' + script;
|
||||
if (!territory.isEmpty())
|
||||
joined += u'-' + territory;
|
||||
d->uiLanguages.append(joined);
|
||||
}
|
||||
}
|
||||
return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages);
|
||||
|
@ -2962,6 +2962,12 @@ void tst_QLocale::uiLanguages_data()
|
||||
QTest::newRow("zh_Hans_CN")
|
||||
<< QLocale(QLocale::Chinese, QLocale::SimplifiedHanScript, QLocale::China)
|
||||
<< QStringList{QString("zh-Hans-CN"), QString("zh-CN"), QString("zh")};
|
||||
|
||||
// TODO: test actual system backends correctly handle locales with
|
||||
// script-specificity (script listed first is the default, in CLDR v40):
|
||||
// az_{Latn,Cyrl}_AZ, bs_{Latn,Cyrl}_BA, sr_{Cyrl,Latn}_{BA,RS,XK,UZ},
|
||||
// sr_{Latn,Cyrl}_ME, ff_{Latn,Adlm}_{BF,CM,GH,GM,GN,GW,LR,MR,NE,NG,SL,SN},
|
||||
// shi_{Tfng,Latn}_MA, vai_{Vaii,Latn}_LR, zh_{Hant,Hans}_{MO,HK}
|
||||
}
|
||||
|
||||
void tst_QLocale::uiLanguages()
|
||||
|
Loading…
Reference in New Issue
Block a user