diff --git a/pagermaid/modules/external.py b/pagermaid/modules/external.py index 97a79a2..aa8a1ee 100644 --- a/pagermaid/modules/external.py +++ b/pagermaid/modules/external.py @@ -1,14 +1,11 @@ """ PagerMaid features that uses external HTTP APIs other than Telegram. """ -import translators as ts from os import remove from magic_google import MagicGoogle from gtts import gTTS from gtts.tts import gTTSError from re import compile as regex_compile -from translators.apis import TranslatorError - from pagermaid import log, silent from pagermaid.listener import listener, config from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang, alias_command @@ -34,7 +31,13 @@ async def translate(context): if not silent: await context.edit(lang('translate_processing')) try: - result = ts.google(source_text, to_language=ap_lang.replace("zh-cn", "zh-CN")) + from translators.apis import TranslatorError + from translators import google + except ModuleNotFoundError: + await context.edit(lang('translate_ImportError')) + return + try: + result = google(source_text, to_language=ap_lang.replace("zh-cn", "zh-CN")) except TranslatorError: return await context.edit(lang('translate_ValueError')) except ValueError: