Python编写的微型Google Translate API包装器。
项目描述
Python编写的微型Google Translate API包装器。使用此API需要API密钥。有关获取API密钥的更多信息,请参阅Google Translate API网站。
支持的所有语言列表。
用法
安装:pip install pygtaw。
识别您的API密钥并创建一个新的Client对象。
>>> import pygtaw
>>> api_key = 'ENTER_API_KEY'
>>> client = pygtaw.Client(api_key)
进行翻译请求
>>> query = 'Hello, world!'
>>> target = 'Korean'
>>> source = 'English'
>>> translation = client.translate(query, target, source)
>>>
>>> print translation.translated_text
안녕하세요
您也可以发送不带源的语言的翻译请求–Google Translate API可以检测源语言
>>> translation = client.translate('Hello', target='Spanish')
>>> print translation.translated_text
Hola
>>> print translation.detected_source_language
English
测试
目前,测试是通过向Google Translate API发送请求来进行的。要运行测试,请确保在测试文件夹中创建一个键文件并在.gitignore中添加它。
项目详情
关闭
pygtaw-0.0.9.tar.gz的散列
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d354d7fe0146f4fa8f5a80ce324148499b4c5588c8ed40e6a7eb64d1bce41ba9 |
|
MD5 | 39fc1fee51a0a0e26e4e6ccca9320b1b |
|
BLAKE2b-256 | 421a7876ded6bcc0ebfe41989ab11f638fc8428c1f0dadf97d27fffc43080c94 |