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.

Pick-to: 6.7
Change-Id: I1ab8edfa49117bdc9c4353228e73c2d1e5becffc
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Moody Liu <mooodyhunter@outlook.com>
This commit is contained in:
Kirikaze Chiyuki 2024-04-21 11:08:10 +08:00
parent e185ff2c12
commit 4431ffa8b9
2 changed files with 7 additions and 0 deletions

View File

@ -4760,6 +4760,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

@ -4178,6 +4178,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();
}