python中英文翻译模块

从一种语言到另一种语言的文本翻译在各种网站中越来越普遍。 帮助我们执行此操作的python包称为translate。
可以通过以下方式安装此软件包。 它提供主要语言的翻译。

官网:https://pypi.org/project/translate/

安装

   pip install translate
  • 1

使用方法:

# encoding: utf-8

from translate import Translator


# 以下是将简单句子从英语翻译中文
translator= Translator(to_lang="chinese")
translation = translator.translate("Good night!")
print translation


# 在任何两种语言之间,中文翻译成英文
translator= Translator(from_lang="chinese",to_lang="english")
translation = translator.translate("我想你")
print translation
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
D:\Python27\python.exe F:/PycharmProjects/tom/文本翻译功能.py
晚安!
I missed you.

Process finished with exit code 0
  • 1
  • 2
  • 3
  • 4
  • 5

果然牛逼啊

猜你喜欢

转载自www.cnblogs.com/gaidy/p/10815177.html
今日推荐