Playing with Translation in Google Translate API

Sandun Isuru Niraj
3 min readMar 11, 2019

When we talking about the translation from one language to another language we can’t forget about the Google Translate. Of course, we use their traditional website, translate.google.com to get translations to be done.

But they have introduced their Cloud Translation API recently to the public to get things done easily through their own applications. You can access their resources through the Google Cloud console.

In this article, I’m going to implement a simple translation application using the Google Translate API and NodeJS.

Ok, Let’s get hand dirty.

First of all, you need a Google Cloud account. If you have paid account don’t worry. If you not, You can register for a trial account with $300 for 1 year period when you add your Credit/Debit card.

If you completed, Then head back to the Google Cloud Console.

Now, You need to create a new Project.

And enter the name and click create the project. Then you need to the setup API key.

So go to the API Credentials create page here.

Now click Create Credentials and then API Key. Now you can see your API key is created.

Copy that key and paste somewhere for future usage.

Now clone this repo from Github.

Then you can rename the .env.example file to .env and add your API key

And then run

npm install

to download dependencies.

Then run the project using node index.js, If you have nodemon try running nodemon index.js

We have used Axios for sending HTTP Request to the Google Translate API. You can send this sample request to the localhost:3000/translate endpoint by using Postman as POST request.

{
"source": "si", //Source Language of your Text
"target": "en", // Language that you need to translate
"text": "අම්මා සඳකි" // Your translatable Text
}

Then you can see the response as text message.

Thank you.

--

--