-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
88 lines (74 loc) · 2.99 KB
/
main.py
File metadata and controls
88 lines (74 loc) · 2.99 KB
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
80
81
82
83
84
85
86
87
88
import asyncio
import time
from colorama import init, Fore, Back, Style
from googletrans import Translator
from utils import type_print, type_print_lines, build_language_list
from languages import LANGUAGES
init(autoreset=True)
translator = Translator()
def big_intro():
ascii_art = r"""
███╗ ██╗██╗ ██╗██╗ ██╗
████╗ ██║██║ ██║██║ ██║
██╔██╗ ██║██║ ██║██║ ██║
██║╚██╗██║██║ ██║██║ ██║
██║ ╚████║╚██████╔╝███████╗███████╗
╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚══════╝
"""
created_by = "CREATED_BY t.me/theeeraven"
type_print(ascii_art, delay=0.001, fore=Fore.MAGENTA)
type_print(created_by.center(60), delay=0.05, fore=Fore.CYAN)
print("\n")
time.sleep(0.5)
def program_intro():
type_print("Welcome to Python Translator!", delay=0.05, fore=Fore.YELLOW)
type_print("Translate any text between multiple languages.", delay=0.03, fore=Fore.YELLOW)
type_print("Enjoy colorful terminal output and interactive menus!", delay=0.03, fore=Fore.YELLOW)
print("\n")
time.sleep(0.5)
async def translate_text(text, dest):
try:
result = await translator.translate(text, dest=dest)
return result.text
except Exception as e:
return f"[ERROR] {e}"
async def translation_menu():
while True:
type_print("Enter text to translate (or 'b' to go back):", 0.05, Fore.GREEN, Back.RED)
user_input = input(Fore.GREEN).strip()
if user_input.lower() == 'b':
break
type_print("Enter target language code:", 0.05, Fore.GREEN, Back.RED)
dest = input(Fore.GREEN).strip()
if dest not in LANGUAGES:
print(Fore.RED + "Invalid language code! Try again.")
continue
translated = await translate_text(user_input, dest)
print(Back.GREEN + Fore.YELLOW + "Translated text:" + Style.RESET_ALL)
print(Back.RED + Fore.YELLOW + translated)
print()
async def main_menu():
lang_text = build_language_list(LANGUAGES)
type_print("Available languages:", 0.05, Fore.RED, Back.GREEN)
type_print_lines(lang_text)
while True:
type_print("Main Menu:", 0.05, Fore.CYAN, Back.BLACK)
print(Fore.YELLOW + "[1] Start Translation")
print(Fore.YELLOW + "[0] Exit")
choice = input(Fore.GREEN + "Enter choice: ").strip()
if choice == '1':
await translation_menu()
elif choice == '0':
print(Fore.CYAN + "Exiting program. Bye 👋")
break
else:
print(Fore.RED + "Invalid choice. Try again.")
async def main():
big_intro()
program_intro()
await main_menu()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nBye 👋")