当前位置: 首页>>代码示例>>Python>>正文


Python Translator.to_lang方法代码示例

本文整理汇总了Python中translate.Translator.to_lang方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.to_lang方法的具体用法?Python Translator.to_lang怎么用?Python Translator.to_lang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在translate.Translator的用法示例。


在下文中一共展示了Translator.to_lang方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doTranslate

# 需要导入模块: from translate import Translator [as 别名]
# 或者: from translate.Translator import to_lang [as 别名]
    def doTranslate(self):
        openDirName = self.getOpenFileName()
        trans = Translator(to_lang="ko")
        trans.from_lang = self.lang_code[str(self.cb_fromLang.currentText())]
        self.label.setText("Under translating")
        for langCode in self.lang_code.keys():
            try:
                writeFile = open(openDirName+"\\"+langCode+"_"+self.originalFileName,'w')
                transResult=''
                trans.to_lang = self.lang_code[langCode]
                for line in self.readText:
                    try:
                        transResult += trans.translate(line).encode('utf-8')+"\n"
                    except:
                        transResult += trans.translate(line)+'\n'
                writeFile.write(transResult)
                writeFile.close()
            except:
                print langCode
                print self.readText
                break

        self.label.setText("Working done")
开发者ID:HeesangLee,项目名称:GoogleTranslate,代码行数:25,代码来源:GoogleTranslate.py

示例2: Translator

# 需要导入模块: from translate import Translator [as 别名]
# 或者: from translate.Translator import to_lang [as 别名]
#make sure you have already downloaded the module we will be using, i.e.
# use the terminal or cmd.exe if you're on windows and type
# pip install translate
from translate import Translator
abbreviations = {"Chinese": "zh",
                "Russian": "ru",
                "German": "de",
                "French": "fr",
                "Japanese": "ja",
                "Korean": "ko",
                "Dutch": "nl",
                "Hindi": "hi",
                "Arabic": "ar",
                "Tamil": "ta"}
toGerman = Translator(to_lang=abbreviations["German"])
toFrench = Translator(to_lang=abbreviations["French"])
toKorean = Translator(to_lang=abbreviations["Korean"])
# make one for another one of the languages above
# better yet, search for another language abbreviation, add it to our dictionary, and translate for that language
toGerman.translate("Hi")
toFrench.translate("Hi")
toKorean.translate("Hi")

testTranslator = Translator(to_lang="en")
message = unicode("The day is young")
for abbrev in abbreviations:
    testTranslator.to_lang = abbreviations[abbrev]
    temp = testTranslator.translate('%s'%message)
    quotedMessage = "\"" + message + "\""
    print "A rough translation of", quotedMessage, "in", abbrev, "is", temp
开发者ID:utkpython,项目名称:utkpython.github.io,代码行数:32,代码来源:googleTranslate.py


注:本文中的translate.Translator.to_lang方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。