# 微软bing翻译器python sdk
[![PyPI version](https://badge.fury.io/py/cn_bing_translator.svg)](https://badge.fury.io/py/cn_bing_translator)
[![Download count](https://img.shields.io/pypi/dm/cn_bing_translator)](https://img.shields.io/pypi/dm/cn_bing_translator)
## 介绍
微软bing翻译器,支持cn.bing.com和www.bing.com,建议轻量使用,欢迎star、follow、fork。
## 适用对象
无法或者不便使用微软Azaue Text Translation服务的用户轻量级用户可以使用bing提供的翻译能力。
## 源码
[github](https://github.com/minibear2021/cn_bing_translator)
[gitee](https://gitee.com/minibear2021/cn_bing_translator)
## 安装
```
pip install cn_bing_translator
```
## 使用方法
```python
from cn_bing_translator import Translator
if __name__ == "__main__":
translator = Translator()
source = "翻译器"
result = translator.process(source)
print(result)
```
默认情况下将自动检测源语言语种,并翻译为英语,如果需要指定其他语种,可以在初始化的时候传入对应的语言代码:
```python
# 传入以下参数初始化一个从英语到日语的翻译器
translator = Translator(fromLang='en', toLang='ja')
```
具体支持的语言类型和代码请参考[微软网站](https://learn.microsoft.com/en-us/azure/ai-services/translator/language-support)。
翻译器初始化的时候,也可以定制user agent:
```python
agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 Edg/99.0.4844.51'
translator = Translator(agent=agent)
```
如果有使用代理的需求,可以指定proxy:
```python
proxy = {'https':'http://localhost:8080'}
translator = Translator(proxy=proxy)
```
默认调用cn.bing.com,如需使用www.bing.com,可以在初始化的时候指定:
```python
translator = Translator(cnBing=False)
```
需要注意的是,根据bing.com的跳转规则,如果服务器判断是中国区用户访问,即使指定cnBing为False,仍然会自动跳转到cn.bing.com。
## 注意事项
建议轻量级使用,控制调用量和频率,微软bing翻译器默认带有防滥用措施,频繁发起大量请求可能会触发拦截。
Raw data
{
"_id": null,
"home_page": "https://github.com/minibear2021/cn_bing_translator",
"name": "cn-bing-translator",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "microsoft bing translator",
"author": "minibear",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/35/bd/4366321414955e3a6bf593c96909018924ec4a30661766b85f9eff5ad941/cn_bing_translator-0.0.3.tar.gz",
"platform": null,
"description": "# \u5fae\u8f6fbing\u7ffb\u8bd1\u5668python sdk\n\n[![PyPI version](https://badge.fury.io/py/cn_bing_translator.svg)](https://badge.fury.io/py/cn_bing_translator)\n[![Download count](https://img.shields.io/pypi/dm/cn_bing_translator)](https://img.shields.io/pypi/dm/cn_bing_translator)\n\n## \u4ecb\u7ecd\n\n\u5fae\u8f6fbing\u7ffb\u8bd1\u5668\uff0c\u652f\u6301cn.bing.com\u548cwww.bing.com\uff0c\u5efa\u8bae\u8f7b\u91cf\u4f7f\u7528\uff0c\u6b22\u8fcestar\u3001follow\u3001fork\u3002\n\n## \u9002\u7528\u5bf9\u8c61\n\n\u65e0\u6cd5\u6216\u8005\u4e0d\u4fbf\u4f7f\u7528\u5fae\u8f6fAzaue Text Translation\u670d\u52a1\u7684\u7528\u6237\u8f7b\u91cf\u7ea7\u7528\u6237\u53ef\u4ee5\u4f7f\u7528bing\u63d0\u4f9b\u7684\u7ffb\u8bd1\u80fd\u529b\u3002\n\n## \u6e90\u7801\n\n[github](https://github.com/minibear2021/cn_bing_translator)\n\n[gitee](https://gitee.com/minibear2021/cn_bing_translator)\n\n## \u5b89\u88c5\n\n```\npip install cn_bing_translator\n```\n\n## \u4f7f\u7528\u65b9\u6cd5\n\n```python\nfrom cn_bing_translator import Translator\n\nif __name__ == \"__main__\":\n translator = Translator()\n source = \"\u7ffb\u8bd1\u5668\"\n result = translator.process(source)\n print(result)\n```\n\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5c06\u81ea\u52a8\u68c0\u6d4b\u6e90\u8bed\u8a00\u8bed\u79cd\uff0c\u5e76\u7ffb\u8bd1\u4e3a\u82f1\u8bed\uff0c\u5982\u679c\u9700\u8981\u6307\u5b9a\u5176\u4ed6\u8bed\u79cd\uff0c\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u7684\u65f6\u5019\u4f20\u5165\u5bf9\u5e94\u7684\u8bed\u8a00\u4ee3\u7801\uff1a\n\n```python\n# \u4f20\u5165\u4ee5\u4e0b\u53c2\u6570\u521d\u59cb\u5316\u4e00\u4e2a\u4ece\u82f1\u8bed\u5230\u65e5\u8bed\u7684\u7ffb\u8bd1\u5668\ntranslator = Translator(fromLang='en', toLang='ja')\n```\n\n\u5177\u4f53\u652f\u6301\u7684\u8bed\u8a00\u7c7b\u578b\u548c\u4ee3\u7801\u8bf7\u53c2\u8003[\u5fae\u8f6f\u7f51\u7ad9](https://learn.microsoft.com/en-us/azure/ai-services/translator/language-support)\u3002\n\n\u7ffb\u8bd1\u5668\u521d\u59cb\u5316\u7684\u65f6\u5019\uff0c\u4e5f\u53ef\u4ee5\u5b9a\u5236user agent\uff1a\n\n```python\nagent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1 Edg/99.0.4844.51'\ntranslator = Translator(agent=agent)\n```\n\n\u5982\u679c\u6709\u4f7f\u7528\u4ee3\u7406\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u6307\u5b9aproxy\uff1a\n\n```python\nproxy = {'https':'http://localhost:8080'}\ntranslator = Translator(proxy=proxy)\n```\n\n\u9ed8\u8ba4\u8c03\u7528cn.bing.com\uff0c\u5982\u9700\u4f7f\u7528www.bing.com\uff0c\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u7684\u65f6\u5019\u6307\u5b9a\uff1a\n\n```python\ntranslator = Translator(cnBing=False)\n```\n\n\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6839\u636ebing.com\u7684\u8df3\u8f6c\u89c4\u5219\uff0c\u5982\u679c\u670d\u52a1\u5668\u5224\u65ad\u662f\u4e2d\u56fd\u533a\u7528\u6237\u8bbf\u95ee\uff0c\u5373\u4f7f\u6307\u5b9acnBing\u4e3aFalse\uff0c\u4ecd\u7136\u4f1a\u81ea\u52a8\u8df3\u8f6c\u5230cn.bing.com\u3002\n\n## \u6ce8\u610f\u4e8b\u9879\n\n\u5efa\u8bae\u8f7b\u91cf\u7ea7\u4f7f\u7528\uff0c\u63a7\u5236\u8c03\u7528\u91cf\u548c\u9891\u7387\uff0c\u5fae\u8f6fbing\u7ffb\u8bd1\u5668\u9ed8\u8ba4\u5e26\u6709\u9632\u6ee5\u7528\u63aa\u65bd\uff0c\u9891\u7e41\u53d1\u8d77\u5927\u91cf\u8bf7\u6c42\u53ef\u80fd\u4f1a\u89e6\u53d1\u62e6\u622a\u3002\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "microsoft cn.bing translator",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/minibear2021/cn_bing_translator"
},
"split_keywords": [
"microsoft",
"bing",
"translator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "973e7993b2ad858aa3e4543dc2e302274413a903ce4b3cd77faf2e40005deb2f",
"md5": "514ecd9ebba0c04374f0884aeca19f11",
"sha256": "e4063a456762dbbf0696fb5c7b540b9947dba76dd60f24662b37a9f11289481c"
},
"downloads": -1,
"filename": "cn_bing_translator-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "514ecd9ebba0c04374f0884aeca19f11",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5976,
"upload_time": "2023-07-21T06:12:53",
"upload_time_iso_8601": "2023-07-21T06:12:53.847369Z",
"url": "https://files.pythonhosted.org/packages/97/3e/7993b2ad858aa3e4543dc2e302274413a903ce4b3cd77faf2e40005deb2f/cn_bing_translator-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "35bd4366321414955e3a6bf593c96909018924ec4a30661766b85f9eff5ad941",
"md5": "e0c4c6cf98e5b0417dd8141fd35be613",
"sha256": "406b70ff2217c2731816e6c9434168e5dbbdf40a5b0d98dd0d69dc88fe907bd7"
},
"downloads": -1,
"filename": "cn_bing_translator-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "e0c4c6cf98e5b0417dd8141fd35be613",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5079,
"upload_time": "2023-07-21T06:12:55",
"upload_time_iso_8601": "2023-07-21T06:12:55.169558Z",
"url": "https://files.pythonhosted.org/packages/35/bd/4366321414955e3a6bf593c96909018924ec4a30661766b85f9eff5ad941/cn_bing_translator-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-21 06:12:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "minibear2021",
"github_project": "cn_bing_translator",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "cn-bing-translator"
}