• 技术文章 >常见问题 >Python常见问题

    python中翻译功能translate模块

    宋雪维宋雪维2021-04-07 17:35:51原创10083

    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模块实现翻译功能的过程,希望能对你有所帮助哟~

    (推荐操作系统:windows7系统、Python 3.9.1,DELL G3电脑。)

    专题推荐:pythontranslate模块
    品易云
    上一篇:python中random模块常见函数有哪几种? 下一篇:python中unicode编码转换为中文

    相关文章推荐

    • python len()函数的功能是什么?• python中round函数具体使用详解• 如何使用python random模块中的randint()函数?• 理解python中的random.choice()• python中random模块将列表内容打乱• python中random模块常见函数有哪几种?• python中count函数是什么意思?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网