Friday, September 18, 2015

Use Google Translate API for FREE

My company subscribed to Google Apps for Education. So, I though that access to Google Translate API would be included in our contract... but, that's not the case :(

Hummm... hummm... let's hack this for free.

Prerequisite is to have a Google account (even a free gmail account). What we will do is the create a sctipt on Google that will use the translate api freely and publish it as a REST web service which has the same JSON output format as the original.

Let's go!

  1. Connect to and create an empty project.
  2. Copy paste the code below
  3. Publish it as web application
  4. Grant access to the url of your script to anonymous access if needed

var mock = {

function doGet(e) {
  e = e || mock;
  var sourceText = ''
  if (e.parameter.q){
    sourceText = e.parameter.q;
  var sourceLang = 'auto';
  if (e.parameter.source){
    sourceLang = e.parameter.source;

  var targetLang = 'en';
  if ({
    targetLang =;
  var translatedText = LanguageApp.translate(sourceText, sourceLang, targetLang)
  var json = {
    'data': {
      'translations' : [{
        'translatedText' : translatedText
  return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON);

The original Translation API from Google is[encodedText]&target=[language]&source=[language]&key=APIKEY

Your's will be something like[encodedText]&target=[language]&source=[language]

The output formats of the two REST service are identicals.



Greg David said...

Hello! If you are working on software translation projects, I may recommend to evaluate It is an online localization management tool equipped with great features (API, translation memory, Gengo integration, automatic translation, Bitbucket and GitHub integration) and a user-friendly interface that will automate your workflow.

simashree said...

Thanks for the great information in your blog Selenium Training in Chennai

Remove ugly bash (shell) directory highlight colors

Tired of green over blue colors in default Ubuntu shell for directories ? Just type this from your shell console to update your bash profi...