python中翻译功能translate模块实现方法


Posted in Python onDecember 17, 2020

现如今,各个国家交流密切,通过翻译使我们打破了语言壁垒,而翻译在互联网上的存在也尤为普遍。python中执行翻译操作的包是translate包,通过下载安装translate包,使用translate模块可以在python中实现多种语言直接的相互翻译。

1、下载translate包

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

2、使用pip安装translate包

pip install translate

3、使用translate模块实现翻译功能

from translate import Translator
def translate_content_ch():
  # 实现英文转中文
  translator=Translator(to_lang='chinese')
  translation=translator.translate('hello')
  return translation
def translate_content_en():
#实现中文转英文
  translator=Translator(from_lang='chinese',to_lang='english')
  translation=translator.translate('你好')
  return translation

Python translate()方法补充实例

先按照转换表的替换出新的 string,然后再执行 del 参数的替换,有个先后顺序:

# -*- coding:utf-8 -*-
from string import maketrans

intab = 'aeiou'
outtab = '12345'
str1 = 'i am a example string for test! wow...!!!'

print "str1:",str1
print "intab:",intab
print "outtab:",outtab

transtab = maketrans(intab,outtab)

print "str1.translate(translate(intab,outtab)):"
print str1.translate(transtab)

print "str1.translate(translate(intab,outtab),'x1'):"
print str1.translate(transtab,'x1')

输出结果为:

str1: i am a example string for test! wow...!!!
intab: aeiou
outtab: 12345
str1.translate(translate(intab,outtab)):
3 1m 1 2x1mpl2 str3ng f4r t2st! w4w...!!!
str1.translate(translate(intab,outtab),'x1'):
3 1m 1 21mpl2 str3ng f4r t2st! w4w...!!!

到此这篇关于python中翻译功能translate模块实现方法的文章就介绍到这了,更多相关python中翻译功能translate模块如何实现内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Python 相关文章推荐
Python使用SocketServer模块编写基本服务器程序的教程
Jul 12 Python
Python实现简单的获取图片爬虫功能示例
Jul 12 Python
django文档学习之applications使用详解
Jan 29 Python
Python读取excel指定列生成指定sql脚本的方法
Nov 28 Python
Python IDE Pycharm中的快捷键列表用法
Aug 08 Python
python函数装饰器之带参数的函数和带参数的装饰器用法示例
Nov 06 Python
Pandas数据离散化原理及实例解析
Nov 16 Python
解决Python二维数组赋值问题
Nov 28 Python
解决import tensorflow as tf 出错的原因
Apr 16 Python
python连接mysql数据库并读取数据的实现
Sep 25 Python
python numpy中multiply与*及matul 的区别说明
May 26 Python
解决pycharm下载库时出现Failed to install package的问题
Sep 04 Python
python中count函数知识点浅析
Dec 17 #Python
Python 使用SFTP和FTP实现对服务器的文件下载功能
Dec 17 #Python
python爬虫利器之requests库的用法(超全面的爬取网页案例)
Dec 17 #Python
python使用smtplib模块发送邮件
Dec 17 #Python
python实现计算器简易版
Dec 17 #Python
利用Python实现自动扫雷小脚本
Dec 17 #Python
用python读取xlsx文件
Dec 17 #Python
You might like
php 智能404跳转代码,适合换域名没改变目录的网站
2010/06/04 PHP
php中判断数组是一维,二维,还是多维的解决方法
2013/05/04 PHP
在PHP中设置、使用、删除Cookie的解决方法
2013/05/06 PHP
使用php实现快钱支付功能(涉及到接口)
2013/07/01 PHP
php获取远程文件的内容和大小
2015/11/03 PHP
php socket通信(tcp/udp)实例分析
2016/02/14 PHP
PHP加密技术的简单实现
2016/09/04 PHP
jQuery中live方法的重复绑定说明
2011/10/21 Javascript
自己封装的常用javascript函数分享
2015/01/07 Javascript
JS表的模拟方法
2015/02/05 Javascript
jQuery实现复选框成对选择及对应取消的方法
2015/03/03 Javascript
Bootstrap实现响应式导航栏效果
2015/12/28 Javascript
最常见的左侧分类菜单栏jQuery实现代码
2016/11/28 Javascript
微信小程序 底部导航栏目开发资料
2016/12/05 Javascript
Angular.Js中过滤器filter与自定义过滤器filter实例详解
2017/05/08 Javascript
js评分组件使用详解
2017/06/06 Javascript
详解Vue打包优化之code spliting
2018/04/09 Javascript
小程序跳转H5页面的方法步骤
2020/03/06 Javascript
原生javascript如何实现共享onload事件
2020/07/03 Javascript
[01:28:44]DOTA2-DPC中国联赛定级赛 RNG vs iG BO3第一场 1月10日
2021/03/11 DOTA
python生成随机mac地址的方法
2015/03/16 Python
在Python中操作字典之clear()方法的使用
2015/05/21 Python
python感知机实现代码
2019/01/18 Python
python处理DICOM并计算三维模型体积
2019/02/26 Python
django使用haystack调用Elasticsearch实现索引搜索
2019/07/24 Python
详解Python中的正斜杠与反斜杠
2019/08/09 Python
用Python去除图像的黑色或白色背景实例
2019/12/12 Python
详解Python3中的 input() 函数
2020/03/18 Python
Python实现自动打开电脑应用的示例代码
2020/04/17 Python
selenium自动化测试入门实战
2020/12/21 Python
浅谈CSS3动画的回调处理
2016/07/21 HTML / CSS
拥有超过850家商店的美国在线派对商店:Party City
2018/10/21 全球购物
2014年大学庆元旦迎新年活动方案
2014/03/09 职场文书
525心理活动总结
2014/07/04 职场文书
教育系统干部作风整顿心得体会
2014/09/09 职场文书
习近平在党的群众路线教育实践活动总结大会上的讲话全文
2014/10/25 职场文书