本文整理汇总了Python中translate.Translator方法的典型用法代码示例。如果您正苦于以下问题:Python translate.Translator方法的具体用法?Python translate.Translator怎么用?Python translate.Translator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类translate
的用法示例。
在下文中一共展示了translate.Translator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: translation
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def translation(cmd, message, args):
if args:
if len(args) >= 2:
trans_arg = args[0]
sentence = ' '.join(args[1:])
if '>' in trans_arg:
trans_split = trans_arg.split('>')
from_lang = trans_split[0].lower()
to_lang = trans_split[1].lower()
else:
from_lang = trans_arg
to_lang = 'en'
translator = translate.Translator(to_lang=to_lang, from_lang=from_lang)
trans_output = translator.translate(sentence)
title = f'?? Translated from {from_lang.upper()} to {to_lang.upper()}'
response = discord.Embed(color=0x3B88C3, title=title)
response.description = trans_output
else:
response = discord.Embed(color=0xBE1931, title='? Missing language or sentence.')
else:
response = discord.Embed(color=0xBE1931, title='? Nothing inputted.')
await message.channel.send(embed=response)
示例2: translate
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def translate(cmd, message, args):
if not args:
embed = discord.Embed(color=0xDB0000, title='? No Arguments Given')
else:
trans_qry = args[0]
if '>' not in trans_qry:
embed = discord.Embed(color=0xDB0000, title='? Invalid Translation Query')
else:
to_trans = ' '.join(args[1:])
from_lang, to_lang = trans_qry.split('>')
translator = trans.Translator(from_lang=from_lang, to_lang=to_lang)
transed = translator.translate(to_trans)
embed = discord.Embed(color=0x1abc9c, title='?? Translated')
embed.add_field(name=f'From {from_lang.upper()}', value=f'```\n{to_trans}\n```', inline=False)
embed.add_field(name=f'To {to_lang.upper()}', value=f'```\n{transed}\n```', inline=False)
await message.channel.send(None, embed=embed)
示例3: translate
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def translate(self, language, *text):
"""Translates text from English to specified language
**Use double quotes for each option**
**Dependencies**: pip install translate
(https://github.com/terryyin/google-translate-python)
Keyword arguments:
language -- Two-letter code for the languate to translate to
text -- Text to translate.
"""
text_to_string = ''.join(text)
translator = Translator(to_lang=language)
translation = translator.translate(text_to_string)
await self.bot.say(translation)
示例4: __init__
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def __init__(self, server_settings):
"""
Loads a translation model and initialises the webserver.
@param server_settings: see `settings.py`
"""
self._style = server_settings.style
self._host = server_settings.host
self._port = server_settings.port
self._threads = server_settings.threads
self._debug = server_settings.verbose
self._models = server_settings.models
self._num_processes = server_settings.num_processes
self._device_list = server_settings.device_list
self._status = self.STATUS_LOADING
# start webserver
self._server = Bottle()
self._server.config['logging.level'] = 'DEBUG' if server_settings.verbose else 'WARNING'
self._server.config['logging.format'] = '%(levelname)s: %(message)s'
self._server.install(LoggingPlugin(self._server.config))
logging.info("Starting Nematus Server")
# start translation workers
logging.info("Loading translation models")
self._translator = Translator(server_settings)
self._status = self.STATUS_OK
示例5: ts
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def ts(bot, update): # link above to import for more info
mess = str(update.message.text)
mess = mess.replace('/ts ','')
try:
translator = Translator(to_lang="it")
msg = translator.translate(mess)
ronf.sleep(0.4)
bot.sendMessage(chat_id=update.message.chat_id, text=msg)
except Exception as e:
bot.sendMessage(chat_id=update.message.chat_id, text="I can't read this thing!\n"+str(e))
示例6: __init__
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def __init__(self, resources):
self.translator = Translator()
self.resources = resources
示例7: trans
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def trans(ctx, *args):
"""Ex: '!trans en->de example' OR '!trans de Beispiel'"""
if "bugs" in args[0]:
await client.say("Wraith... bugs is not a language.")
return
if len(args[0]) == 2:
arr = [args[0], "en"]
else: arr = '{}'.format(args[0]).split('->')
t = Translator(from_lang=arr[0],to_lang=arr[1])
await client.say('```' + t.translate(" ".join(args[1:])) + '```')
# Image
示例8: ex
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def ex(dclient, channel, mention, a, cmd_char):
ar = a.split(' ')
if len(ar) >= 2:
lang_id = ar[0]
if lang_id.upper() in LANG_LIST:
s = a[3:]
t = Translator(to_lang=lang_id).translate(s)
await dclient.send_message(channel, t)
else:
await dclient.send_message(channel, 'Invalid language code input, `{}`! Please check <https://www.'
'sitepoint.com/web-foundations/iso-2-letter-language-codes/> '
'for correct language code, {}!'.format(lang_id, mention))
else:
await dclient.send_message(channel, '{}, **USAGE:** {}trans <language-code> <to-translate>'.format(mention,
cmd_char))
示例9: translate_zh_to_en
# 需要导入模块: import translate [as 别名]
# 或者: from translate import Translator [as 别名]
def translate_zh_to_en(content):
# from zh to en
translator= Translator(from_lang='zh',to_lang="en")
translation = translator.translate(content)
return translation