Skip to content
Snippets Groups Projects
Commit f8dfe32f authored by kwadronaut's avatar kwadronaut :speech_balloon: Committed by jkito
Browse files

gui: Add region to language selections menu when available

we currently have language entries which appears to be repeated
but infact they are different languages, e.g es_AR, es_CU  both
show up as 'Spanish' in the language picker, to make it  easier
to distinguish between them the region is added to the lanugage
picker list, so es_CU now appears as 'Spanish (Cuba)'
parent 1256c39b
No related branches found
No related tags found
1 merge request!241Update language picker to include region name and sort the list alphabetically
......@@ -46,31 +46,48 @@ QString getProviderConfig(QJsonValue info, QString provider, QString key, QStrin
return defaultValue;
}
// Function to get custom locale name
QString getCustomLocaleName(const QString &localeCode) {
QLocale locale(localeCode);
QString language = QLocale::languageToString(locale.language());
// Special handling for the default locale
if (language == "C" || language == "en") {
return "English";
}
QString territory = locale.territory() != QLocale::AnyTerritory ? QLocale::territoryToString(locale.territory()) : "";
if (!territory.isEmpty()) {
return QString("%1 (%2)").arg(language, territory);
}
return language;
}
QList<QVariant> getAvailableLocales() {
QString localePath = ":/i18n";
QDir dir(localePath);
QStringList fileNames = dir.entryList(QStringList("*.qm"));
QList<QVariant> locales;
for (int i = 0; i < fileNames.size(); ++i) {
// get locale extracted by filename
QString localeName;
localeName = fileNames[i]; // "de.qm"
localeName.truncate(localeName.lastIndexOf('.')); // "de"
if (localeName == "base") {
localeName = "en";
for (const QString &fileName : fileNames) {
// Extract locale code from filename
QString localeCode = fileName;
localeCode.truncate(localeCode.lastIndexOf('.')); // "main_es_CU.qm" -> "main_es_CU"
if (localeCode == "main_base") {
localeCode = "en";
} else {
// remove main_ prefix
localeName = localeName.mid(5);
// Remove "main_" prefix; main_es_CU -> es_CU
localeCode = localeCode.mid(5);
}
// Get custom locale name
QString localeName = getCustomLocaleName(localeCode);
QLocale locale = QLocale(localeName);
QString name = QLocale::languageToString(locale.language());
QVariantMap localeObject;
localeObject.insert("locale", localeName);
localeObject.insert("name", name);
localeObject.insert("locale", localeCode);
localeObject.insert("name", localeName);
locales.push_back(localeObject);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment