diff --git a/README.md b/README.md index 363d9b1..00831a7 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ ## 2023-12-17 +- update version to `0.0.5` +- fix translation error for `alibaba` platform +- fix translator name typo for `tencent` platform + +## 2023-12-17 + - update version to `0.0.4` - update README - add `Load Image Path` node diff --git a/config.yaml.example b/config.yaml.example index 61a7317..f335a0d 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -1,25 +1,22 @@ -# # 文本翻译配置 -# translator: -# # 百度云 -# baidu: -# key: "" -# secret: "" -# # 阿里云 -# alibaba: -# key: "" -# secret: "" -# region: cn-beijing -# # 腾讯云 -# tecent: -# key: "" -# secret: "" -# region: ap-beijing -# project: 0 -# # 火山引擎 -# volcengine: -# key: "" -# secret: "" -# region: cn-beijing -# # 小牛翻译 -# niutrans: -# secret: "" +# copy and rename this to `config.yaml` +# make sure save as `utf-8` encoding + +translator: + baidu: + key: "" + secret: "" + alibaba: + key: "" + secret: "" + region: cn-beijing + tencent: + key: "" + secret: "" + region: ap-beijing + project: 0 + volcengine: + key: "" + secret: "" + region: cn-beijing + niutrans: + secret: "" diff --git a/utils.py b/utils.py index 642af8b..c0e35b2 100644 --- a/utils.py +++ b/utils.py @@ -20,7 +20,7 @@ from functools import reduce -VERSION = "0.0.4" +VERSION = "0.0.5" ADDON_NAME = "zfkun" HOME_PATH = os.path.dirname(os.path.realpath(__file__)) @@ -340,6 +340,7 @@ def text_translate(platform:str, text:str, source="auto", target="en"): def _text_translate_baidu(text:str, source="auto", target="en"): c = get_translator_config("baidu") if not c: + printColorError('get translator fail: baidu') return (text, source, target,) result = text @@ -383,6 +384,7 @@ def _text_translate_baidu(text:str, source="auto", target="en"): def _text_translate_alibaba_v3(text: str, source="auto", target="en", region="cn-beijing"): c = get_translator_config("alibaba") if not c: + printColorError('get translator fail: alibaba') return (text, source, target,) secret_id = c['key'] or "" @@ -397,7 +399,7 @@ def _text_translate_alibaba_v3(text: str, source="auto", target="en", region="cn action = "TranslateGeneral" version = "2018-10-12" algorithm = "ACS3-HMAC-SHA256" - request_date = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') + request_date = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') nonce = str(uuid.uuid4()) # ************* 步骤 1:拼接规范请求串 ************* @@ -459,6 +461,7 @@ def _text_translate_alibaba_v3(text: str, source="auto", target="en", region="cn "x-acs-signature-nonce": nonce, "x-acs-version": version, } + printColor(f'alibaba translate start: {from_code} => {to_code}') @@ -493,6 +496,7 @@ def _text_translate_alibaba_v3(text: str, source="auto", target="en", region="cn def _text_translate_tencent_v3(text: str, source="auto", target="en", region="ap-beijing"): c = get_translator_config("tencent") if not c: + printColorError('get translator fail: tencent') return (text, source, target,) secret_id = c['key'] or "" @@ -567,7 +571,7 @@ def _text_translate_tencent_v3(text: str, source="auto", target="en", region="ap printColor(f'tencent translate start: {from_code} => {to_code}') hc = http.client.HTTPSConnection(host) - hc.set_debuglevel(2) + # hc.set_debuglevel(2) try: hc.request('POST', canonical_uri, payload.encode('utf-8'), headers) @@ -598,6 +602,7 @@ def _text_translate_tencent_v3(text: str, source="auto", target="en", region="ap def _text_translate_volcengine_v4(text: str, source="auto", target="en", region="cn-beijing"): c = get_translator_config("volcengine") if not c: + printColorError('get translator fail: volcengine') return (text, source, target,) secret_id = c['key'] or "" @@ -699,6 +704,7 @@ def _text_translate_volcengine_v4(text: str, source="auto", target="en", region= def _text_translate_niutrans(text: str, source="auto", target="en"): c = get_translator_config("niutrans") if not c: + printColorError('get translator fail: niutrans') return (text, source, target,) secret_key = c['secret'] or ""