Github代码
网址:https://github.com/Chinese-boy/Many-Translaters/blob/master/谷歌翻译.py
运行报错
Could not find an available JavaScript runtime
则说明缺少nodejs,直接apt install nodejs
就可以使用了。
参考ExecJS and could not find a JavaScript runtime
修改代码
原代码只能将英文转成中文,而我们想将任意语言转成英文。
则需要将代码对应部分
url = "http://translate.google.cn/translate_a/single?client=t" \
"&sl=en&tl=zh-CN&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca" \
"&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&clearbtn=1&otf=1&pc=1" \
"&srcrom=0&ssel=0&tsel=0&kc=2&tk=%s&q=%s" % (tk, content)
修改为:
url = "http://translate.google.cn/translate_a/single?client=t" \
"&sl=auto&tl=en&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca" \
"&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&clearbtn=1&otf=1&pc=1" \
"&srcrom=0&ssel=0&tsel=0&kc=2&tk=%s&q=%s" % (tk, content)
修改的地方为&sl=auto&tl=en
,sl
代表源语言,tl
代表目标语言。