-
Notifications
You must be signed in to change notification settings - Fork 22
/
translator.py
79 lines (70 loc) · 3.06 KB
/
translator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# TODO
# WARNING! IT COMMENTED FULLY SINCE INSTALL PACKAGES FROM THIS MODULE WILL
# BROKE ALL FUCKING DRAGON, NOT JUST THIS MODULE
# THIS MODULE IS INCOMPATIBLE WITH LAST DRAGON VERSION
# SINCE IT USE OUTDATED PACKAGE WITH BROKEN DEPENDENCIES
# IT NEEDS TO BE REWRITED
# from utils.scripts import import_library
# from utils.misc import modules_help, prefix
# from pyrogram import Client, filters
# googletrans = import_library("googletrans", "googletrans==4.0.0rc1")
# from googletrans import Translator
# trl = Translator()
# @Client.on_message(filters.command(["tr", "trans"], prefix) & filters.me)
# async def translate(_client, message):
# await message.edit_text("<b>Translating text...</b>")
# if message.reply_to_message and (
# message.reply_to_message.text or message.reply_to_message.caption
# ):
# if len(message.text.split()) == 1:
# await message.edit(
# f"<b>Usage: Reply to a message, then <code>{prefix}tr [lang]*</code></b>"
# )
# return
# target = message.text.split()[1]
# if message.reply_to_message.text:
# text = message.reply_to_message.text
# else:
# text = message.reply_to_message.caption
# detectlang = trl.detect(text)
# try:
# tekstr = trl.translate(text, dest=target)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit(
# "<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
# detectlang.lang, target, tekstr.text
# )
# )
# else:
# if len(message.text.split()) <= 2:
# await message.edit(f"<b>Usage: <code>{prefix}tr [lang]* [text]*</code></b>")
# return
# target = message.text.split(None, 2)[1]
# text = message.text.split(None, 2)[2]
# detectlang = trl.detect(text)
# try:
# tekstr = trl.translate(text, dest=target)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit(
# "<b>Translated from <code>{}</code> to <code>{}</code></b>:\n\n<code>{}</code>".format(
# detectlang.lang, target, tekstr.text
# )
# )
# @Client.on_message(filters.command(["transdl", "trdl"], prefix) & filters.me)
# async def translatedl(_client, message):
# dtarget = message.text.split(None, 2)[1]
# dtext = message.text.split(None, 2)[2]
# try:
# dtekstr = trl.translate(dtext, dest=dtarget)
# except ValueError as err:
# await message.edit("Error: <code>{}</code>".format(str(err)))
# return
# await message.edit("{}".format(dtekstr.text))
# modules_help["translator"] = {
# "tr": "[lang]* [text/reply]* translate message",
# "trdl": f"[lang]* [your text]* short variant of {prefix}tr",
# }