We can use a language translator to translate text from one language to another.
There are various APIs and modules for this, we’ll use the Google Translate API.
We will use the Goslate module to translate. Apart from translation, it supports
language detection, batch translation, dictionary lookup and more.
The goslate module connects with the Google Translate API.
The first step is to install the goslate module.
Install goslate using pyenv, pipenv or virtualenv.
With just a few lines of code we can translate English to French.
Change the second parameter in gs.translate to alter the language.
There are a few other translation APIS including:
- Google Cloud Platform
- mstranslate - Microsoft(Bing) translate API for python3
- gp-python-client - IBM Bluemix
- yandex-translater - API for Yandex Translate
- No known module - Baidu Translation API
Do you know of any other modules? leave a comment.
If there is no module available for the translation API,
you could make your own module using beautifulsoup.
This is a simple dictionary translation (offline). If you want a simple word translation, you can use this.Use your package manager to install dictd,
Then to list databases
To translate a single word:
We create this code to list all translations: