From 5551e82fea2e2de8f5745d8e2b54dd33faaf48a8 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 14 Jun 2022 11:54:34 +0200 Subject: [PATCH] ui: Fix hash function name localization --- .../include/hex/api/content_registry.hpp | 8 ++++---- plugins/builtin/source/content/hashes.cpp | 16 ++++++++-------- .../builtin/source/content/views/view_hashes.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/libimhex/include/hex/api/content_registry.hpp b/lib/libimhex/include/hex/api/content_registry.hpp index 620ec9344..d9006e367 100644 --- a/lib/libimhex/include/hex/api/content_registry.hpp +++ b/lib/libimhex/include/hex/api/content_registry.hpp @@ -426,7 +426,7 @@ namespace hex { class Hash { public: - Hash(std::string name) : m_name(std::move(name)) {} + Hash(std::string unlocalizedName) : m_unlocalizedName(std::move(unlocalizedName)) {} class Function { public: @@ -463,8 +463,8 @@ namespace hex { virtual void draw() { } [[nodiscard]] virtual Function create(std::string name) = 0; - [[nodiscard]] const std::string &getName() const { - return this->m_name; + [[nodiscard]] const std::string &getUnlocalizedName() const { + return this->m_unlocalizedName; } protected: @@ -473,7 +473,7 @@ namespace hex { } private: - std::string m_name; + std::string m_unlocalizedName; }; namespace impl { diff --git a/plugins/builtin/source/content/hashes.cpp b/plugins/builtin/source/content/hashes.cpp index cff3dbcf2..69f0cd0c5 100644 --- a/plugins/builtin/source/content/hashes.cpp +++ b/plugins/builtin/source/content/hashes.cpp @@ -8,7 +8,7 @@ namespace hex::plugin::builtin { class HashMD5 : public ContentRegistry::Hashes::Hash { public: - HashMD5() : Hash("hex.builtin.hash.md5"_lang) {} + HashMD5() : Hash("hex.builtin.hash.md5") {} Function create(std::string name) override { return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector { @@ -21,7 +21,7 @@ namespace hex::plugin::builtin { class HashSHA1 : public ContentRegistry::Hashes::Hash { public: - HashSHA1() : Hash("hex.builtin.hash.sha1"_lang) {} + HashSHA1() : Hash("hex.builtin.hash.sha1") {} Function create(std::string name) override { return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector { @@ -34,7 +34,7 @@ namespace hex::plugin::builtin { class HashSHA224 : public ContentRegistry::Hashes::Hash { public: - HashSHA224() : Hash("hex.builtin.hash.sha224"_lang) {} + HashSHA224() : Hash("hex.builtin.hash.sha224") {} Function create(std::string name) override { return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector { @@ -47,7 +47,7 @@ namespace hex::plugin::builtin { class HashSHA256 : public ContentRegistry::Hashes::Hash { public: - HashSHA256() : Hash("hex.builtin.hash.sha256"_lang) {} + HashSHA256() : Hash("hex.builtin.hash.sha256") {} Function create(std::string name) override { return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector { @@ -60,7 +60,7 @@ namespace hex::plugin::builtin { class HashSHA384 : public ContentRegistry::Hashes::Hash { public: - HashSHA384() : Hash("hex.builtin.hash.sha384"_lang) {} + HashSHA384() : Hash("hex.builtin.hash.sha384") {} Function create(std::string name) override { return Hash::create(name, [](const Region& region, prv::Provider *provider) -> std::vector { @@ -131,9 +131,9 @@ namespace hex::plugin::builtin { ContentRegistry::Hashes::add(); ContentRegistry::Hashes::add(); - ContentRegistry::Hashes::add>("hex.builtin.hash.crc8"_lang, crypt::crc8, 0x07, 0x0000, 0x0000); - ContentRegistry::Hashes::add>("hex.builtin.hash.crc16"_lang, crypt::crc16, 0x8005, 0x0000, 0x0000); - ContentRegistry::Hashes::add>("hex.builtin.hash.crc32"_lang, crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF); + ContentRegistry::Hashes::add>("hex.builtin.hash.crc8", crypt::crc8, 0x07, 0x0000, 0x0000); + ContentRegistry::Hashes::add>("hex.builtin.hash.crc16", crypt::crc16, 0x8005, 0x0000, 0x0000); + ContentRegistry::Hashes::add>("hex.builtin.hash.crc32", crypt::crc32, 0x04C1'1DB7, 0xFFFF'FFFF, 0xFFFF'FFFF); } diff --git a/plugins/builtin/source/content/views/view_hashes.cpp b/plugins/builtin/source/content/views/view_hashes.cpp index 12b0c9095..5d25151e9 100644 --- a/plugins/builtin/source/content/views/view_hashes.cpp +++ b/plugins/builtin/source/content/views/view_hashes.cpp @@ -70,10 +70,10 @@ namespace hex::plugin::builtin { } if (ImGui::Begin(View::toWindowName("hex.builtin.view.hashes.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) { - if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, this->m_selectedHash != nullptr ? this->m_selectedHash->getName().c_str() : "")) { + if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, this->m_selectedHash != nullptr ? LangEntry(this->m_selectedHash->getUnlocalizedName()) : "")) { for (const auto hash : hashes) { - if (ImGui::Selectable(hash->getName().c_str(), this->m_selectedHash == hash)) { + if (ImGui::Selectable(LangEntry(hash->getUnlocalizedName()), this->m_selectedHash == hash)) { this->m_selectedHash = hash; this->m_newHashName.clear(); } @@ -83,7 +83,7 @@ namespace hex::plugin::builtin { } if (this->m_newHashName.empty() && this->m_selectedHash != nullptr) - this->m_newHashName = hex::format("{} {}", this->m_selectedHash->getName(), static_cast("hex.builtin.view.hashes.hash"_lang)); + this->m_newHashName = hex::format("{} {}", LangEntry(this->m_selectedHash->getUnlocalizedName()), static_cast("hex.builtin.view.hashes.hash"_lang)); if (ImGui::BeginChild("##settings", ImVec2(ImGui::GetContentRegionAvailWidth(), 200_scaled), true)) { if (this->m_selectedHash != nullptr) { @@ -150,7 +150,7 @@ namespace hex::plugin::builtin { } ImGui::TableNextColumn(); - ImGui::TextFormatted("{}", function.getType()->getName()); + ImGui::TextFormatted("{}", LangEntry(function.getType()->getUnlocalizedName())); ImGui::TableNextColumn(); std::string result;