from gpytranslate import SyncTranslator from pyrogram import * from pyrogram.types import * from config import * trans = SyncTranslator() @Client.on_message( ~filters.scheduled & filters.command(["tr"]) & ~filters.forwarded ) async def translate(_, message: Message): global to_translate reply_msg = message.reply_to_message if not reply_msg: await message.reply_text("Reply to a message to translate it!") return if reply_msg.caption: to_translate = reply_msg.caption elif reply_msg.text: to_translate = reply_msg.text try: args = message.text.split()[1].lower() if "//" in args: source = args.split("//")[0] dest = args.split("//")[1] else: source = trans.detect(to_translate) dest = args except IndexError: source = trans.detect(to_translate) dest = "en" translation = trans(to_translate, sourcelang=source, targetlang=dest) reply = "" reply += f"Translated from {source} to {dest}:\n" reply += f"{translation.text}\n" try: await message.reply_text(reply) except Exception as e: await message.reply_text(f"Error : {e}")