Google Cloud Translation API - bounswe/bounswe2017group3 GitHub Wiki
Google Cloud Translation API
Cloud Translation API gives a basic programmatic interface for translating a random text into any language supported by this API. Websites and applications can incorporate with Translation API for dynamic translation of text from the source language to a target language due to highly responsiveness of the API. Additionally, if the source language is unknown, language detection is available. The API is updated constantly to improve translations and introduce new languages.
Translate Many Languages
Translation API supports more than one hundred different languages, from Afrikaans to Zulu. So, it is possible to translate between thousand of language pairs.
Language Detection
In cases the source language is unknown, Translation API can automatically identify languages with high accuracy.
Simple Integration
Translation API is an easy to use Google REST API. So, sending it HTML documents is just enough for translation. Extracting text from the documents is not needed.
Highly Scalability
Translation API can handle almost any volume without any problem. There is a generous daily quota and it is allowed to set limits below that amount.
Simple Pricing
Translation API charges on a per character basis, even if the character is multiple bytes.
#How to make an API request
- Create a JSON request file with the following text, and save it as a translate-request.json plain text file:
'q': 'The quick brown fox jumped over the lazy dog.',
'source': 'en',
'target': 'es',
'format': 'text'
}```
In this code snippet, 'q' refers to the source text, 'source' and 'target' means the source and the target language codes, in this case, English and Spanish respectively. Also, 'format' is specified as text.
+ Authenticate to your service account, passing the location of your service account key file:
```gcloud auth activate-service-account --key-file=```**```service-account-key-file```**
+ Obtain an authorization token using your service account:
gcloud auth print-access-token
access_token
+ Use curl to make a v2 request, passing it the access token you printed, and the filename of the JSON request which is **translate-request.json**:
curl -s -k -H 'Content-Type: application/json'
-H 'Authorization: Bearer access_token'
'https://translation.googleapis.com/language/translate/v2'
-d @translate-request.json
Then the response will be similar to:
{ "data": {
"translations": [
{ "translatedText": "El zorro rápida saltó sobre el perro perezoso." }
]
}
}
##References
+ [Cloud Translation API - Google Cloud Platform](https://cloud.google.com/translate/)
+ [Google Translate API - SDKs - Programmable Web](https://www.programmableweb.com/api/google-translate)
+ [Translation API - Quickstart - Google Cloud Platform](https://cloud.google.com/translate/docs/getting-started#make_a_translation_api_request)