To run this:
pip3 install -r requirements.txt
- Tutorial code is in
translator.py
. - If you want to translate a document, you can use
translate_doc.py
:Output:python3 translate_doc.py --help
usage: translate_doc.py [-h] [-s SOURCE] [-d DESTINATION] target Simple Python script to translate text using Google Translate API (googletrans wrapper) positional arguments: target Text/Document to translate optional arguments: -h, --help show this help message and exit -s SOURCE, --source SOURCE Source language, default is Google Translate's auto detection -d DESTINATION, --destination DESTINATION Destination language, default is English
- For instance, if you want to translate text in the document
wonderland.txt
from english (en
as language code) to arabic (ar
as language code):A new filepython translate_doc.py wonderland.txt --source en --destination ar
wonderland_ar.txt
will appear in the current directory that contains the translated document. - You can also translate text and print in the stdout using
translate_doc.py
:Output:python translate_doc.py 'Bonjour' -s fr -d en
'Hello'