本文整理汇总了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")
示例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