The gods are silent-personal CSDN blog post directory
This article uses the unofficial library pygoogletranslation https://pypi.org/project/pygoogletranslation/
This library is directly used by the web API of Google Translate's official website, so the service is unreliable.
The amount of translations is unlimited.
Download method:pip install pygoogletranslation
env_path/lib/python3.6/site-packages/pygoogletranslation/utils.py
Line 8 needs to be changed to: from pygoogletranslation.models import TranslatedPart
1 (this seems to be a problem caused by moving from Python 2 to Python 3)
Call code:
from pygoogletranslation import Translator
proxy={
"http":"127.0.0.1:7890","https":"127.0.0.1:7890"}
translator=Translator(proxies=proxy)
t=translator.translate(query,dest='zh-CN')
print(t.text)
For the agent part, read my medium blog post. This is a slide that cannot be touched.
The input parameters of the translate function:
- query
- The language that can be accepted by input and output can
translator.glanguage()
be viewed through variables - src: input language,
auto
auto-detect language by default - dest
zh-CN
:Simplified Chinese
Other references used in writing this article: