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


Python Translator.detect_language方法代码示例

本文整理汇总了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)
开发者ID:JeffBorwey,项目名称:HypeBot,代码行数:10,代码来源:TranslateHandler.py

示例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
开发者ID:tominaga443,项目名称:globalbot,代码行数:17,代码来源:mstranslator.py

示例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;
开发者ID:ShoSekine,项目名称:HONYAC,代码行数:26,代码来源:fileuploader.py

示例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')
开发者ID:kz20,项目名称:Microsoft-Translator-Python-API,代码行数:5,代码来源:test.py

示例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)
开发者ID:jpbreuer,项目名称:Butterknife-Serverside,代码行数:8,代码来源:translator.py


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