-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtranslator.py
More file actions
32 lines (25 loc) · 871 Bytes
/
translator.py
File metadata and controls
32 lines (25 loc) · 871 Bytes
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
#main file
from translate import Translator
from sys import argv, exit
try:
from_language = argv[1]
to_language = argv[2]
except IndexError as errr:
print ("No languages proivded!")
try:
with open("./original.txt", mode='r') as myfile:
text=(myfile.read())
except FileNotFoundError as er:
print("File not found!")
text="We could not find the file you wanted to translate!"
to_language = from_language
try:
translator=Translator(from_lang = from_language, to_lang=to_language)
translation=translator.translate(text)
except RuntimeError as err:
print("Unable to translate, please check availability of languages")
try:
with open("./translation.txt", mode='w') as output:
output.write(translation)
except FileNotFoundError as er:
print("File not found!")