本文整理汇总了Python中microsofttranslator.Translator.detect_language方法的典型用法代码示例。如果您正苦于以下问题:Python Translator.detect_language方法的具体用法?Python Translator.detect_language怎么用?Python Translator.detect_language使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类microsofttranslator.Translator
的用法示例。
在下文中一共展示了Translator.detect_language方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_translate_method
# 需要导入模块: from microsofttranslator import Translator [as 别名]
# 或者: from microsofttranslator.Translator import detect_language [as 别名]
def call_translate_method(self, text, from_language, to_language):
# This is supposed to be secret. I'm not really worried unless we distribute this thing.
translator = Translator("HypeBot", "6QvARrt7O0/JPsUeNRDeixHIGozNb6O7Gd5cFjFLjYU=")
if from_language == None:
from_language = translator.detect_language(text=text)
if to_language == None:
to_language = 'en' # Assume English
return translator.translate(text=text, to_lang=to_language, from_lang=from_language)
示例2: MSTranslator
# 需要导入模块: from microsofttranslator import Translator [as 别名]
# 或者: from microsofttranslator.Translator import detect_language [as 别名]
class MSTranslator():
def __init__(self, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret
self.translator = Translator(client_id, client_secret)
def detect(self, text):
code = self.translator.detect_language(text)
lang = Language(code)
return lang
def translate(self, text, target_lang="ja"):
translated_text = self.translator.translate(text, target_lang)
return translated_text
示例3: translate
# 需要导入模块: from microsofttranslator import Translator [as 别名]
# 或者: from microsofttranslator.Translator import detect_language [as 别名]
def translate():
#missingword = request.form['missingword']
#to_language = request.form['to_language']
missingword = 'envelope'
to_language = 'ja'
#from_language = request.form['from_language']
#翻訳
print '1step'
translator = Translator('skeven', 'vizaHdZEjZkP0ZdL/B3CQ0UO9yzsgmTT2hDtuvJFdL0=')
# from_languageは自動的に判別されるので指定する必要が無い
translated_word = translator.translate(missingword, to_language)
print '2step'
#translated_word = translator.translate("Hello", "ja")
# Registering Word to DB(CSV?)
languagetype = translator.detect_language(missingword)
print '3step'
inlinecsv = languagetype + '$YIN$' + missingword + '$YIN$' + to_language + "$YIN$" + translated_word + '\n'
print inlinecsv
f = open('./word/addinfo_dictionary_utf8.txt', 'a')
f.write(inlinecsv.encode('utf-8'))
f.close()
return translated_word;
示例4: test_detect_language
# 需要导入模块: from microsofttranslator import Translator [as 别名]
# 或者: from microsofttranslator.Translator import detect_language [as 别名]
def test_detect_language(self):
client = Translator(client_id, client_secret, debug=True)
self.assertEqual(client.detect_language('hello'), u'en')
示例5: translate
# 需要导入模块: from microsofttranslator import Translator [as 别名]
# 或者: from microsofttranslator.Translator import detect_language [as 别名]
def translate(text, to_language):
translator = Translator('butterknife', '8DWdIRK0yOdWalb3nLuOreETN0Eekpdo0VMITD3snJU=')
from_language = translator.detect_language(text)
output_text = translator.translate(text, to_language)
return json.jsonify(original=text, translated=output_text)