- 库名:pygtrans–python google translate
- 检测待翻译字符串的类型,中文翻译成英文,英文翻译成中文
from pygtrans import Translate
client = Translate()
Question = '你好'
laguage = client.detect(Question).language ## 检测语言
if laguage == 'zh-CN':
## 将中文翻译成英文
Question = client.translate(Question, target='en')
Question = Question.translatedText ## str类型
## 将英文翻译成中文
text = client.translate(Question)
anwser = text.translatedText ## str类型