2022-10-02 20:34:59 +00:00
|
|
|
import googletrans
|
|
|
|
from googletrans import *
|
|
|
|
|
|
|
|
translator = googletrans.Translator()
|
|
|
|
|
|
|
|
f1 = input("Enter source file (with .txt extension)")
|
2022-10-05 13:38:37 +00:00
|
|
|
|
|
|
|
data = None
|
|
|
|
|
|
|
|
# f2 is the file object which reads the source file
|
|
|
|
with open(f1, encoding="utf8") as f2:
|
|
|
|
data = f2.read()
|
|
|
|
|
2022-10-02 20:34:59 +00:00
|
|
|
f3 = input("Enter destination file (with .txt extension)")
|
|
|
|
|
2022-10-05 13:38:37 +00:00
|
|
|
# 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 : ')
|
2022-10-02 20:34:59 +00:00
|
|
|
|
2022-10-05 13:38:37 +00:00
|
|
|
translation = translator.translate(data, dest=input_language)
|
|
|
|
print(translation.text)
|
|
|
|
f4.write(translation.text)
|