From 65587af47d597df204a1b49fdfe29cf4a4d70b6f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 6 Aug 2023 18:55:59 +0300 Subject: [PATCH] kdecore: probe all languages from KLocale::languageCodeToName() and KLocale::countryCodeToName() for that to work what KConfig expects (the language only) has to be first in the list, otherwise KConfig returns entries that are actually not in the set locale (go figure) Signed-off-by: Ivailo Monev --- kdecore/localization/klocale.cpp | 41 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/kdecore/localization/klocale.cpp b/kdecore/localization/klocale.cpp index 2e0aa90e..692fceed 100644 --- a/kdecore/localization/klocale.cpp +++ b/kdecore/localization/klocale.cpp @@ -658,19 +658,29 @@ QString KLocale::languageCodeToName(const QString &language) const { QString result; const QString entryfile = KStandardDirs::locate("locale", language + QLatin1String("/entry.desktop")); - const QString localelanguage = languageList().first(); + const QStringList entrylanguages = languageList(); if (!entryfile.isEmpty()) { KConfig entryconfig(entryfile); - entryconfig.setLocale(localelanguage); - KConfigGroup entrygroup(&entryconfig, "KCM Locale"); - result = entrygroup.readEntry("Name"); + foreach (const QString &lang, entrylanguages) { + entryconfig.setLocale(lang); + KConfigGroup entrygroup(&entryconfig, "KCM Locale"); + result = entrygroup.readEntry("Name"); + if (!result.isEmpty()) { + break; + } + } } if (result.isEmpty()) { // in case the language is not installed KConfig languagesconfig(QLatin1String("all_languages"), KConfig::NoGlobals, "locale"); - languagesconfig.setLocale(localelanguage); - KConfigGroup languagegroup(&languagesconfig, language); - result = languagegroup.readEntry("Name"); + foreach (const QString &lang, entrylanguages) { + languagesconfig.setLocale(lang); + KConfigGroup languagegroup(&languagesconfig, language); + result = languagegroup.readEntry("Name"); + if (!result.isEmpty()) { + break; + } + } } if (result.isEmpty()) { // not translated at all @@ -684,12 +694,17 @@ QString KLocale::countryCodeToName(const QString &country) const { QString result; const QString entryfile = KStandardDirs::locate("locale", QString::fromLatin1("l10n/") + country.toLower() + QLatin1String("/entry.desktop")); - const QString localelanguage = languageList().first(); + const QStringList entrylanguages = languageList(); if (!entryfile.isEmpty()) { KConfig entryconfig(entryfile); - entryconfig.setLocale(localelanguage); - KConfigGroup entrygroup(&entryconfig, "KCM Locale"); - result = entrygroup.readEntry("Name"); + foreach (const QString &lang, entrylanguages) { + entryconfig.setLocale(lang); + KConfigGroup entrygroup(&entryconfig, "KCM Locale"); + result = entrygroup.readEntry("Name"); + if (!result.isEmpty()) { + break; + } + } } if (result.isEmpty()) { // not translated at all (e.g. 001 - world) @@ -788,11 +803,11 @@ void KLocale::reparseConfiguration() if (!configtranslations.isEmpty()) { d->languagelist.append(configtranslations); } - // the locale name itself (e.g. "en_US") const QString localename = d->locale.name(); - d->languagelist.append(localename); // the language only (e.g. "en") d->languagelist.append(kGetLanguage(localename)); + // the locale name itself (e.g. "en_US") + d->languagelist.append(localename); // default as fallback, unless the locale language is the default if (localename != KLocale::defaultLanguage()) { d->languagelist.append(KLocale::defaultLanguage());