Google Translate, support APIKEY
Project description
pygtrans
谷歌翻译, 支持 APIKEY
安装
pip install -U pygtrans
pip install git+ssh://git@github.com/foyoux/pygtrans.git
pip install git+https://github.com/foyoux/pygtrans.git
基本功能
- 获取语言支持列表
- 自动检测语言, 支持批量
- 文本/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)
最佳实践
pygtrans
中包含两个翻译模块Translate
的最佳实践:http
代理:Translate(proxies={"https": "http://localhost:10809"})
socks5
代理:Translate(proxies={"https": "socks5://localhost:10808"})
- 重要:尽量一次性多翻译,减少请求次数,参考 #13,比如一次性翻译 2000 / 5000 / 10000
Project details
Release history Release notifications | RSS feed
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.5.2.tar.gz
(22.8 kB
view details)
Built Distribution
pygtrans-1.5.2-py3-none-any.whl
(23.8 kB
view details)
File details
Details for the file pygtrans-1.5.2.tar.gz
.
File metadata
- Download URL: pygtrans-1.5.2.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
5884b97ff654ecdd50aa9c59b1d7b87f12da37f45406b880d1059b2ee5e186f0
|
|
MD5 |
f32297c2c08d59e490dfdfc5e9c644a8
|
|
BLAKE2b-256 |
e399bf88558c430d9f066d9d703b36d8756f463048513ec4db2f0f18a04aa418
|
File details
Details for the file pygtrans-1.5.2-py3-none-any.whl
.
File metadata
- Download URL: pygtrans-1.5.2-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
082e10c0dbd17cb4ae42288638fad1c14ed4d85a636d8605d97709b8e4efbe62
|
|
MD5 |
bd1dabc749ed7f7a9193b8c1d71c5e07
|
|
BLAKE2b-256 |
26cf84552718e3e8ac6d0ad76e12cb2fe6e49087727956f236c0df8570222f0a
|