-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
62 lines (37 loc) · 1.09 KB
/
translate.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
import sys
import requests
import re
from googletrans import Translator
from googletrans import LANGUAGES
#
search = sys.argv[1:]
if len(search)!=2:
print("Please enter valid inputs")
exit()
# print(len(search))
# print(sys.argv[1])
words=re.sub(r"[^\w\s]", '',sys.argv[1])
# print(words)
# print(words)
destination=sys.argv[2]
LANGCODES = dict(map(reversed, LANGUAGES.items()))
translator = Translator()
if (destination not in LANGCODES.keys()):
print('No Language Found, Please Clarify')
exit()
# print(LANGCODES.keys())
# regex=re.sub('[.,()0-9:;]+', '', words)
# # print(regex)
# LANGCODES = dict(map(reversed, LANGUAGES.items()))
# translator = Translator()
new=translator.translate(words, destination)
print(new.text)
# def translate(thisText, destn):
# translator.translate(thisText, dest=destn)
# newWords=translator.translate(words)
# return newWords.text
# print(translate(words, destination))
# print(translate('hey'))
# print(translate('bonjour'))
# print(LANGCODES)
# n=translator.translate('bonjour moi')