From 2889ce59d51eb1bca94e77e76cdd150c889316fb Mon Sep 17 00:00:00 2001 From: Lu-jinfeng <335742390@qq.com> Date: Thu, 28 Dec 2023 15:52:40 +0800 Subject: [PATCH] Fix UI internationalization translation issue. --- src/yuzu/configuration/configure_cpu.h | 2 +- src/yuzu/configuration/configure_graphics.h | 2 +- src/yuzu/configuration/shared_translation.cpp | 12 ++++------- src/yuzu/configuration/shared_translation.h | 21 ++++++++++++------- src/yuzu/configuration/shared_widget.cpp | 17 ++++++++------- src/yuzu/configuration/shared_widget.h | 16 +++++++------- 6 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index a102b4c1f9..d16789b154 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -45,7 +45,7 @@ private: const Core::System& system; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + const ConfigurationShared::TranslationShared::ComboboxTranslationMap& combobox_translations; std::vector> apply_funcs{}; QComboBox* accuracy_combobox; diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 5c8286836a..6c0be23837 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -97,7 +97,7 @@ private: const std::function update_aspect_ratio; const Core::System& system; - const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + const ConfigurationShared::TranslationShared::ComboboxTranslationMap& combobox_translations; const std::vector>& shader_mapping; QPushButton* api_restore_global_button; diff --git a/src/yuzu/configuration/shared_translation.cpp b/src/yuzu/configuration/shared_translation.cpp index 7e908924c4..570dfa6003 100644 --- a/src/yuzu/configuration/shared_translation.cpp +++ b/src/yuzu/configuration/shared_translation.cpp @@ -16,10 +16,9 @@ #include "yuzu/uisettings.h" namespace ConfigurationShared { - -std::unique_ptr InitializeTranslations(QWidget* parent) { +std::unique_ptr TranslationShared::InitializeTranslations( + QWidget* parent) { std::unique_ptr translations = std::make_unique(); - const auto& tr = [parent](const char* text) -> QString { return parent->tr(text); }; #define INSERT(SETTINGS, ID, NAME, TOOLTIP) \ translations->insert(std::pair{SETTINGS::values.ID.Id(), std::pair{(NAME), (TOOLTIP)}}) @@ -190,13 +189,10 @@ std::unique_ptr InitializeTranslations(QWidget* parent) { return translations; } - -std::unique_ptr ComboboxEnumeration(QWidget* parent) { +std::unique_ptr TranslationShared::ComboboxEnumeration( + QWidget* parent) { std::unique_ptr translations = std::make_unique(); - const auto& tr = [&](const char* text, const char* context = "") { - return parent->tr(text, context); - }; #define PAIR(ENUM, VALUE, TRANSLATION) {static_cast(Settings::ENUM::VALUE), (TRANSLATION)} diff --git a/src/yuzu/configuration/shared_translation.h b/src/yuzu/configuration/shared_translation.h index d5fc3b8def..a1c754f97b 100644 --- a/src/yuzu/configuration/shared_translation.h +++ b/src/yuzu/configuration/shared_translation.h @@ -9,19 +9,13 @@ #include #include #include +#include #include "common/common_types.h" #include "common/settings.h" class QWidget; namespace ConfigurationShared { -using TranslationMap = std::map>; -using ComboboxTranslations = std::vector>; -using ComboboxTranslationMap = std::map; - -std::unique_ptr InitializeTranslations(QWidget* parent); - -std::unique_ptr ComboboxEnumeration(QWidget* parent); static const std::map anti_aliasing_texts_map = { {Settings::AntiAliasing::None, QStringLiteral(QT_TRANSLATE_NOOP("GMainWindow", "None"))}, @@ -66,3 +60,16 @@ static const std::map shader_backend_texts_map }; } // namespace ConfigurationShared +namespace ConfigurationShared { +class TranslationShared : public QObject { + Q_OBJECT +public: + using TranslationMap = std::map>; + using ComboboxTranslations = std::vector>; + using ComboboxTranslationMap = std::map; + static std::unique_ptr InitializeTranslations( + QWidget* parent); + static std::unique_ptr ComboboxEnumeration( + QWidget* parent); +}; +} // namespace ConfigurationShared \ No newline at end of file diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 941683a437..2b5762dd8d 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp @@ -132,7 +132,7 @@ QWidget* Widget::CreateCombobox(std::function& serializer, combobox = new QComboBox(this); combobox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - const ComboboxTranslations* enumeration{nullptr}; + const TranslationShared::ComboboxTranslations* enumeration{nullptr}; if (combobox_enumerations.contains(type)) { enumeration = &combobox_enumerations.at(type); for (const auto& [id, name] : *enumeration) { @@ -182,7 +182,7 @@ QWidget* Widget::CreateRadioGroup(std::function& serializer, layout->setContentsMargins(0, 0, 0, 0); group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); - const ComboboxTranslations* enumeration{nullptr}; + const TranslationShared::ComboboxTranslations* enumeration{nullptr}; if (combobox_enumerations.contains(type)) { enumeration = &combobox_enumerations.at(type); for (const auto& [id, name] : *enumeration) { @@ -710,8 +710,10 @@ bool Widget::Valid() const { Widget::~Widget() = default; -Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, - const ComboboxTranslationMap& combobox_translations_, QWidget* parent_, +Widget::Widget(Settings::BasicSetting* setting_, + const TranslationShared::TranslationMap& translations_, + const TranslationShared::ComboboxTranslationMap& combobox_translations_, + QWidget* parent_, bool runtime_lock_, std::vector>& apply_funcs_, RequestType request, bool managed, float multiplier, Settings::BasicSetting* other_setting, const QString& suffix) @@ -765,8 +767,9 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati } Builder::Builder(QWidget* parent_, bool runtime_lock_) - : translations{InitializeTranslations(parent_)}, - combobox_translations{ComboboxEnumeration(parent_)}, parent{parent_}, runtime_lock{ + : translations{TranslationShared::InitializeTranslations(parent_)}, + combobox_translations{TranslationShared::ComboboxEnumeration(parent_)}, parent{parent_}, + runtime_lock{ runtime_lock_} {} Builder::~Builder() = default; @@ -795,7 +798,7 @@ Widget* Builder::BuildWidget(Settings::BasicSetting* setting, return BuildWidget(setting, apply_funcs, request, true, 1.0f, other_setting, suffix); } -const ComboboxTranslationMap& Builder::ComboboxTranslations() const { +const TranslationShared::ComboboxTranslationMap& Builder::ComboboxTranslations() const { return *combobox_translations; } diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 226284cf36..51909105f0 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h @@ -67,8 +67,10 @@ public: * @param other_setting Second setting to modify, to replace the label with a checkbox * @param suffix Set to specify formats for Slider feedback labels or SpinBox */ - explicit Widget(Settings::BasicSetting* setting, const TranslationMap& translations, - const ComboboxTranslationMap& combobox_translations, QWidget* parent, + explicit Widget(Settings::BasicSetting* setting, + const TranslationShared::TranslationMap& translations, + const TranslationShared::ComboboxTranslationMap& combobox_translations, + QWidget* parent, bool runtime_lock, std::vector>& apply_funcs_, RequestType request = RequestType::Default, bool managed = true, float multiplier = default_multiplier, @@ -138,8 +140,8 @@ private: const std::function& touch); QWidget* parent; - const TranslationMap& translations; - const ComboboxTranslationMap& combobox_enumerations; + const TranslationShared::TranslationMap& translations; + const TranslationShared::ComboboxTranslationMap& combobox_enumerations; Settings::BasicSetting& setting; std::vector>& apply_funcs; @@ -165,11 +167,11 @@ public: RequestType request = RequestType::Default, const QString& suffix = default_suffix) const; - const ComboboxTranslationMap& ComboboxTranslations() const; + const TranslationShared::ComboboxTranslationMap& ComboboxTranslations() const; private: - std::unique_ptr translations; - std::unique_ptr combobox_translations; + std::unique_ptr translations; + std::unique_ptr combobox_translations; QWidget* parent; const bool runtime_lock;