免费的google python翻译api。完全免费翻译。

googletrans-temp的Python项目详细描述


GitHub licensetravis statusDocumentation StatusPyPI versionCoverage StatusCode Climate

googletrans是一个freeunlimitedpython库 实现了google翻译api。它使用Google Translate Ajax API来调用 检测并翻译。

与Python2.7+和3.4+兼容。(注意:Python2支持将在 下一个主要版本。)

有关详细信息,请参阅API Documentation

功能

  • 快速可靠-它使用的服务器与 translate.google.com使用
  • 自动语言检测
  • 批量翻译
  • 可自定义的服务URL
  • 连接池(使用requests.session的优势)
  • 支持http/2

待办事项

更多的功能即将推出。

  • 代理支持
  • 内部会话管理(用于更好的批量翻译)

支持http/2

这对每个人都很重要!(在我的测试中速度提高了2倍)如果 你想让googletrans更快你应该安装 hyper包装。谷歌将 自动检测是否安装了hyper,如果安装了hyper,将使用它 用于http网络。

这个库是如何工作的

你可能想知道为什么这个图书馆工作正常,而另一个 像goslate这样的方法是行不通的,因为google已经更新了它的 翻译服务最近有一个票务机制,防止了很多 爬虫程序。

我终于想出了一种反向生成票证的方法 在obfuscated and minified code used by Google to generate such token上的工程, 并在python之上实现。不过,这可能会在 任何时候。


安装

要安装,要么使用pip之类的软件包“googletrans” 或者下载软件包并将“googletrans”目录放入 python路径。无论如何,值得注意的是,这只需要两个 模块:请求和未来。

$ pip install googletrans

基本用法

如果没有给出源语言,google translate将尝试检测 源语言。

>>>fromgoogletransimportTranslator>>>translator=Translator()>>>translator.translate('안녕하세요.')# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>>>>translator.translate('안녕하세요.',dest='ja')# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>>>>translator.translate('veritas lux mea',src='la')# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>

自定义服务url

你可以使用另一个谷歌翻译域名进行翻译。如果是多重的 提供url,然后随机选择一个域。

>>>fromgoogletransimportTranslator>>>translator=Translator(service_urls=['translate.google.com','translate.google.co.kr',])

高级使用(批量)

数组可用于在单个方法中转换一批字符串 调用和单个http会话。与上述方法完全相同 对于数组也是。

>>>translations=translator.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  ->  게으른 개

语言检测

顾名思义,detect方法标识 一个给定的句子。

>>>fromgoogletransimportTranslator>>>translator=Translator()>>>translator.detect('이 문장은 한글로 쓰여졌습니다.')# <Detected lang=ko confidence=0.27041003>>>>translator.detect('この文章は日本語で書かれました。')# <Detected lang=ja confidence=0.64889508>>>>translator.detect('This sentence is written in English.')# <Detected lang=en confidence=0.22348526>>>>translator.detect('Tiu frazo estas skribita en Esperanto.')# <Detected lang=eo confidence=0.10538048>

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] 안녕하세요.

库使用说明

免责声明:这是一个使用translate.google.com的web api的非正式库 也与谷歌无关。

  • {STR 1 }:单个文本的最大字符限制为15K。< /强>
  • 由于google translate的web版本的限制,这个api 不能保证图书馆在任何时候都能正常工作 (所以如果你不关心稳定性,请使用这个库)。
  • 重要:如果您想使用稳定的api,我强烈建议您使用 Google’s official translate API
  • 如果出现http 5xx错误或类似于6的错误,可能是因为 谷歌已经禁止你的客户端IP地址。

版本控制

这个库跟随Semantic Versioning从 2.0.0版。任何版本为0.x.y的版本都受向后不兼容的限制 随时更改。

提交拉取请求

对这个图书馆的贡献总是受到欢迎和高度鼓励的 :)

  1. 分叉此项目。
  2. 创建主题分支。
  3. 实现您的功能或错误修复。
  4. 运行pytest
  5. 添加测试您的功能或错误修复。
  6. 再次运行步骤4。如果您的更改没有100%覆盖,请返回 第五步。
  7. 提交并推送更改。
  8. 提交请求。

许可证

googletrans是根据麻省理工学院的许可证授权的。条款如下 如下:

The MIT License (MIT)

Copyright (c) 2015 SuHun Han

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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何通过编程将图像插入Word文档?   java Maven在Quickstart原型中更改jUnit版本   OS X上的eclipse java版本和路径   java在hibernate中将具有依赖对象的类映射到单独的表   JavaJSF2如何在复合组件子组件完成操作后执行操作?   java无法从列表<节点>强制转换为列表<元素>   java如何将数组链接到方法   检查数组中是否存在一个范围内的所有值的最佳方法是什么?(爪哇)   redis Java:我们应该尽快退出trywithresource块来释放资源吗?   对象不会出现在java swing中的按键上   SQLServerJava。sql。SQLException:客户端尝试签出连接已超时   java如何使用JPA以线程安全的方式保存或更新对象?   java如何在不显示滚动条的情况下消除SWT ScrolledComposite中浪费的空间   如何在Eclipse中从Java编辑器显示scala文档?