Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Translation API

dalarm edited this page Jul 27, 2017 · 2 revisions

This wiki page is to document the Translation API. Rough outline. Add on to it as you learn more about the API.

GoogleTrans

This is a free API that utilizes Google Translate API. This also uses the Google Translate Ajax API so that we can use functions such as detect and translate.

If you want to read in-depth documentation, click here

Installation

In order to use this API, you need to install it by using this command

pip install googletrans

Functionalities

This API comes with several functions that we can use such as detect and translate. Here are a few examples:

from googletrans import Translator

translator = Translator()
translator.translate('como estas.') 
translator.translate('como estas', dest='ja')
translator.translate('hello', src='en')
translator.detect('como estas.')

Make sure to import the Translator at the top of your code before using the API. If you don't specify the source or destination language, it will do it automatically. The default destination language is English. As for detect, that function is primarily used to output what language the API thinks the expression is in. It will also give you the percentage of confidence that the API has in its own answer. So, if the API isn't too confident with the detected language, it will give you a low percentage of confidence.

If you look in the documentation provided above, you can see that there's also a way to use arrays. With the array, you can translate multiple expressions with a for-loop.