Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I easily machine translate something with python? [closed]

Tags:

python

nltk

You used to be able to use nltk.misc.babelfish 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' 
like image 685
Jonathan Avatar asked Dec 20 '15 15:12

Jonathan


People also ask

Is automatic machine translation possible?

Automated translation may be used to automate the machine translation of text as a stage in the localization workflow. However, automated translation and machine translation are not interchangeable terms as they serve entirely different functions.

How does hybrid machine translation work?

Hybrid Machine Translation is a method of machine translation that is characterized by the use of multiple machine translation approaches within a single machine translation system.

How do I use Google translate in Python?

You can also translate text documents via Google Translate API. All you have to do is to read the text file in Python using the open method, read the text and pass it to the translate() method.


1 Answers

Goslate is a good library for this that uses Google Translate: http://pythonhosted.org/goslate/

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'...}

like image 62
G Brown Avatar answered Oct 04 '22 20:10

G Brown