From 6fe319329b248f49fb42aced662a8dacdcfd802e Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 8 Mar 2023 02:01:56 +0200 Subject: [PATCH] Fix language selection --- config/schemas/mod.json | 8 +- config/schemas/settings.json | 2 +- launcher/firstLaunch/firstlaunch_moc.cpp | 29 +++++++- launcher/firstLaunch/firstlaunch_moc.h | 3 + launcher/firstLaunch/firstlaunch_moc.ui | 95 +++++++++--------------- launcher/languages.cpp | 6 +- lib/Languages.h | 2 +- 7 files changed, 76 insertions(+), 69 deletions(-) diff --git a/config/schemas/mod.json b/config/schemas/mod.json index 855e13b69..7ee8a4057 100644 --- a/config/schemas/mod.json +++ b/config/schemas/mod.json @@ -91,7 +91,7 @@ "language" : { "type":"string", "description": "Base language of the mod, before applying localizations. By default vcmi assumes English", - "enum" : [ "chinese", "english", "german", "polish", "russian", "ukrainian" ], + "enum" : [ "chinese", "english", "korean", "german", "polish", "russian", "ukrainian" ], }, "depends": { "type":"array", @@ -125,12 +125,18 @@ "type":"boolean", "description": "If set to true, mod will not be enabled automatically on install" }, + "chinese" : { + "$ref" : "#/definitions/localizable" + }, "english" : { "$ref" : "#/definitions/localizable" }, "german" : { "$ref" : "#/definitions/localizable" }, + "korean" : { + "$ref" : "#/definitions/localizable" + }, "polish" : { "$ref" : "#/definitions/localizable" }, diff --git a/config/schemas/settings.json b/config/schemas/settings.json index 651e095c9..ffdc5372e 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -63,7 +63,7 @@ }, "language" : { "type":"string", - "enum" : [ "chinese", "english", "german", "polish", "russian", "ukrainian" ], + "enum" : [ "chinese", "english", "german", "korean", "polish", "russian", "ukrainian", "other_cp1250", "other_cp1251", "other_cp1252" ], "default" : "english" }, "lastSave" : { diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp index 9119e0202..aea431aab 100644 --- a/launcher/firstLaunch/firstlaunch_moc.cpp +++ b/launcher/firstLaunch/firstlaunch_moc.cpp @@ -11,10 +11,17 @@ #include "firstlaunch_moc.h" #include "ui_firstlaunch_moc.h" +#include "mainwindow_moc.h" + +#include "../languages.h" +#include "../../lib/CConfigHandler.h" + FirstLaunchView::FirstLaunchView(QWidget * parent) : QWidget(parent), ui(new Ui::FirstLaunchView) { ui->setupUi(this); + + Languages::fillLanguages(ui->listWidgetLanguage); } FirstLaunchView::~FirstLaunchView() @@ -27,21 +34,37 @@ void FirstLaunchView::on_buttonTabLanguage_clicked() ui->installerTabs->setCurrentIndex(0); } - void FirstLaunchView::on_buttonTabHeroesData_clicked() { ui->installerTabs->setCurrentIndex(1); } - void FirstLaunchView::on_buttonTabModPreset_clicked() { ui->installerTabs->setCurrentIndex(2); } - void FirstLaunchView::on_buttonTabFinish_clicked() { ui->installerTabs->setCurrentIndex(3); } +void FirstLaunchView::on_listWidgetLanguage_currentRowChanged(int currentRow) +{ + Settings node = settings.write["general"]["language"]; + QString selectedLanguage = ui->listWidgetLanguage->item(currentRow)->data(Qt::UserRole).toString(); + node->String() = selectedLanguage.toStdString(); + + if(auto * mainWindow = dynamic_cast(qApp->activeWindow())) + mainWindow->updateTranslation(); +} + +void FirstLaunchView::changeEvent(QEvent *event) +{ + if(event->type() == QEvent::LanguageChange) + { + ui->retranslateUi(this); + Languages::fillLanguages(ui->listWidgetLanguage); + } + QWidget::changeEvent(event); +} diff --git a/launcher/firstLaunch/firstlaunch_moc.h b/launcher/firstLaunch/firstlaunch_moc.h index 159d1e48e..04fc3fc88 100644 --- a/launcher/firstLaunch/firstlaunch_moc.h +++ b/launcher/firstLaunch/firstlaunch_moc.h @@ -19,6 +19,7 @@ class FirstLaunchView : public QWidget { Q_OBJECT + void changeEvent(QEvent *event); public: explicit FirstLaunchView(QWidget * parent = 0); ~FirstLaunchView(); @@ -35,6 +36,8 @@ private slots: void on_buttonTabFinish_clicked(); + void on_listWidgetLanguage_currentRowChanged(int currentRow); + private: Ui::FirstLaunchView * ui; diff --git a/launcher/firstLaunch/firstlaunch_moc.ui b/launcher/firstLaunch/firstlaunch_moc.ui index 325412262..fe3bdba8e 100644 --- a/launcher/firstLaunch/firstlaunch_moc.ui +++ b/launcher/firstLaunch/firstlaunch_moc.ui @@ -157,7 +157,7 @@ 0 - + 75 @@ -170,7 +170,7 @@ - + Next @@ -203,35 +203,10 @@ - + 5 - - - English - - - - - German - - - - - Polish - - - - - Russian - - - - - Ukrainian - - @@ -254,7 +229,7 @@ 0 - + 75 @@ -285,7 +260,7 @@ 6 - + 25 @@ -298,7 +273,7 @@ - + 25 @@ -311,7 +286,7 @@ - + 50 @@ -321,7 +296,7 @@ - + 50 @@ -331,7 +306,7 @@ - + 100 @@ -347,7 +322,7 @@ - + 100 @@ -363,7 +338,7 @@ - + 50 @@ -382,7 +357,7 @@ - + 100 @@ -398,7 +373,7 @@ - + 25 @@ -411,7 +386,7 @@ - + 100 @@ -447,7 +422,7 @@ 6 - + You Heroes III language was succesfully detected automatically. @@ -457,7 +432,7 @@ - + Automatic detection of language failed. Please select language of your Heroes III copy @@ -467,10 +442,10 @@ - + - + 75 @@ -519,14 +494,14 @@ - + Back - + Next @@ -551,7 +526,7 @@ 0 - + 75 @@ -579,7 +554,7 @@ - + 100 @@ -595,7 +570,7 @@ - + 0 @@ -603,7 +578,7 @@ - Localization to (language) + Localization to English Qt::ToolButtonTextOnly @@ -611,7 +586,7 @@ - + 100 @@ -627,7 +602,7 @@ - + 0 @@ -643,7 +618,7 @@ - + 0 @@ -659,7 +634,7 @@ - + 100 @@ -675,7 +650,7 @@ - + 100 @@ -683,7 +658,7 @@ - VCMI provides translations of Heroes III into a different languages. If you wish, you can install translation to (your language) + VCMI provides translations of Heroes III into a different languages. If you wish, you can install translation to English true @@ -691,7 +666,7 @@ - + 0 @@ -737,14 +712,14 @@ - + Back - + Skip @@ -810,14 +785,14 @@ - + Back - + Finish diff --git a/launcher/languages.cpp b/launcher/languages.cpp index e43baa0b2..33e23e529 100644 --- a/launcher/languages.cpp +++ b/launcher/languages.cpp @@ -42,12 +42,12 @@ QString Languages::generateLanguageName(const Languages::Options & language) QString localizedName = QApplication::translate("Language", language.nameEnglish.c_str()); QString nativeName = language.nameNative.c_str(); - if(activeLanguage == language.identifier) - return nativeName; - if(!language.hasTranslation) return localizedName; + if(activeLanguage == language.identifier) + return nativeName; + QString displayName = QString("%1 (%2)").arg(localizedName, nativeName); return displayName; diff --git a/lib/Languages.h b/lib/Languages.h index 8f7b1e9f8..a0356195e 100644 --- a/lib/Languages.h +++ b/lib/Languages.h @@ -67,7 +67,7 @@ inline const auto & getLanguageList() { "other_cp1250", "Other (East European)", "", "CP1251", false, false }, { "other_cp1251", "Other (Cyrillic Script)", "", "CP1250", false, false }, - { "other_cp1250", "Other (West European)", "", "CP1252", false, false } + { "other_cp1252", "Other (West European)", "", "CP1252", false, false } } }; static_assert(languages.size() == static_cast(ELanguages::COUNT), "Languages array is missing a value!");