Jono Jono - 5 months ago 22
Python Question

How can I easily machine translate something with python?

You used to be able to use

to translate things, but the Yahoo Babelfish API went down. Is there an easy way I can, say, do this?

>>> import translate
>>> translate('carpe diem', 'latin', 'english')

'seize the day'


Goslate is a good library for this that uses Google Translate:

Here's the example from the docs:

>>> import goslate
>>> gs = goslate.Goslate()
>>> print(gs.translate('hello world', 'de'))
hallo welt

In order to go from "carpe diem" to "seize the day":

>>> print(gs.translate('carpe diem', 'en', 'la'))
seize the day

So it's essentially the same as the Babelfish API used to be, but the order of the target and source languages is switched. And one more thing -- if you need to figure out the short code, gs.get_languages() will give you a dictionary of all the short codes for each supported language: {...'la':'Latin'...}