forked from king04aman/All-In-One-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.py
More file actions
23 lines (19 loc) · 715 Bytes
/
translate.py
File metadata and controls
23 lines (19 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from tabulate import tabulate
from googletrans import Translator
class TranslateClass(object):
def __init__(self, word, lang):
self.word = word
self.lang = lang
self.Trans = Translator(service_urls=["translate.google.com"])
def __repr__(self):
translated = self.Trans.translate(self.word, dest=self.lang).text
data = [
['Language:', "Sentence"],
['English', self.word],
['Hindi', str(translated)]]
table = str(tabulate(data, headers="firstrow", tablefmt="grid"))
return table
if __name__ == '__main__':
translate = input('Enter Sentence: ')
language = 'hi'
print(TranslateClass(translate, language))