diff --git a/src/common/Configuration.cpp b/src/common/Configuration.cpp index 6178431d..a5be951a 100644 --- a/src/common/Configuration.cpp +++ b/src/common/Configuration.cpp @@ -244,7 +244,8 @@ bool Configuration::setLocaleByName(const QString &language) QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); for (auto &it : allLocales) { - if (QString::compare(it.nativeLanguageName(), language, Qt::CaseInsensitive) == 0) { + if (QString::compare(it.nativeLanguageName(), language, Qt::CaseInsensitive) == 0 || + it.name() == language) { setLocale(it); return true; } @@ -650,14 +651,16 @@ QStringList Configuration::getAvailableTranslations() QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); for (auto i : fileNames) { - QString localeName = i.mid(sizeof("cutter_") - 1, 2); - for (auto j : allLocales) { - if (j.name().startsWith(localeName)) { - currLanguageName = j.nativeLanguageName(); - currLanguageName = currLanguageName.at(0).toUpper() - + currLanguageName.right(currLanguageName.length() - 1); + QString localeName = i.mid(sizeof("cutter_") - 1, 2); // TODO:#2321 don't asume 2 characters + // language code is sometimes 3 characters, and there could also be language_COUNTRY. Qt supports that. + QLocale locale(localeName); + if (locale.language() != QLocale::C) { + currLanguageName = locale.nativeLanguageName(); + if (currLanguageName.isEmpty()) { // Qt doesn't have native language name for some languages + currLanguageName = QLocale::languageToString(locale.language()); + } + if (!currLanguageName.isEmpty()) { languages << currLanguageName; - break; } } } diff --git a/src/dialogs/WelcomeDialog.cpp b/src/dialogs/WelcomeDialog.cpp index c650c308..1422d70d 100644 --- a/src/dialogs/WelcomeDialog.cpp +++ b/src/dialogs/WelcomeDialog.cpp @@ -26,7 +26,6 @@ WelcomeDialog::WelcomeDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Welc QStringList langs = Config()->getAvailableTranslations(); ui->languageComboBox->addItems(langs); QString curr = Config()->getCurrLocale().nativeLanguageName(); - curr = curr.at(0).toUpper() + curr.right(curr.length() - 1); if (!langs.contains(curr)) { curr = "English"; } @@ -64,7 +63,7 @@ void WelcomeDialog::on_themeComboBox_currentIndexChanged(int index) */ void WelcomeDialog::onLanguageComboBox_currentIndexChanged(int index) { - QString language = ui->languageComboBox->itemText(index).toLower(); + QString language = ui->languageComboBox->itemText(index); Config()->setLocaleByName(language); QMessageBox mb; diff --git a/src/dialogs/preferences/AppearanceOptionsWidget.cpp b/src/dialogs/preferences/AppearanceOptionsWidget.cpp index 5bb38998..3ff4511a 100644 --- a/src/dialogs/preferences/AppearanceOptionsWidget.cpp +++ b/src/dialogs/preferences/AppearanceOptionsWidget.cpp @@ -33,7 +33,6 @@ AppearanceOptionsWidget::AppearanceOptionsWidget(PreferencesDialog *dialog) ui->languageComboBox->addItems(langs); QString curr = Config()->getCurrLocale().nativeLanguageName(); - curr = curr.at(0).toUpper() + curr.right(curr.length() - 1); if (!langs.contains(curr)) { curr = "English"; }