Skip to content

Commit

Permalink
fix translation error for alibaba platform
Browse files Browse the repository at this point in the history
fix translator name typo for `tencent` platform
  • Loading branch information
zfkun committed Dec 17, 2023
1 parent 896258f commit c0c5f2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 22 additions & 25 deletions config.yaml.example
Original file line number Diff line number Diff line change
@@ -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: ""
12 changes: 9 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ""
Expand All @@ -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:拼接规范请求串 *************
Expand Down Expand Up @@ -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}')

Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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 ""
Expand Down

0 comments on commit c0c5f2b

Please sign in to comment.