Update translate func for title

This commit is contained in:
yoshiko2
2021-11-09 13:35:58 +08:00
parent 0aa8bc3a90
commit 963320a14e
2 changed files with 8 additions and 31 deletions

21
ADC_function.py Executable file → Normal file
View File

@@ -299,27 +299,6 @@ f"https://{gsite}/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl={t
translate_list = [i["trans"] for i in result.json()["sentences"]]
trans_result = trans_result.join(translate_list)
# elif engine == "baidu":
# url = "https://fanyi-api.baidu.com/api/trans/vip/translate"
# salt = secrets.randbelow(1435660287) + 1 # random.randint(1, 1435660288)
# sign = app_id + src + str(salt) + key
# sign = hashlib.md5(sign.encode()).hexdigest()
# url += (
# "?appid="
# + app_id
# + "&q="
# + src
# + "&from=auto&to="
# + target_language
# + "&salt="
# + str(salt)
# + "&sign="
# + sign
# )
# result = get_html(url=url, return_type="object")
#
# translate_list = [i["dst"] for i in result.json()["trans_result"]]
# trans_result = trans_result.join(translate_list)
elif engine == "azure":
url = "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=" + target_language
headers = {

View File

@@ -275,16 +275,14 @@ def get_data_from_json(file_number, oCC): # 从JSON返回元数据
for translate_value in translate_values:
if json_data[translate_value] == "":
continue
t = ""
# if conf.get_transalte_engine() == "baidu":
# json_data[translate_value] = translate(
# json_data[translate_value],
# target_language="zh",
# engine=conf.get_transalte_engine(),
# app_id=conf.get_transalte_appId(),
# key=conf.get_transalte_key(),
# delay=conf.get_transalte_delay(),
# )
if translate_value == "title":
title_dict = json.load(
open(str(Path.home() / '.local' / 'share' / 'avdc' / 'c_number.json'), 'r', encoding="utf-8"))
try:
json_data[translate_value] = title_dict[number]
continue
except:
pass
if conf.get_transalte_engine() == "azure":
t = translate(
json_data[translate_value],