Fix separator in QLocale::uiLanguages()

Since commit 91e70f23 introduced separator to uiLanguages(), the system
locale id still does not respect the separator parameter and hardcodes
dash as separator. Fixing this should make the format consistent.

Change-Id: I1ab8edfa49117bdc9c4353228e73c2d1e5becffc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Moody Liu <mooodyhunter@outlook.com>
(cherry picked from commit 4431ffa8b90f4d089f98544e8c2eeac6cfc7abb2)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Kirikaze Chiyuki 2024-04-21 11:08:10 +08:00 committed by Qt Cherry-pick Bot
parent e85a0951dd
commit f05cf3f11f
2 changed files with 7 additions and 0 deletions

View File

@ -4750,6 +4750,11 @@ QStringList QLocale::uiLanguages(TagSeparator separator) const
const bool isSystem = d->m_data == &systemLocaleData;
if (isSystem) {
uiLanguages = systemLocale()->query(QSystemLocale::UILanguages).toStringList();
if (separator != TagSeparator::Dash) {
// Map from default separator, Dash, used by backends:
const QChar join = QLatin1Char(sep);
uiLanguages = uiLanguages.replaceInStrings(u"-", QStringView(&join, 1));
}
// ... but we need to include likely-adjusted forms of each of those, too.
// For now, collect up locale Ids representing the entries, for later processing:
for (const auto &entry : std::as_const(uiLanguages))

View File

@ -4102,6 +4102,8 @@ void tst_QLocale::mySystemLocale()
qDebug("\n\t%s", qPrintable(QLocale::system().uiLanguages().join(u"\n\t")));
});
QCOMPARE(QLocale::system().uiLanguages(), uiLanguages);
QCOMPARE(QLocale::system().uiLanguages(QLocale::TagSeparator::Underscore),
uiLanguages.replaceInStrings(u"-", u"_"));
reporter.dismiss();
}