From ca19f7006c7e6f129ce2c03241eb214f3c7fd20f Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 2 Dec 2023 11:15:54 +0400 Subject: [PATCH] Make hardcoded strings in Launcher and Wizard localizable --- apps/launcher/datafilespage.cpp | 27 +++++++++++++------ apps/launcher/graphicspage.cpp | 18 ++++++++++--- apps/wizard/installationpage.cpp | 3 ++- apps/wizard/languageselectionpage.cpp | 12 +++++---- apps/wizard/mainwizard.cpp | 5 ++-- .../contentselector/view/contentselector.cpp | 2 +- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 4ad99c99f1..dc2c07d9bd 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -164,11 +164,14 @@ Launcher::DataFilesPage::DataFilesPage(const Files::ConfigurationManager& cfg, C const QString encoding = mGameSettings.value("encoding", "win1252"); mSelector->setEncoding(encoding); - QStringList languages; - languages << tr("English") << tr("French") << tr("German") << tr("Italian") << tr("Polish") << tr("Russian") - << tr("Spanish"); + QVector> languages = { { "English", tr("English") }, { "French", tr("French") }, + { "German", tr("German") }, { "Italian", tr("Italian") }, { "Polish", tr("Polish") }, + { "Russian", tr("Russian") }, { "Spanish", tr("Spanish") } }; - mSelector->languageBox()->addItems(languages); + for (auto lang : languages) + { + mSelector->languageBox()->addItem(lang.second, lang.first); + } mNewProfileDialog = new TextInputDialog(tr("New Content List"), tr("Content List name:"), this); mCloneProfileDialog = new TextInputDialog(tr("Clone Content List"), tr("Content List name:"), this); @@ -254,9 +257,17 @@ bool Launcher::DataFilesPage::loadSettings() if (!currentProfile.isEmpty()) addProfile(currentProfile, true); - const int index = mSelector->languageBox()->findText(mLauncherSettings.getLanguage()); - if (index != -1) - mSelector->languageBox()->setCurrentIndex(index); + auto language = mLauncherSettings.getLanguage(); + + for (int i = 0; i < mSelector->languageBox()->count(); ++i) + { + QString languageItem = mSelector->languageBox()->itemData(i).toString(); + if (language == languageItem) + { + mSelector->languageBox()->setCurrentIndex(i); + break; + } + } return true; } @@ -386,7 +397,7 @@ void Launcher::DataFilesPage::saveSettings(const QString& profile) mLauncherSettings.setContentList(profileName, dirList, selectedArchivePaths(), fileNames); mGameSettings.setContentList(dirList, selectedArchivePaths(), fileNames); - QString language(mSelector->languageBox()->currentText()); + QString language(mSelector->languageBox()->currentData().toString()); mLauncherSettings.setLanguage(language); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 84d5049d6c..fa9d5eb479 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -154,8 +154,13 @@ bool Launcher::GraphicsPage::loadSettings() if (Settings::shadows().mEnableIndoorShadows) indoorShadowsCheckBox->setCheckState(Qt::Checked); - shadowComputeSceneBoundsComboBox->setCurrentIndex( - shadowComputeSceneBoundsComboBox->findText(QString(tr(Settings::shadows().mComputeSceneBounds.get().c_str())))); + auto boundMethod = Settings::shadows().mComputeSceneBounds.get(); + if (boundMethod == "bounds") + shadowComputeSceneBoundsComboBox->setCurrentIndex(0); + else if (boundMethod == "primitives") + shadowComputeSceneBoundsComboBox->setCurrentIndex(1); + else + shadowComputeSceneBoundsComboBox->setCurrentIndex(2); const int shadowDistLimit = Settings::shadows().mMaximumShadowMapDistance; if (shadowDistLimit > 0) @@ -254,7 +259,14 @@ void Launcher::GraphicsPage::saveSettings() Settings::shadows().mEnableIndoorShadows.set(indoorShadowsCheckBox->checkState() != Qt::Unchecked); Settings::shadows().mShadowMapResolution.set(shadowResolutionComboBox->currentText().toInt()); - Settings::shadows().mComputeSceneBounds.set(shadowComputeSceneBoundsComboBox->currentText().toStdString()); + + auto index = shadowComputeSceneBoundsComboBox->currentIndex(); + if (index == 0) + Settings::shadows().mComputeSceneBounds.set("bounds"); + else if (index == 1) + Settings::shadows().mComputeSceneBounds.set("primitives"); + else + Settings::shadows().mComputeSceneBounds.set("none"); } QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen) diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index cf2e3671e1..2dd796ab3f 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -1,5 +1,6 @@ #include "installationpage.hpp" +#include #include #include #include @@ -123,7 +124,7 @@ void Wizard::InstallationPage::startInstallation() mUnshield->setPath(path); // Set the right codec to use for Morrowind.ini - QString language(field(QLatin1String("installation.language")).toString()); + QString language(field(QLatin1String("installation.language")).value()->currentData().toString()); if (language == QLatin1String("Polish")) { diff --git a/apps/wizard/languageselectionpage.cpp b/apps/wizard/languageselectionpage.cpp index 9808d3c56c..38050b1cab 100644 --- a/apps/wizard/languageselectionpage.cpp +++ b/apps/wizard/languageselectionpage.cpp @@ -14,12 +14,14 @@ Wizard::LanguageSelectionPage::LanguageSelectionPage(QWidget* parent) void Wizard::LanguageSelectionPage::initializePage() { - QStringList languages; - languages << QLatin1String("English") << QLatin1String("French") << QLatin1String("German") - << QLatin1String("Italian") << QLatin1String("Polish") << QLatin1String("Russian") - << QLatin1String("Spanish"); + QVector> languages = { { "English", tr("English") }, { "French", tr("French") }, + { "German", tr("German") }, { "Italian", tr("Italian") }, { "Polish", tr("Polish") }, + { "Russian", tr("Russian") }, { "Spanish", tr("Spanish") } }; - languageComboBox->addItems(languages); + for (auto lang : languages) + { + languageComboBox->addItem(lang.second, lang.first); + } } int Wizard::LanguageSelectionPage::nextId() const diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index e9cce3db5e..5fd316d17a 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -270,8 +270,7 @@ void Wizard::MainWizard::runSettingsImporter() arguments.append(QLatin1String("--encoding")); // Set encoding - QString language(field(QLatin1String("installation.language")).toString()); - + QString language(field(QLatin1String("installation.language")).value()->currentData().toString()); if (language == QLatin1String("Polish")) { arguments.append(QLatin1String("win1250")); @@ -392,7 +391,7 @@ void Wizard::MainWizard::reject() void Wizard::MainWizard::writeSettings() { // Write the encoding and language settings - QString language(field(QLatin1String("installation.language")).toString()); + QString language(field(QLatin1String("installation.language")).value()->currentData().toString()); mLauncherSettings.setLanguage(language); if (language == QLatin1String("Polish")) diff --git a/components/contentselector/view/contentselector.cpp b/components/contentselector/view/contentselector.cpp index 2f01200927..62d476b944 100644 --- a/components/contentselector/view/contentselector.cpp +++ b/components/contentselector/view/contentselector.cpp @@ -32,7 +32,7 @@ void ContentSelectorView::ContentSelector::buildContentModel(bool showOMWScripts void ContentSelectorView::ContentSelector::buildGameFileView() { - ui.gameFileView->addItem(""); + ui.gameFileView->addItem(tr("")); ui.gameFileView->setVisible(true); connect(ui.gameFileView, qOverload(&ComboBox::currentIndexChanged), this,