From ce9ce42c1c5a1599fc3c12cae8c8ff02ac376f23 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 9 Jul 2023 20:24:56 +0200 Subject: [PATCH] impr: Only reload localization when necessary --- lib/libimhex/include/hex/api/localization.hpp | 3 +++ lib/libimhex/source/api/localization.cpp | 7 +++++++ plugins/builtin/source/content/welcome_screen.cpp | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/libimhex/include/hex/api/localization.hpp b/lib/libimhex/include/hex/api/localization.hpp index 723a9a428..036a8770f 100644 --- a/lib/libimhex/include/hex/api/localization.hpp +++ b/lib/libimhex/include/hex/api/localization.hpp @@ -39,10 +39,13 @@ namespace hex { static void resetLanguageStrings(); + static const std::string &getSelectedLanguage(); + private: std::string m_unlocalizedString; static std::string s_fallbackLanguage; + static std::string s_selectedLanguage; static std::map s_currStrings; }; diff --git a/lib/libimhex/source/api/localization.cpp b/lib/libimhex/source/api/localization.cpp index 85eaea49a..f91d79f23 100644 --- a/lib/libimhex/source/api/localization.cpp +++ b/lib/libimhex/source/api/localization.cpp @@ -5,6 +5,7 @@ namespace hex { std::string LangEntry::s_fallbackLanguage; + std::string LangEntry::s_selectedLanguage; std::map LangEntry::s_currStrings; LanguageDefinition::LanguageDefinition(std::map &&entries) { @@ -89,6 +90,8 @@ namespace hex { for (auto &definition : definitions[fallbackLanguage]) LangEntry::s_currStrings.insert(definition.getEntries().begin(), definition.getEntries().end()); } + + LangEntry::s_selectedLanguage = language; } const std::map &LangEntry::getSupportedLanguages() { @@ -107,4 +110,8 @@ namespace hex { LangEntry::s_currStrings.clear(); } + const std::string &LangEntry::getSelectedLanguage() { + return s_selectedLanguage; + } + } \ No newline at end of file diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index ae9564a87..7ba0880d9 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -403,7 +403,8 @@ namespace hex::plugin::builtin { { auto language = ContentRegistry::Settings::read("hex.builtin.setting.interface", "hex.builtin.setting.interface.language", "en-US"); - LangEntry::loadLanguage(language); + if (language != LangEntry::getSelectedLanguage()) + LangEntry::loadLanguage(language); } {