添加可选的翻译功能

This commit is contained in:
PikachuLiker
2020-11-02 22:18:17 +08:00
parent c1039872b9
commit fb453763df
4 changed files with 34 additions and 2 deletions

View File

@@ -451,3 +451,11 @@ def translateTag_to_sc(tag):
return tag
else:
return tag
def translate(src:str,target_language:str="zh_cn"):
url = f"https://translate.google.cn/translate_a/single?client=gtx&dt=t&dj=1&ie=UTF-8&sl=auto&tl={target_language}&q={src}"
result = get_html(url=url,return_type="object")
translate_list = [i["trans"] for i in result.json()["sentences"]]
return "".join(translate_list)