Skip to main content

Google Translate, support APIKEY

Project description

pygtrans

谷歌翻译, 支持 APIKEY

Downloads

安装

pip install -U pygtrans

基本功能

  • 获取语言支持列表
  • 自动检测语言, 支持批量
  • 文本/HTML 翻译, 支持批量
  • 支持 TTS

快速入门

from pygtrans import Translate

client = Translate(proxies={'https': 'http://localhost:10809'})

# 检测语言
text = client.detect('Answer the question.')
assert text.language == 'en'

# 翻译句子
text = client.translate('Look at these pictures and answer the questions.')
assert text.translatedText == '看这些图片,回答问题。'

# 批量翻译
texts = client.translate([
    'Good morning. What can I do for you?',
    'Read aloud and underline the sentences about booking a flight.',
    'May I have your name and telephone number?'
])
assert [text.translatedText for text in texts] == [
    '早上好。我能为你做什么?',
    '大声朗读并在有关预订航班的句子下划线。',
    '可以给我你的名字和电话号码吗?'
]

# 翻译到日语
text = client.translate('请多多指教', target='ja')
assert text.translatedText == 'お知らせ下さい'

# 翻译到韩语
text = client.translate('请多多指教', target='ko')
assert text.translatedText == '조언 부탁드립니다'

# 文本到语音
tts = client.tts('やめて', target='ja')
open('やめて.mp3', 'wb').write(tts)

最佳实践

  1. pygtrans中包含两个翻译模块
    1. Translate:
      • 完全免费,支持批量
      • 从2021年9月15日开始, 需要翻墙才能使用, 具体参考 #8
    2. ApiKeyTranslate: 需要有效的谷歌翻译 API KEY谷歌提供免费试用
  2. Translate的最佳实践:
    1. 准备好代理VPN,建议 v2rayN https://github.com/2dust/v2rayN
    2. 使用 clash 进行代理,将会导致失败,参考 #13
    3. 建议不要打开全局代理
    4. http example:Translate(proxies={"https": "http://localhost:10809"})
    5. socks5 example: Translate(proxies={"https": "socks5://localhost:10808"})
    6. 重要:尽量一次性多翻译,减少请求次数,参考 #13
    7. 重要:尽量一次性多翻译,减少请求次数,参考 #13
    8. 重要:尽量一次性多翻译,减少请求次数,参考 #13

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygtrans-1.2.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

pygtrans-1.2.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file pygtrans-1.2.0.tar.gz.

File metadata

  • Download URL: pygtrans-1.2.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pygtrans-1.2.0.tar.gz
Algorithm Hash digest
SHA256 49f9e6b9b093c240b01f44d0c69f6d8519571256916fc78eaee211b4f16fb4d8
MD5 986d27c870c1d70e578abbdfeeb818b7
BLAKE2b-256 bbfc9ec187d0ef2fe5e53afed9dbacf12bc08cfe3d99d41c62c7549db09274b8

See more details on using hashes here.

File details

Details for the file pygtrans-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pygtrans-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pygtrans-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5acb8f1a33f718e52a469d92ad8b54a5d1fe5b78bb3a20da3fca585c246e7783
MD5 5e110e7172e8a066dbb6116c941fbcd9
BLAKE2b-256 eb70aa7b490a0946a2d9c912165ec9e945d4274e79f5b38585a1fc215a8d3437

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page