Python文本处理

文本翻译

文本翻译详细操作教程
从一种语言到另一种语言的文本翻译在各种网站中越来越普遍。 帮助我们执行此操作的python包称为translate。
可以通过以下方式安装此软件包。 它提供主要语言的翻译。
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-23
pip install translate
以下是将简单句子从英语翻译成德语的示例。语言的默认值为英语。
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-23
from translate import Translator
translator= Translator(to_lang="German")
translation = translator.translate("Good Morning!")
print translation
当运行上面的程序时,我们得到以下输出 -
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-23
Guten Morgen!
在任何两种语言之间
如果需要指定from-language和to-language,那么参考下面的程序中指定它。
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-23
from translate import Translator
translator= Translator(from_lang="german",to_lang="spanish")
translation = translator.translate("Guten Morgen")
print translation
执行上面示例代码,得到以下结果 -
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-23
Buenos días
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4