From 51121fbd0bbe015fcdde718c8d45b58ae3424c34 Mon Sep 17 00:00:00 2001 From: Akash Jain Date: Mon, 3 Oct 2022 02:04:59 +0530 Subject: [PATCH] translate contents of txt file from one language to another Added --- scripts/file_translater/Readme.md | 7 +++++++ scripts/file_translater/trans.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 scripts/file_translater/Readme.md create mode 100644 scripts/file_translater/trans.py diff --git a/scripts/file_translater/Readme.md b/scripts/file_translater/Readme.md new file mode 100644 index 0000000..b854475 --- /dev/null +++ b/scripts/file_translater/Readme.md @@ -0,0 +1,7 @@ +# Adding a Automation Script to translate contents of txt file from one language to another + +## Usage + +- Clone the repo +- download the requirements +- run `python trans.py` diff --git a/scripts/file_translater/trans.py b/scripts/file_translater/trans.py new file mode 100644 index 0000000..6ee43f4 --- /dev/null +++ b/scripts/file_translater/trans.py @@ -0,0 +1,22 @@ +# 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 : ') +input_language = input('Input Your Translation Language : ') + +translation = translator.translate(data, dest=input_language) +print(translation.text) +f4.write(translation.text) +f4.close()