Translating human languages in Python [closed]

2019-01-11 14:39发布

问题:

Is there a Python module for the translation of texts from one human language to another? I'm planning to work with texts that are to be pre and post processed with Python scripts. What other Python-integrated approaches can be used?

回答1:

If you're looking to actually translate a string of text between two languages, say from English "Hello" to Spanish "Hola", you might want to look into the Google Language API.

Another alternative due to recent deprecation of the free version of Google's API is the Bing Translator API.

Lastly, Google Cloud Platform offers the Translate API as a service, costing about $1 USD per 50,000 characters translated.



回答2:

The Python Natural Language Toolkit will almost certainly be useful to you:

"Open source Python modules, linguistic data and documentation for research and development in natural language processing"

I don't believe it will do translation directly, but it's great for machine understanding of natural language text.



回答3:

Python supports gettext. Check out the docs here.



回答4:

If you want to translate arbitrary (natural) text, check out Goslate, a free python API to Google Translation Services. According to this website, code is as easy as this:

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

You can pip install using

pip install goslate


回答5:

What to use depends on what you want to translate.

  1. Texts that are a part of your application, like UI etc. Then use gettext directly, or zope.i18n, which wraps gettext so it's easier to use.
  2. Arbitrary texts: The Google Translation API is the thing for you.
  3. "Content", ie things that the user of the application will modify and translate: Well... nothing, really. You have to implement that yourself.

On your description, it sounds like you are after #2.