Exemplo n.º 1
0
    def translate_text(self, text):
        if self.translator == "google":
            return ts.google(text, to_language=self.to_language)
        elif self.translator == "bing":
            return ts.bing(text, to_language=self.to_language)
        elif self.translator == "google_separate":
            return self.google_separate.translate(text=text, dest=self.to_language).text
        elif self.translator == "microsoft":
            params = {'appid': 'Bearer ' + self.token, 'text': text, 'to': self.to_language}

            requestHeader = {'Accept': 'application/xml'}

            responseResult = requests.get(self.translateUrl, params=params, headers=requestHeader)

            soup = BeautifulSoup(responseResult.text, "lxml")

            return colored(soup.get_text())

        elif self.translator == "sogou":
            return ts.sogou(text, to_language=self.to_language)
        elif self.translator == "baidu":
            return ts.baidu(text, to_language=self.to_language)
        elif self.translator == "alibaba":
            return ts.alibaba(text, to_language=self.to_language)
        elif self.translator == "tencent":
            return ts.tencent(text, to_language=self.to_language)
        elif self.translator == "youdao":
            return ts.youdao(text, to_language=self.to_language)
        elif self.translator == "deepl":
            return ts.deepl(text, to_language=self.to_language)
Exemplo n.º 2
0
	async def trg(self, ctx, tar= None, *, txt= None):
		if tar is None:
			embed = discord.Embed(title="**How to translate to Spanish:** \nUse ``!trg <your language> <text>``", color=discord.Color.red())
			embed.add_field(name="**Languages:**", value=f"``zh``: Chinese\n``en``: English\n``jp``: Japanese\n``fr``: French\n``it``: Italian\n``de``: German\n``tr``: Turkish\n``ru``: Russian\n``pt``: Portuguese")
			await ctx.send(embed=embed)
		elif txt is None:
			await ctx.send("You didn't specify any sentence or word to translate.")	
		else:
			r = ts.tencent(txt, f'{tar}', 'es')
			await ctx.send(f'{txt} **->** {r} | *{ctx.author}*')
Exemplo n.º 3
0
	async def tr(self, ctx, tar= None, *, txt= None):
		if tar is None:
			embed = discord.Embed(title="**Cómo traducir:** \nUse ``!tr <idioma al que vas a traducir> <texto o palabra>``", color=discord.Color.red())
			embed.add_field(name="**Idiomas:**", value=f"``zh``: Chino\n``en``: Inglés\n``jp``: Japonés\n``fr``: Francés\n``it``: Italiano\n``de``: Alemán\n``tr``: Turco\n``ru``: Ruso\n``pt``: Portugués")
			await ctx.send(embed=embed)
		elif txt is None:
			await ctx.send("Escribe algo para traducir.")	
		else:
			r = ts.tencent(txt, 'es', f'{tar}')
			await ctx.send(f'{txt} **->** {r} |*{ctx.author}*')
Exemplo n.º 4
0
def tencent_block(eng_qns):
    # translate the English question to Chinese using Youdao
    eng_chi_tencent = ts.tencent(eng_qns, 'en', 'zh-CN')
    # the list of questions translated from Chinese to English
    the_list = []
    # Google
    chi_eng_google = ts.google(eng_chi_tencent, 'zh', 'en')
    the_list.append(chi_eng_google)
    # Bing
    translator = Translator(from_lang="zh", to_lang="en")
    chi_eng_bing = translator.translate(eng_chi_tencent)
    the_list.append(chi_eng_bing)
    # Youdao
    chi_eng_youdao = ts.youdao(eng_chi_tencent, 'zh', 'en')
    the_list.append(chi_eng_youdao)
    # Tencent
    chi_eng_tencent = ts.tencent(eng_chi_tencent, 'zh', 'en')
    the_list.append(chi_eng_tencent)
    return the_list