免费的google python翻译api。完全免费翻译。
aiogoogletrans的Python项目详细描述
aiogoogletrans是一个支持异步的[googletrans](https://github.com/ssut/py-googletrans)fork。
与Python3.6+兼容
功能
- 异步
- 快速可靠-它使用的服务器与 translate.google.com使用
- 自动语言检测
- 批量翻译
- 可自定义的服务URL
安装
要安装,可以使用pip和包“aiogoogletrans”这样的东西 或者下载包并将“aiogogogletrans”目录放入 python路径。无论如何,值得注意的是,这只需要两个 模块:请求和未来。
$ pip install aiogoogletrans
基本用法
如果没有给出源语言,google translate将尝试检测 源语言。
>>>fromaiogoogletransimportTranslator>>>translator=Translator()>>>importasyncio>>>loop=asyncio.get_event_loop()>>>loop.run_until_complete(translator.translate('안녕하세요.'))# <Translated src=ko confidence=1.0 dest=en text=Good evening. pronunciation=Good evening.>>>>loop.run_until_complete(translator.translate('안녕하세요.',dest='ja'))# <Translated src=ko confidence=1.0 dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>>>>loop.run_until_complete(translator.translate('veritas lux mea',src='la'))# <Translated src=la confidence=1.0 dest=en text=The truth is my light pronunciation=The truth is my light>
自定义服务url
你可以使用另一个谷歌翻译域名进行翻译。如果是多重的 提供url,然后随机选择一个域。
>>>fromaiogoogletransimportTranslator>>>translator=Translator(service_urls=['translate.google.com','translate.google.co.kr',])
高级使用(批量)
数组可用于在单个方法中转换一批字符串 调用和单个http会话。与上述方法完全相同 对于数组也是。
>>>translations=awaittranslator.translate(['The quick brown fox','jumps over','the lazy dog'],dest='ko')>>>fortranslationintranslations:...print(translation.origin,' -> ',translation.text)# The quick brown fox -> 빠른 갈색 여우# jumps over -> 이상 점프# the lazy dog -> 게으른 개
googletrans作为命令行应用程序
$ translate -h usage: translate [-h][-d DEST][-s SRC][-c] text Python Google Translator as a command-line tool positional arguments: text The text you want to translate. optional arguments: -h, --help show this help message and exit -d DEST, --dest DEST The destination language you want to translate. (Default: en) -s SRC, --src SRC The source language you want to translate. (Default: auto) -c, --detect $ translate "veritas lux mea" -s la -d en [veritas] veritas lux mea -> [en] The truth is my light [pron.] The truth is my light $ translate -c "안녕하세요."[ko, 1] 안녕하세요.
库使用说明
-
一个文本上的最大字符限制是0。
- 由于google translate的web版本的限制,这个api 不能保证图书馆在任何时候都能正常工作。 (如果您不关心稳定性,请使用此库。)
- 如果你想使用一个稳定的api,我强烈建议你使用 Google’s official translate API。
- 如果出现http 5xx错误或类似于6的错误,可能是因为 谷歌已经禁止你的客户端IP地址。
版本控制
这个库从Semantic Versioning开始 2.0.0版。任何版本为0.x.y的版本都受向后不兼容的限制 随时更改。
提交拉取请求
对这个图书馆的贡献总是受到欢迎和高度鼓励的 :)
- 分叉此项目。
- 创建主题分支。
- 实现您的功能或错误修复。
- 运行pytest。
- 为您的功能或错误修复添加测试。
- 再次运行步骤4。如果您的更改没有100%覆盖,请返回 第五步。
- 提交并推送更改。
- 提交请求。
许可证
googletrans是根据麻省理工学院的许可证授权的。条款如下 如下:
The MIT License (MIT) Copyright (c) 2015 Simone Esposito Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.