diff --git a/text_translator/README.md b/text_translator/README.md new file mode 100644 index 000000000..0655f3d43 --- /dev/null +++ b/text_translator/README.md @@ -0,0 +1,13 @@ +# Using TextTranslator script +## Steps to translate : +1. Run the script `TextTranslator.py` using python. + +2. After execution of the script you will be prompted to enter the Text you want to translate. + +3. You will get the correct translation of the given text in English. + +## NOTE : The input text could be in any language, it will be automatically detected and translated into English. +## If you want to change the output Language, you may add a dest field to translation in `TextTranslator.py` and provide the language code for the required language : +``` +translation = translator.translate("INPUT_TEXT", dest="LANGUAGE_CODE") +``` diff --git a/text_translator/TextTranslator.py b/text_translator/TextTranslator.py new file mode 100644 index 000000000..a7fbc4830 --- /dev/null +++ b/text_translator/TextTranslator.py @@ -0,0 +1,9 @@ +from googletrans import Translator, constants +from pprint import pprint + +# init the Google API translator +translator = Translator() + +# translate text in any language to english text (by default) +translation = translator.translate(input("Enter text to translate into English")) +print(f"{translation.origin} ({translation.src}) --> {translation.text} ({translation.dest})") diff --git a/text_translator/requirements.txt b/text_translator/requirements.txt new file mode 100644 index 000000000..c49ad8a2c --- /dev/null +++ b/text_translator/requirements.txt @@ -0,0 +1 @@ + googletrans(3.1.0a0)