From 66df19352f7269b2e6ed73f257e1d3a015f18f32 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 12 Mar 2023 23:33:38 +0200 Subject: [PATCH] Do not show languages without translations in UI --- launcher/firstLaunch/firstlaunch_moc.cpp | 9 +++++---- launcher/languages.cpp | 13 ++++++++++--- launcher/languages.h | 5 +++-- launcher/settingsView/csettingsview_moc.cpp | 4 ++-- lib/Languages.h | 10 ++++++---- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp index 192d8891e..6c14344b5 100644 --- a/launcher/firstLaunch/firstlaunch_moc.cpp +++ b/launcher/firstLaunch/firstlaunch_moc.cpp @@ -59,7 +59,7 @@ void FirstLaunchView::changeEvent(QEvent * event) if(event->type() == QEvent::LanguageChange) { ui->retranslateUi(this); - Languages::fillLanguages(ui->listWidgetLanguage); + Languages::fillLanguages(ui->listWidgetLanguage, false); } QWidget::changeEvent(event); } @@ -102,9 +102,7 @@ void FirstLaunchView::on_comboBoxLanguage_currentIndexChanged(int index) void FirstLaunchView::enterSetup() { - // TODO: block all UI except FirstLaunchView - Languages::fillLanguages(ui->listWidgetLanguage); - Languages::fillLanguages(ui->comboBoxLanguage); + Languages::fillLanguages(ui->listWidgetLanguage, false); } void FirstLaunchView::setSetupProgress(int progress) @@ -253,6 +251,8 @@ QString FirstLaunchView::heroesLanguageDetect() void FirstLaunchView::heroesLanguageUpdate() { + Languages::fillLanguages(ui->comboBoxLanguage, true); + QString language = heroesLanguageDetect(); bool success = !language.isEmpty(); @@ -266,6 +266,7 @@ void FirstLaunchView::heroesLanguageUpdate() ui->comboBoxLanguage->insertItem(0, itemName, QString("auto")); ui->comboBoxLanguage->setCurrentIndex(0); } + ui->labelDataFailure->setVisible(!success); ui->labelDataSuccess->setVisible(success); ui->pushButtonDataNext->setEnabled(success); diff --git a/launcher/languages.cpp b/launcher/languages.cpp index 33e23e529..91af38c9d 100644 --- a/launcher/languages.cpp +++ b/launcher/languages.cpp @@ -17,7 +17,7 @@ #include // list of language names, for generation of translations. Do not use directly, use Languages namespace instead -static const std::array languageTranslatedNamesGenerator = { +static const std::array languageTranslatedNamesGenerator = { { QT_TRANSLATE_NOOP("Language", "Chinese"), QT_TRANSLATE_NOOP("Language", "English"), @@ -26,6 +26,7 @@ static const std::array languageTranslatedNamesGenerator = { QT_TRANSLATE_NOOP("Language", "Korean"), QT_TRANSLATE_NOOP("Language", "Polish"), QT_TRANSLATE_NOOP("Language", "Russian"), + QT_TRANSLATE_NOOP("Language", "Spanish"), QT_TRANSLATE_NOOP("Language", "Ukrainian"), QT_TRANSLATE_NOOP("Language", "Other (East European)"), QT_TRANSLATE_NOOP("Language", "Other (Cyrillic Script)"), @@ -53,7 +54,7 @@ QString Languages::generateLanguageName(const Languages::Options & language) return displayName; } -void Languages::fillLanguages(QComboBox * widget) +void Languages::fillLanguages(QComboBox * widget, bool includeAll) { widget->blockSignals(true); // we do not want calls caused by initialization widget->clear(); @@ -62,6 +63,9 @@ void Languages::fillLanguages(QComboBox * widget) for(const auto & language : Languages::getLanguageList()) { + if (!language.hasTranslation && !includeAll) + continue; + QString displayName = generateLanguageName(language); QVariant userData = QString::fromStdString(language.identifier); @@ -73,7 +77,7 @@ void Languages::fillLanguages(QComboBox * widget) widget->blockSignals(false); } -void Languages::fillLanguages(QListWidget * widget) +void Languages::fillLanguages(QListWidget * widget, bool includeAll) { widget->blockSignals(true); // we do not want calls caused by initialization widget->clear(); @@ -82,6 +86,9 @@ void Languages::fillLanguages(QListWidget * widget) for(const auto & language : Languages::getLanguageList()) { + if (!language.hasTranslation && !includeAll) + continue; + QString displayName = generateLanguageName(language); QVariant userData = QString::fromStdString(language.identifier); diff --git a/launcher/languages.h b/launcher/languages.h index fc156704f..c818316cb 100644 --- a/launcher/languages.h +++ b/launcher/languages.h @@ -19,7 +19,8 @@ namespace Languages QString generateLanguageName(const Languages::Options & identifier); - void fillLanguages(QComboBox * widget); - void fillLanguages(QListWidget * widget); + /// if includeAll is set, all languages including encoding placeholders will be included into widget + void fillLanguages(QComboBox * widget, bool includeAll); + void fillLanguages(QListWidget * widget, bool includeAll); } diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 7d9bab60f..8bb8c9fdb 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -97,7 +97,7 @@ void CSettingsView::loadSettings() ui->comboBoxAutoSave->setCurrentIndex(settings["general"]["saveFrequency"].Integer() > 0 ? 1 : 0); - Languages::fillLanguages(ui->comboBoxLanguage); + Languages::fillLanguages(ui->comboBoxLanguage, false); std::string cursorType = settings["video"]["cursor"].String(); size_t cursorTypeIndex = boost::range::find(cursorTypesList, cursorType) - cursorTypesList; @@ -312,7 +312,7 @@ void CSettingsView::changeEvent(QEvent *event) if(event->type() == QEvent::LanguageChange) { ui->retranslateUi(this); - Languages::fillLanguages(ui->comboBoxLanguage); + Languages::fillLanguages(ui->comboBoxLanguage, false); } QWidget::changeEvent(event); } diff --git a/lib/Languages.h b/lib/Languages.h index a0356195e..f87ae6e0b 100644 --- a/lib/Languages.h +++ b/lib/Languages.h @@ -18,9 +18,10 @@ enum class ELanguages ENGLISH, FRENCH, GERMAN, - KOREAN, + KOREAN, // currently has no translations or detection POLISH, RUSSIAN, + SPANISH, UKRAINIAN, // Pseudo-languages, that have no translations but can define H3 encoding to use @@ -54,15 +55,16 @@ struct Options inline const auto & getLanguageList() { - static const std::array languages + static const std::array languages { { - { "chinese", "Chinese", "简体中文", "GBK", true, true }, + { "chinese", "Chinese", "简体中文", "GBK", true, true }, // Note: actually Simplified Chinese { "english", "English", "English", "CP1252", true, true }, { "french", "French", "Français", "CP1252", true, true }, { "german", "German", "Deutsch", "CP1252", true, true }, - { "korean", "Korean", "한국어", "CP949", false, true }, + { "korean", "Korean", "한국어", "CP949", false, false }, { "polish", "Polish", "Polski", "CP1250", true, true }, { "russian", "Russian", "Русский", "CP1251", true, true }, + { "spanish", "Spanish", "Español", "CP1252", false, true }, { "ukrainian", "Ukrainian", "Українська", "CP1251", true, true }, { "other_cp1250", "Other (East European)", "", "CP1251", false, false },