summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qlocale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qlocale.cpp')
-rw-r--r--src/corelib/text/qlocale.cpp50
1 files changed, 27 insertions, 23 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp
index 67b06f42f4..6cf0488f83 100644
--- a/src/corelib/text/qlocale.cpp
+++ b/src/corelib/text/qlocale.cpp
@@ -337,22 +337,6 @@ QByteArray QLocalePrivate::bcp47Name(char separator) const
return localeId.withLikelySubtagsRemoved().name(separator);
}
-/*!
- \internal
- */
-QByteArray QLocalePrivate::rawName(char separator) const
-{
- QByteArrayList parts;
- if (m_data->m_language_id != QLocale::AnyLanguage)
- parts.append(languageCode().latin1());
- if (m_data->m_script_id != QLocale::AnyScript)
- parts.append(scriptCode().latin1());
- if (m_data->m_country_id != QLocale::AnyCountry)
- parts.append(countryCode().latin1());
-
- return parts.join(separator);
-}
-
static const QLocaleData *findLocaleDataById(const QLocaleId &localeId)
{
const uint idx = locale_index[localeId.language_id];
@@ -4542,6 +4526,31 @@ QStringList QLocale::uiLanguages() const
}
if (locales.isEmpty())
locales.append(systemLocale()->fallbackUiLocale());
+ // If the system locale (isn't C and) didn't include itself in the list,
+ // or as fallback, presume to know better than it and put its name
+ // first. (Known issue, QTBUG-104930, on some macOS versions when in
+ // locale en_DE.) Our translation system might have a translation for a
+ // locale the platform doesn't believe in.
+ const QString name = bcp47Name();
+ if (!name.isEmpty() && language() != C && !uiLanguages.contains(name)) {
+ // That uses contains(name) as a cheap pre-test, but there may be an
+ // entry that matches this on purging likely subtags.
+ QLocaleId mine =
+ { d->m_data->m_language_id, d->m_data->m_script_id, d->m_data->m_country_id };
+ mine = mine.withLikelySubtagsRemoved();
+ const auto isMine = [mine](const QString &entry) {
+ QLocale::Language lang;
+ QLocale::Script script;
+ QLocale::Country cntry;
+ QLocalePrivate::getLangAndCountry(entry, lang, script, cntry);
+ QLocaleId id = { ushort(lang), ushort(script), ushort(cntry) };
+ return id.withLikelySubtagsRemoved() == mine;
+ };
+ if (std::none_of(uiLanguages.constBegin(), uiLanguages.constEnd(), isMine)) {
+ locales.prepend(*this);
+ uiLanguages.prepend(name);
+ }
+ }
} else
#endif
{
@@ -4554,13 +4563,8 @@ QStringList QLocale::uiLanguages() const
if (i < uiLanguages.size()) {
// Adding likely-adjusted forms to system locale's list.
// Name the locale is derived from:
- const QString &name = uiLanguages.at(i);
- prior = name.toLatin1();
- // Don't try to likely-adjust if construction's likely-adjustments
- // were so drastic the result doesn't match the prior name:
- if (locale.name() != name && locale.d->rawName() != prior)
- continue;
- // Insert just after prior:
+ prior = uiLanguages.at(i).toLatin1();
+ // Insert just after the entry we're supplementing:
j = i + 1;
} else {
// Plain locale, not system locale; just append.