Tuesday, March 27, 2018

Google Translation API


When you want to translate words from one language to another language, What will you do? Go to google translate and select the language origin and the target language as described below,





What if you want to translate in your Java code? For this Google has a solution in thier Google Cloud Platform(GCP), Google Cloud Translation API. In GCP platform, Google provides their api’s and in the platform you can do the api analytics and billing! Forget to mention its not free but for initial signup there are giving $300 credits free and we can use for 1 year.

Let’s look at the Google Cloud Translation API,



In the translation API, there are five methods listed below,




For the translation, we need to use language.translations.translate method. 

In the GCP platform we can test the api as follows,


For the “q” property, we need to type the text to be translated.

For the “source” property, we need to give the text language origin
For the “target” property, we need to give the target language.

The below image depicts the api call result,



So, we have tested the api using GCP platform, how about testing the api from externally

So, here comes POSTMAN,



Postman is an api testing tool which can be installed in Google Chrome as a plugin. To test the api, Google needs to authenticate us, so Google provides authentication mechanism like API Key, Oauth 2.0 Client ID’s.  As i earlier mentioned, its not free so we need to sign up for billing using our credit card and can use the free credits.

To get the API Key, we need to create a project in GCP platform and have to generate the key,
The api can be invoked by calling,

The Postman result follows,



Expect Future Posts, Thank You

2 comments: