Fix Sakura Dict of CHT (#976)

* fix sakura dict cht to chs

* add zhhant, zhhans and fix dict
This commit is contained in:
CHLBC 2024-08-09 17:46:12 +08:00 committed by GitHub
parent 835b63a250
commit 846253f861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 5 deletions

View File

@ -52,8 +52,13 @@ class TS(basetrans):
gpt_dict_text_list = [] gpt_dict_text_list = []
for gpt in gpt_dict: for gpt in gpt_dict:
src = gpt["src"] src = gpt["src"]
dst = gpt["dst"] if self.needzhconv:
info = gpt["info"] if "info" in gpt.keys() else None 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: if info:
single = f"{src}->{dst} #{info}" single = f"{src}->{dst} #{info}"
else: else:
@ -106,8 +111,6 @@ class TS(basetrans):
content = "" content = ""
gpt_dict_raw_text = self.make_gpt_dict_text(gpt_dict) 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 += "根据以下术语表(可以为空):\n" + gpt_dict_raw_text + "\n\n"
content += ( content += (

View File

@ -8,6 +8,8 @@ dict_zhcn = None
dict_zhsg = None dict_zhsg = None
dict_zhtw = None dict_zhtw = None
dict_zhhk = None dict_zhhk = None
dict_zhhans = None
dict_zhhant = None
pfsdict = {} pfsdict = {}
@ -30,7 +32,7 @@ def getdict(locale):
Generate or get convertion dict cache for certain locale. Generate or get convertion dict cache for certain locale.
Dictionaries are loaded on demand. 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: if zhcdicts is None:
loaddict(DICTIONARY) loaddict(DICTIONARY)
if locale == "zh-cn": if locale == "zh-cn":
@ -47,6 +49,18 @@ def getdict(locale):
dict_zhtw = zhcdicts["zh2Hant"].copy() dict_zhtw = zhcdicts["zh2Hant"].copy()
dict_zhtw.update(zhcdicts["zh2TW"]) dict_zhtw.update(zhcdicts["zh2TW"])
got = dict_zhtw 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: if locale not in pfsdict:
pfsdict[locale] = getpfset(got) pfsdict[locale] = getpfset(got)