trsanslator
trsanslator

we are able to use a language translator to translate text from one language to every other.
there are various API and modules for this, we’ll use the google translate api.

we will use the goslate module to translate. other than translation, it helps
language detection, batch translation, dictionary research and greater.

Installation

the goslate module connects with the google translate api.
the first step is to Install in the goslate module.
install goslate the use of pyenv, pipenv or virtualenv.

Example

With just a few lines of code we can translate English to French.


import goslate

text = “Hello World”

gs = goslate.Goslate()
translatedText = gs.translate(text,’fr’)

print(translatedText)

Change the second parameter in gs.translate to alter the language.

Other Translate APIs

There are a few other translation APIS including:

that is a simple dictionary translation (offline). in case you need a easy word translation, you could use this.use your package deal manager to install dictd,


sudo pacman -S dictd
sudo apt-get install dictd

Then to list databases


dict -D

To translate a single word:


dict -d fd-eng-spa “earth”

We create this code to list all translations:


import os

word = ‘earth’
translation = os.popen(‘dict -d fd-eng-spa ‘ + word).read()
print(translation)

LEAVE A REPLY

Please enter your comment!
Please enter your name here