
这个包把提供翻译的几家服务做了个整合,方便 python 调用,包括:谷歌、有道、百度、金山。
支持各种源语言和目标语言,这里是语言列表。
支持代理设置,不过目前提供的谷歌翻译暂时不需要使用代理。
这两天刚好用到,写了点代码,干脆做成包,放出来。
代码很简单,源码在github上,有需要自取吧。
pip install translation 基本使用
from translation import baidu, google, youdao, iciba print(google('hello world!', dst = 'zh-CN')) print(google('hello world!', dst = 'ru')) print(baidu('hello world!', dst = 'zh')) print(baidu('hello world!', dst = 'ru')) print(youdao('hello world!', dst = 'zh-CN')) print(iciba('hello world!', dst = 'zh')) 代理
from translation import google, ConnectError # 127.0.0.1:1080 is a vaild proxies try: print(google('hello world!', src = 'auto', dst = 'zh-CN', proxies = {'http': '127.0.0.1:1080'})) except ConnectError: print('Invaild proxy') 1 katyang 2016-07-07 21:53:13 +08:00 安装遇到错误 from main import Translation ImportError: No module named 'main' 红字显示 Command "python setup.py egg_info" failed with error code 1 in …… |
2 与`ydcv`有什么区别? |
3 yuyang1110 2016-07-07 22:27:48 +08:00 proxy 并不需要呀。。。 python 用 http_proxy=blah blah python main.py 就好了 |
4 NxnXgpuPSfsIT OP @yuyang1110 我是写一个要打包成 exe 的程序的时候用到了这个东西,所以就加了 proxy 进去。也方便中途修改吧。 |
5 NxnXgpuPSfsIT OP @vimmer 这个多了谷歌百度金山?有文档?那个没用过具体不是很清楚 |
6 NxnXgpuPSfsIT OP @katyang 不好意思,刚好像因为连不上 pypi , py3 的更新没成功传上去,你重新试一下: pip install translation --upgrade |
7 fzinfz 2016-07-07 22:54:19 +08:00 via iPad 我是来找英语 bug 的... a ... proxies? ies , es , s...... |
8 NxnXgpuPSfsIT OP @fzinfz 哈哈,好的。因为参数的 key 是 proxies ,所以将就着只能这样了(摊手) |
9 katyang 2016-07-07 23:40:22 +08:00 @NxnXgpuPSfsIT 下载成功,已经开始使用,谢谢 |
10 katyang 2016-07-09 11:44:55 +08:00 @NxnXgpuPSfsIT 想问问,没有加必应翻译是故意的吗? |
11 NxnXgpuPSfsIT OP @katyang 不是啦,之后更新版本再加 |
12 katyang 2016-07-10 08:18:55 +08:00 @NxnXgpuPSfsIT 期待 |
13 NxnXgpuPSfsIT OP @katyang 已更新 Bing 翻译 |
14 katyang 2016-07-18 07:37:35 +08:00 |
15 NxnXgpuPSfsIT OP @katyang 支持的语言标志可以看这里: http://translation.readthedocs.io/zh_CN/latest/Language/ |
16 katyang 2016-07-18 11:05:21 +08:00 @NxnXgpuPSfsIT 谢谢,已经用上了 :) |
17 GoTop 2016-09-09 17:07:08 +08:00 google 翻译,用了 http 代理还是提示异常呢 请问怎么使用 socks5 代理啊 |
18 NxnXgpuPSfsIT OP @GoTop 现在版本的 google 翻译应该不用代理也可以用 |