forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonal_translator.py
50 lines (31 loc) · 1.34 KB
/
personal_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
# -*- coding: utf-8 -*-
"""Personal_translator.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1lHb0mCvF6Ie3QaTt3VfqlNjNs6vuV5qJ
"""
# uncomment the line to intall googletrans library
# ! pip install googletrans
from googletrans import Translator
# make a simple function that will translate any language to english
def text_translator(Text):
translator = Translator()
translated = translator.translate(Text, dest="en")
return translated.text
text_translator(
"Cidades brasileiras integram programa de preservação de florestas"
) # portuguese to english
text_translator("Guten Morgen, wie gehts?") # german to english
text_translator("Ami tumake bhalobashi") # bengali to english
text_translator("ਮੈਨੂੰ ਇੱਕ ਗੱਲ ਦੱਸੋ") # punjabi to english
text_translator("I am fine") # english text remains constant
def eng2punj_translator(Text): # english to punjabi translator
translator = Translator()
translated = translator.translate(Text, dest="pa")
return translated.text
eng2punj_translator("Meet you soon")
def eng2beng_translator(Text): # english to bengali translator
translator = Translator()
translated = translator.translate(Text, dest="bn")
return translated.text
eng2beng_translator("So happy to see you")