From 846253f8611e88d96c36b18cc9ca1f01fb813a5c Mon Sep 17 00:00:00 2001 From: CHLBC <42777336+chlbc@users.noreply.github.com> Date: Fri, 9 Aug 2024 17:46:12 +0800 Subject: [PATCH] Fix Sakura Dict of CHT (#976) * fix sakura dict cht to chs * add zhhant, zhhans and fix dict --- .../LunaTranslator/translator/sakura.py | 11 +++++++---- LunaTranslator/LunaTranslator/zhconv.py | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/sakura.py b/LunaTranslator/LunaTranslator/translator/sakura.py index 82add5ee..bc242fd2 100644 --- a/LunaTranslator/LunaTranslator/translator/sakura.py +++ b/LunaTranslator/LunaTranslator/translator/sakura.py @@ -52,8 +52,13 @@ class TS(basetrans): gpt_dict_text_list = [] for gpt in gpt_dict: src = gpt["src"] - dst = gpt["dst"] - info = gpt["info"] if "info" in gpt.keys() else None + if self.needzhconv: + dst = zhconv.convert(gpt["dst"], "zh-hans") + info = zhconv.convert(gpt["info"], "zh-hans") if "info" in gpt.keys() else None + else: + dst = gpt["dst"] + info = gpt["info"] if "info" in gpt.keys() else None + if info: single = f"{src}->{dst} #{info}" else: @@ -106,8 +111,6 @@ class TS(basetrans): content = "" gpt_dict_raw_text = self.make_gpt_dict_text(gpt_dict) - if self.needzhconv: - gpt_dict_raw_text = zhconv.convert(gpt_dict_raw_text, "zh-cn") content += "根据以下术语表(可以为空):\n" + gpt_dict_raw_text + "\n\n" content += ( diff --git a/LunaTranslator/LunaTranslator/zhconv.py b/LunaTranslator/LunaTranslator/zhconv.py index bfb15a1b..d536b4f7 100644 --- a/LunaTranslator/LunaTranslator/zhconv.py +++ b/LunaTranslator/LunaTranslator/zhconv.py @@ -8,6 +8,8 @@ dict_zhcn = None dict_zhsg = None dict_zhtw = None dict_zhhk = None +dict_zhhans = None +dict_zhhant = None pfsdict = {} @@ -30,7 +32,7 @@ def getdict(locale): Generate or get convertion dict cache for certain locale. Dictionaries are loaded on demand. """ - global zhcdicts, dict_zhcn, dict_zhsg, dict_zhtw, dict_zhhk, pfsdict + global zhcdicts, dict_zhcn, dict_zhsg, dict_zhtw, dict_zhhk, dict_zhhans, dict_zhhant, pfsdict if zhcdicts is None: loaddict(DICTIONARY) if locale == "zh-cn": @@ -47,6 +49,18 @@ def getdict(locale): dict_zhtw = zhcdicts["zh2Hant"].copy() dict_zhtw.update(zhcdicts["zh2TW"]) got = dict_zhtw + elif locale == "zh-hans": + if dict_zhhans: + got = dict_zhhans + else: + dict_zhhans = zhcdicts["zh2Hans"].copy() + got = dict_zhhans + elif locale == "zh-hant": + if dict_zhhant: + got = dict_zhhant + else: + dict_zhtw = zhcdicts["zh2Hant"].copy() + got = dict_zhhant if locale not in pfsdict: pfsdict[locale] = getpfset(got)