diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp index 13346c5506..eec718ae9b 100644 --- a/src/corelib/text/qlocale_unix.cpp +++ b/src/corelib/text/qlocale_unix.cpp @@ -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); diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 7095728dce..9c69e9fe4a 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -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()