Initialize googletrans.Translator for every usage
This commit is contained in:
parent
0d87a789e0
commit
554a07cfbc
|
@ -4,7 +4,6 @@ from pyrogram import Client, filters
|
||||||
from .. import config, help_dict, log_errors, public_log_errors
|
from .. import config, help_dict, log_errors, public_log_errors
|
||||||
|
|
||||||
PROBLEM_CODES = set(i for i in googletrans.LANGUAGES if '-' in i)
|
PROBLEM_CODES = set(i for i in googletrans.LANGUAGES if '-' in i)
|
||||||
translator = googletrans.Translator()
|
|
||||||
|
|
||||||
@Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['tr', 'translate'], prefixes=config['config']['prefixes']))
|
@Client.on_message(~filters.sticker & ~filters.via_bot & ~filters.edited & filters.me & filters.command(['tr', 'translate'], prefixes=config['config']['prefixes']))
|
||||||
@log_errors
|
@log_errors
|
||||||
|
@ -37,7 +36,7 @@ async def translate(client, message):
|
||||||
else:
|
else:
|
||||||
src_lang, dest_lang = lang
|
src_lang, dest_lang = lang
|
||||||
def _translate():
|
def _translate():
|
||||||
return translator.translate(text, src=src_lang, dest=dest_lang)
|
return googletrans.Translator().translate(text, src=src_lang, dest=dest_lang)
|
||||||
await message.reply_text((await client.loop.run_in_executor(None, _translate)).text, parse_mode=None)
|
await message.reply_text((await client.loop.run_in_executor(None, _translate)).text, parse_mode=None)
|
||||||
|
|
||||||
help_dict['translate'] = ('Translate',
|
help_dict['translate'] = ('Translate',
|
||||||
|
|
Loading…
Reference in New Issue