Merge pull request #151 from Icelain/patch-1

made code quality improvements to the file_translater script
This commit is contained in:
Advaita Saha 2022-10-05 21:59:50 +05:30 committed by GitHub
commit e5680e817f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,22 +1,23 @@
# Imports
import googletrans
from googletrans import *
translator = googletrans.Translator()
f1 = input("Enter source file (with .txt extension)")
f2 = open(f1, encoding="utf8")
data = f2.read()
# print(data)
f3 = input("Enter destination file (with .txt extension)")
f4 = open(f3, encoding="utf8", mode="w")
f2.close()
# input_text = input('Input Your Translation Text : ')
data = None
# f2 is the file object which reads the source file
with open(f1, encoding="utf8") as f2:
data = f2.read()
f3 = input("Enter destination file (with .txt extension)")
# f4 is the file object which writes to the output file
with open(f3, encoding="utf8", mode="w") as f4:
input_language = input('Input Your Translation Language : ')
translation = translator.translate(data, dest=input_language)
print(translation.text)
f4.write(translation.text)
f4.close()