Skip to content

Commit

Permalink
Include locale in language dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Müller authored and fmoc committed Mar 11, 2022
1 parent d47a148 commit f998fba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/9460
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ Enhancement: Provide informal German translations
The community was maintaining an informal German translation for years but we where only able to
provide a single version of German in the client.
We now ship both versions, the informal can be selected in the combobox in the advanced settings.
To be able to distinguish between formal and informal locales, we also include the locale
identifier in the dropdown (e.g., "Deutsch (de-informal)").

https://github.com/owncloud/client/issues/9460
https://github.com/owncloud/client/pull/9502
42 changes: 18 additions & 24 deletions src/gui/generalsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
#include "config.h"
#include "translations.h"

#include <QNetworkProxy>
#include <QDir>
#include <QScopedValueRollback>
#include <QMessageBox>
#include <QNetworkProxy>
#include <QOperatingSystemVersion>
#include <QScopedValueRollback>

namespace OCC {

Expand Down Expand Up @@ -279,13 +279,8 @@ void GeneralSettings::saveMiscSettings()

// the first entry, identified by index 0, means "use default", which is a special case handled below
if (pickedLanguageIndex > 0) {
// for now, we use the locale names as labels in the dropdown
// therefore, we can store them directly in the config file
// in future versions, we will likely display nice names instead of locales to improve the user experience
const auto pickedLanguageName = _ui->languageDropdown->itemText(pickedLanguageIndex);
const auto pickedLanguageLocale = localesToLanguageNamesMap.key(pickedLanguageName);

cfgFile.setUiLanguage(pickedLanguageLocale);
const QString &pickedLocale = _ui->languageDropdown->itemData(pickedLanguageIndex).toString();
cfgFile.setUiLanguage(pickedLocale);
} else {
// empty string means "use system default"
cfgFile.setUiLanguage("");
Expand Down Expand Up @@ -343,8 +338,19 @@ void GeneralSettings::reloadConfig()

void GeneralSettings::loadLanguageNamesIntoDropdown()
{
// allow method to be called more than once
_ui->languageDropdown->clear();

// if no option has been chosen explicitly by the user, the first entry shall be used
_ui->languageDropdown->addItem(tr("(use default)"));

// initialize map of locales to language names
const auto availableLocales = Translations::listAvailableTranslations();
const auto availableLocales = []() {
auto rv = Translations::listAvailableTranslations().values();
rv.sort(Qt::CaseInsensitive);
return rv;
}();

for (const auto &availableLocale : availableLocales) {
auto nativeLanguageName = QLocale(availableLocale).nativeLanguageName();

Expand All @@ -355,20 +361,8 @@ void GeneralSettings::loadLanguageNamesIntoDropdown()
nativeLanguageName = tr("unknown (%1)").arg(availableLocale);
}

localesToLanguageNamesMap.insert(availableLocale, nativeLanguageName);
}

// allow method to be called more than once
_ui->languageDropdown->clear();

// if no option has been chosen explicitly by the user, the first entry shall be used
_ui->languageDropdown->addItem(tr("(use default)"));

QStringList availableTranslations(localesToLanguageNamesMap.values());
availableTranslations.sort(Qt::CaseInsensitive);

for (const auto &i : qAsConst(availableTranslations)) {
_ui->languageDropdown->addItem(i);
QString entryText = QStringLiteral("%1 (%2)").arg(nativeLanguageName, availableLocale);
_ui->languageDropdown->addItem(entryText, availableLocale);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/gui/generalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private slots:
Ui::GeneralSettings *_ui;
QPointer<IgnoreListEditor> _ignoreEditor;
bool _currentlyLoading;
QMap<QString, QString> localesToLanguageNamesMap;
};


Expand Down

0 comments on commit f998fba

Please sign in to comment.