fix:增加语言翻译脚本和两国语言文件
This commit is contained in:
parent
c0b2114683
commit
91bbaabf1c
1161
lan/lan_hy.json
Normal file
1161
lan/lan_hy.json
Normal file
File diff suppressed because it is too large
Load Diff
1161
lan/lan_ka.json
Normal file
1161
lan/lan_ka.json
Normal file
File diff suppressed because it is too large
Load Diff
29
langAi.py
29
langAi.py
@ -15,7 +15,7 @@ import requests
|
||||
# 运行格式方式:python langAi.py youdao 备注:aliyun 阿里云 youdao 有道翻译
|
||||
|
||||
# 语言文件路径 /Users/mac/www/app-starlock/lan
|
||||
path = "/Users/mac/Desktop/app-starlock/lan/"
|
||||
path = "./lan2/"
|
||||
# 原语言
|
||||
SOURCE_LANG = 'lan_en'
|
||||
|
||||
@ -312,10 +312,14 @@ YOUDAO_LANG_MAP = {
|
||||
'name': '塞尔维亚语(西里尔文)',
|
||||
'code': 'sr-Cyrl'
|
||||
},
|
||||
# 'lan_sr_latn': {
|
||||
# 'name': '塞尔维亚语(拉丁文)',
|
||||
# 'code': 'sr-Latn'
|
||||
# },
|
||||
'lan_hy': {
|
||||
'name': '亚美尼亚语',
|
||||
'code': 'hy'
|
||||
},
|
||||
'lan_ka': {
|
||||
'name': '格鲁吉亚语',
|
||||
'code': 'ka'
|
||||
},
|
||||
}
|
||||
|
||||
# =============================== 以下为固定代码,非必要请勿修改 ===============================
|
||||
@ -410,8 +414,8 @@ def translation(channel, source_language, target_language, text):
|
||||
translation_text = aliyun_translation(source_language, target_language, text)
|
||||
elif channel == 'youdao':
|
||||
translation_text = youdao_translation(source_language, target_language, text)
|
||||
# 延迟1秒
|
||||
time.sleep(1)
|
||||
# 延迟2秒
|
||||
time.sleep(2)
|
||||
|
||||
return translation_text
|
||||
|
||||
@ -444,8 +448,15 @@ def youdao_translation(source_language, target_language, text):
|
||||
post_body['sign'] = sign
|
||||
|
||||
req = fetch_content(YOUDAO_CONFIG['domain'], 'POST', post_body)
|
||||
req = json.loads(req)
|
||||
return req['translation'][0]
|
||||
req_json = json.loads(req)
|
||||
try:
|
||||
return req_json['translation'][0]
|
||||
except KeyError as e:
|
||||
print(f"[翻译异常][KeyError] 目标语言: {target_language}, key: {text}, API返回: {req_json}, 请求参数: {post_body}")
|
||||
raise
|
||||
except Exception as e:
|
||||
print(f"[翻译异常][OtherError] 目标语言: {target_language}, key: {text}, API返回: {req_json}, 请求参数: {post_body}, 异常: {e}")
|
||||
raise
|
||||
|
||||
|
||||
# 阿里云翻译
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user