From bd4f1da8c8b58ba0d80c1e955fa1c6f57e36d0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:17:30 +0800 Subject: [PATCH] lang --- .../LunaTranslator/myutils/commonbase.py | 4 ++-- .../LunaTranslator/translator/deepl.py | 15 +++++++++++---- .../LunaTranslator/translator/deepl_dev.py | 12 ++++++++++++ .../LunaTranslator/translator/deeplapi-free.py | 16 ++++++++++++---- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/LunaTranslator/LunaTranslator/myutils/commonbase.py b/LunaTranslator/LunaTranslator/myutils/commonbase.py index dc012681..0d3edc24 100644 --- a/LunaTranslator/LunaTranslator/myutils/commonbase.py +++ b/LunaTranslator/LunaTranslator/myutils/commonbase.py @@ -37,11 +37,11 @@ class commonbase: return self.langmap_.get(self.srclang_1, "") @property - def srclang_1(self): + def srclang_1(self) -> str: return getlangsrc() @property - def tgtlang_1(self): + def tgtlang_1(self) -> str: return getlangtgt() @property diff --git a/LunaTranslator/LunaTranslator/translator/deepl.py b/LunaTranslator/LunaTranslator/translator/deepl.py index 71761b4a..a9240a3a 100644 --- a/LunaTranslator/LunaTranslator/translator/deepl.py +++ b/LunaTranslator/LunaTranslator/translator/deepl.py @@ -55,10 +55,17 @@ def initDeepLXData(sourceLang: str, targetLang: str): class TS(basetrans): - def langmap(self): - x = {_: _.upper() for _ in [_["code"] for _ in static_data["lang_list_all"]]} - x.pop("cht") - return x # {"zh":"ZH","ja":"JA","en":"EN","es":"ES","fr":"FR","ru":"RU"} + @property + def srclang(self): + if self.srclang_1 == "cht": + return "ZH" + return self.srclang_1.upper() + + @property + def tgtlang(self): + if self.tgtlang_1 == "cht": + return "ZH-HANT" + return self.tgtlang_1.upper() def translate(self, translateText): if self.config["usewhich"] == 0: diff --git a/LunaTranslator/LunaTranslator/translator/deepl_dev.py b/LunaTranslator/LunaTranslator/translator/deepl_dev.py index e773616e..8cc29b33 100644 --- a/LunaTranslator/LunaTranslator/translator/deepl_dev.py +++ b/LunaTranslator/LunaTranslator/translator/deepl_dev.py @@ -5,6 +5,18 @@ from translator.basetranslator_dev import basetransdev class TS(basetransdev): target_url = "https://www.deepl.com/en/translator" + @property + def srclang(self): + if self.srclang_1 == "cht": + return "zh" + return self.srclang_1.upper() + + @property + def tgtlang(self): + if self.tgtlang_1 == "cht": + return "zh-hant" + return self.tgtlang_1 + def translate(self, content): self.Page_navigate( "https://www.deepl.com/en/translator#{}/{}/{}".format( diff --git a/LunaTranslator/LunaTranslator/translator/deeplapi-free.py b/LunaTranslator/LunaTranslator/translator/deeplapi-free.py index 06a82ad1..bd0f85b1 100644 --- a/LunaTranslator/LunaTranslator/translator/deeplapi-free.py +++ b/LunaTranslator/LunaTranslator/translator/deeplapi-free.py @@ -4,10 +4,18 @@ from translator.basetranslator import basetrans class TS(basetrans): - def langmap(self): - x = {_: _.upper() for _ in [_["code"] for _ in static_data["lang_list_all"]]} - x.pop("cht") - return x + + @property + def srclang(self): + if self.srclang_1 == "cht": + return "ZH" + return self.srclang_1.upper() + + @property + def tgtlang(self): + if self.tgtlang_1 == "cht": + return "ZH-HANT" + return self.tgtlang_1.upper() def translate(self, query): if self.config["usewhich"] == 0: