當前位置: 首頁>>代碼示例>>Python>>正文


Python translate.Translator方法代碼示例

本文整理匯總了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) 
開發者ID:lu-ci,項目名稱:apex-sigma-core,代碼行數:24,代碼來源:translation.py

示例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) 
開發者ID:lu-ci,項目名稱:apex-sigma,代碼行數:18,代碼來源:translate.py

示例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) 
開發者ID:PythonBuddies,項目名稱:main_bot,代碼行數:20,代碼來源:chat.py

示例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 
開發者ID:EdinburghNLP,項目名稱:nematus,代碼行數:27,代碼來源:server.py

示例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)) 
開發者ID:Oples,項目名稱:Telegram-bot-test,代碼行數:12,代碼來源:TelegramShy.py

示例6: __init__

# 需要導入模塊: import translate [as 別名]
# 或者: from translate import Translator [as 別名]
def __init__(self, resources):
        self.translator = Translator()
        self.resources = resources 
開發者ID:MemeTrash,項目名稱:DogeGen,代碼行數:5,代碼來源:main.py

示例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 
開發者ID:MitchWeaver,項目名稱:DisKvlt-Bot,代碼行數:15,代碼來源:bot.py

示例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)) 
開發者ID:Atomicbeast101,項目名稱:jinux-discord,代碼行數:17,代碼來源:trans.py

示例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 
開發者ID:wwj718,項目名稱:paperweekly_forum,代碼行數:7,代碼來源:qa_bot.py


注:本文中的translate.Translator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。