Free Google Translate API v2 2
Background
Google Translate API v2 is now available as a paid service only, and the number of requests your application can make per day is limited. As of December 1, 2011, Google Translate API v1 is no longer available; it was officially deprecated on May 26, 2011.
Migration
So, if you were using google translate API in you application, you have to register for a paid service or you may do like other many developers migrated to other free API services like
Wait, Google Translate API is still FREE :) Lets see how.
Yes, but using an indirect method. Google Translate API is available as free through Google Apps API. So, you can access Google Translate API from Google spreadsheets as the following:
- Create a blank google spreadsheet
- Create a script from the spreadsheet to access Google Translate API
- Access your spreadsheet remotely using spreadsheet API to translate your text :)
Lets see more details with steps and code....
- Login to your google docs
- Create a blank google spreadsheet
- From spreadsheet menu, select "Tools" > "Script editor"
- Add the following javascript function
function gTranslate(text, from, to) { return LanguageApp.translate(text, from, to); } -
Save your script file
-
Now, lets access spreadsheet from your application. I will give an example using Ruby language and for sure you can use any other language. We will need to install google-spreadsheet-ruby ruby gem to access our spreadsheet. My Ruby code will be as the following...
require "rubygems"
require "google_spreadsheet"
# Logs in. You can also use OAuth
session = GoogleSpreadsheet.login("username@gmail.com", "mypassword")
# First worksheet of http://spreadsheets.google.com/ccc?key=pz7XtlQC-PYx-jrVMJErTcg&hl=en
ws = session.spreadsheet_by_key("pz7XtlQC-PYx-jrVMJErTcg").worksheets[0]
# call my script from spreadsheet
ws[2,1] = '=gTranslate("this is a test", "en", "es")'
ws.save
# Reloads the worksheet to get my changes effect
ws.reload
puts ws[i,1] #Esta es una prueba
Wow, it works without any payments :)
Note To pass parameters to the script function “gTranslate”, you need to use double quotes
ws[2,1] = '=gTranslate("this is a test", "en", "es")'
Single quotes will NOT work.
ws[2,1] = "=gTranslate('this is a test', 'en', 'es')"
Side effects:
This work around solution works fine with me but something slow because we make many requests to save an reload spreadsheet. So, if you need to translate many strings fast, I suggest you join them be new line and then split the result over the new lines.

2 Comments
01/09/12 at 16:51:00
Nice article Mahmoud,
Do you think google will stop it?
01/11/12 at 07:01:22
Thanks Muhammad,
I don't think google will stop it because they encourage users to use google apps. And given google apps integration is very powerful feature and there are already many users use google translate API from their google apps. If google stop it, all these spreadsheets won't work properly.
Leave a Comment...