From 1dfe4dda1cbbf46d10c3bed6ad553f775b0c738a Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 28 Jan 2023 09:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=AC=E5=9C=B0=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E4=B8=8E=E9=BB=98=E8=AE=A4=E7=9A=84=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E7=AE=80=E4=BD=93=E8=AF=AD=E8=A8=80=E7=9B=B4=E6=8E=A5=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_language.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/app_language.cpp b/app_language.cpp index 6971967..d8d794f 100644 --- a/app_language.cpp +++ b/app_language.cpp @@ -686,9 +686,11 @@ public: notify_.erase(it); } } - int get_default_string_id(const char* str) + int get_string_id(const char* str, bool def) { - for (auto& v : map_default_) + std::map* lang = def ? &map_default_ : pak_now_; + + for (auto& v : *lang) { if (v.second == str) return v.first; @@ -696,6 +698,42 @@ public: return -1; } + const char* transform_language(const char* in, bool to_def, bool* found) + { + if (cur_cp_ == DEFAULT_CODE_PAGE) + { + if (found) + *found = true; + + return in; + } + + int id = get_string_id(in, false); + std::map* t = to_def ? &map_default_ : pak_now_; + + if (id == -1) + { + if (found) + *found = false; + + return in; + } + + if (t->count(id)) + { + if (found) + *found = true; + + return (*t)[id].c_str(); + } + else + { + if (found) + *found = false; + + return in; + } + } }; lang_mgr* lang_mgr::inst_ = nullptr; @@ -729,8 +767,17 @@ extern "C" lang_mgr::instance()->register_language_changed_notify(lan_changed, reg, param); } - int lang_get_string_id(const char* utf8_hz) + int lang_get_string_id(const char* str, bool def_lang) { - return lang_mgr::instance()->get_default_string_id(utf8_hz); + return lang_mgr::instance()->get_string_id(str, def_lang); + } + + const char* to_default_language(const char* str, bool* ok) + { + return lang_mgr::instance()->transform_language(str, true, ok); + } + const char* from_default_language(const char* str, bool* ok) + { + return lang_mgr::instance()->transform_language(str, false, ok); } }