From 4431ffa8b90f4d089f98544e8c2eeac6cfc7abb2 Mon Sep 17 00:00:00 2001 From: Kirikaze Chiyuki Date: Sun, 21 Apr 2024 11:08:10 +0800 Subject: [PATCH] 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 Reviewed-by: Moody Liu --- src/corelib/text/qlocale.cpp | 5 +++++ tests/auto/corelib/text/qlocale/tst_qlocale.cpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index ab95b300ebb..86ab072b736 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -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)) diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index c9668cd4d42..eb2d73b9b2c 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -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(); }