diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index da2f57fb12c..34b6b9d52eb 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -5209,23 +5209,24 @@ QStringList QLocale::uiLanguages(TagSeparator separator) const qsizetype stopAt = uiLanguages.size(); QString prefix = entry; qsizetype at = 0; - /* By default we append but if no later entry has this as a prefix and - the locale it implies would use the same script as entry, put it - after the block of consecutive equivalents of which entry is a part - instead. Thus [en-NL, nl-NL, en-GB] will append en but [en-NL, en-GB, - nl-NL] will put it before nl-NL, for example. We require a script - match so we don't pick translations that the user cannot read, - despite knowing the language. (Ideally that would be a constraint the - caller can opt into / out of. See QTBUG-112765.) - */ - bool justAfter - = QLocaleId::fromName(prefix).withLikelySubtagsAdded().script_id == max.script_id; while ((at = prefix.lastIndexOf(cut)) > 0) { prefix = prefix.first(at); // Don't test with hasSeen() as we might defer adding to later, when // we'll need known to see the later entry's offering of this prefix // as a new entry. bool found = known.contains(prefix); + /* By default we append but if no later entry has this as a prefix + and the locale it implies would use the same script as entry, put + it after the block of consecutive equivalents of which entry is a + part instead. Thus [en-NL, nl-NL, en-GB] will append en but + [en-NL, en-GB, nl-NL] will put it before nl-NL, for example. We + require a script match so we don't pick translations that the + user cannot read, despite knowing the language. (Ideally that + would be a constraint the caller can opt into / out of. See + QTBUG-112765.) + */ + bool justAfter + = (QLocaleId::fromName(prefix).withLikelySubtagsAdded().script_id == max.script_id); for (qsizetype j = afterTruncs; !found && j < stopAt; ++j) { QString later = uiLanguages.at(j); if (!later.startsWith(prefix)) { diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 2514e7f6a3b..ffc6d8ace51 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -4175,6 +4175,8 @@ public: return QVariant(QStringList{u"en-CA"_s, u"fr-CA"_s, u"de-AT"_s, u"en-GB"_s, u"fr-FR"_s}); } + if (m_name == u"pa-Arab-GB") // Pakistani Punjabi in Britain + return QVariant(QStringList{u"pa-PK"_s, u"en-GB"_s}); if (m_name == u"no") // QTBUG-131127 return QVariant(QStringList{u"no"_s, u"en-US"_s, u"nb"_s}); if (m_name == u"no-US") // Empty query result: @@ -4300,6 +4302,17 @@ void tst_QLocale::mySystemLocale_data() QTest::addRow("C-Hans-CN") << u"C-Hans-CN"_s << QLocale::C << QStringList{u"C-Hans-CN"_s, u"C"_s}; + QTest::addRow("pa-Arab-GB") + << u"pa-Arab-GB"_s << QLocale::Punjabi + << QStringList{u"pa-Arab-GB"_s, u"pa-Arab-PK"_s, u"pa-PK"_s, u"pa-Arab"_s, + u"en-Latn-GB"_s, u"en-GB"_s, + // Truncations: + u"en-Latn"_s, u"en"_s, + // Last because its implied script, Guru, doesn't match the Arab + // implied by the entry that it's derived from, pa-PK - in contrast + // to en-Latn and en. + u"pa"_s}; + QTest::newRow("en-Dsrt-GB") << u"en-Dsrt-GB"_s << QLocale::English << QStringList{u"en-Dsrt-GB"_s, u"en-Dsrt"_s,