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 <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-06 18:55:59 +03:00
parent c7dc966f67
commit 65587af47d

View file

@ -658,19 +658,29 @@ QString KLocale::languageCodeToName(const QString &language) const
{ {
QString result; QString result;
const QString entryfile = KStandardDirs::locate("locale", language + QLatin1String("/entry.desktop")); const QString entryfile = KStandardDirs::locate("locale", language + QLatin1String("/entry.desktop"));
const QString localelanguage = languageList().first(); const QStringList entrylanguages = languageList();
if (!entryfile.isEmpty()) { if (!entryfile.isEmpty()) {
KConfig entryconfig(entryfile); KConfig entryconfig(entryfile);
entryconfig.setLocale(localelanguage); foreach (const QString &lang, entrylanguages) {
entryconfig.setLocale(lang);
KConfigGroup entrygroup(&entryconfig, "KCM Locale"); KConfigGroup entrygroup(&entryconfig, "KCM Locale");
result = entrygroup.readEntry("Name"); result = entrygroup.readEntry("Name");
if (!result.isEmpty()) {
break;
}
}
} }
if (result.isEmpty()) { if (result.isEmpty()) {
// in case the language is not installed // in case the language is not installed
KConfig languagesconfig(QLatin1String("all_languages"), KConfig::NoGlobals, "locale"); KConfig languagesconfig(QLatin1String("all_languages"), KConfig::NoGlobals, "locale");
languagesconfig.setLocale(localelanguage); foreach (const QString &lang, entrylanguages) {
languagesconfig.setLocale(lang);
KConfigGroup languagegroup(&languagesconfig, language); KConfigGroup languagegroup(&languagesconfig, language);
result = languagegroup.readEntry("Name"); result = languagegroup.readEntry("Name");
if (!result.isEmpty()) {
break;
}
}
} }
if (result.isEmpty()) { if (result.isEmpty()) {
// not translated at all // not translated at all
@ -684,12 +694,17 @@ QString KLocale::countryCodeToName(const QString &country) const
{ {
QString result; QString result;
const QString entryfile = KStandardDirs::locate("locale", QString::fromLatin1("l10n/") + country.toLower() + QLatin1String("/entry.desktop")); 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()) { if (!entryfile.isEmpty()) {
KConfig entryconfig(entryfile); KConfig entryconfig(entryfile);
entryconfig.setLocale(localelanguage); foreach (const QString &lang, entrylanguages) {
entryconfig.setLocale(lang);
KConfigGroup entrygroup(&entryconfig, "KCM Locale"); KConfigGroup entrygroup(&entryconfig, "KCM Locale");
result = entrygroup.readEntry("Name"); result = entrygroup.readEntry("Name");
if (!result.isEmpty()) {
break;
}
}
} }
if (result.isEmpty()) { if (result.isEmpty()) {
// not translated at all (e.g. 001 - world) // not translated at all (e.g. 001 - world)
@ -788,11 +803,11 @@ void KLocale::reparseConfiguration()
if (!configtranslations.isEmpty()) { if (!configtranslations.isEmpty()) {
d->languagelist.append(configtranslations); d->languagelist.append(configtranslations);
} }
// the locale name itself (e.g. "en_US")
const QString localename = d->locale.name(); const QString localename = d->locale.name();
d->languagelist.append(localename);
// the language only (e.g. "en") // the language only (e.g. "en")
d->languagelist.append(kGetLanguage(localename)); 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 // default as fallback, unless the locale language is the default
if (localename != KLocale::defaultLanguage()) { if (localename != KLocale::defaultLanguage()) {
d->languagelist.append(KLocale::defaultLanguage()); d->languagelist.append(KLocale::defaultLanguage());