some translation things
This commit is contained in:
parent
d69ebc2516
commit
867e46e75d
|
@ -1,3 +1,4 @@
|
||||||
|
import time
|
||||||
import html
|
import html
|
||||||
import googletrans
|
import googletrans
|
||||||
from pyrogram import Client, filters
|
from pyrogram import Client, filters
|
||||||
|
@ -36,8 +37,17 @@ async def translate(client, message):
|
||||||
else:
|
else:
|
||||||
src_lang, dest_lang = lang
|
src_lang, dest_lang = lang
|
||||||
def _translate():
|
def _translate():
|
||||||
return googletrans.Translator().translate(text, src=src_lang, dest=dest_lang)
|
while True:
|
||||||
await message.reply_text((await client.loop.run_in_executor(None, _translate)).text, parse_mode=None)
|
try:
|
||||||
|
return googletrans.Translator().translate(text, src=src_lang, dest=dest_lang)
|
||||||
|
except AttributeError:
|
||||||
|
time.sleep(0.5)
|
||||||
|
result = await client.loop.run_in_executor(None, translate)
|
||||||
|
if result.text == text:
|
||||||
|
text = 'They\'re the same'
|
||||||
|
else:
|
||||||
|
text = f'Translated from {result.src} to {result.dest}:\n{result.text[:4000]}'
|
||||||
|
await message.reply_text(text, parse_mode=None)
|
||||||
|
|
||||||
help_dict['translate'] = ('Translate',
|
help_dict['translate'] = ('Translate',
|
||||||
'''{prefix}translate <i>(as reply to text)</i> <i>[src]-[dest]</i> - Translates text and stuff
|
'''{prefix}translate <i>(as reply to text)</i> <i>[src]-[dest]</i> - Translates text and stuff
|
||||||
|
|
Loading…
Reference in New Issue