Google fish - a tiny gem for Google Translate API V2

By Mathijs Vos - via unsplash.com

By Mathijs Vos - via unsplash.com

For the last 9 months I've been heavily involved in the internationalisation of On The Beach. Along with making full use of Rails' excellent i18n API, we've also been translating some content on the fly using Google translate. Recently however, Google announced that they would be throttling the number of requests to the Google Translate API v1 service - and would be shutting off the service entirely on December 1st 2011. As Google Translate API v2 has now launched, I looked around for a gem we could quickly plug in and was surprised to find only the google-api-ruby-client - which for our needs seemed to come with a lot of dead weight (buzz!).

Given we only require a very limited feature set, I decided to build a tiny gem to meet just that need, and google_fish is the result.

Go fishing

gem install google_fish

In order to test this out, you will need an API key - once you've got that sorted, fire up irb

require 'google_fish'
google = GoogleFish.new('my-api-key')
google.translate(:en, :es, 'hi')
# => 'hola'
google.translate(:en, :es, '<p>hi</p>', :html => true)
# => '<p> hola </p>'

And that's it, a simple interface to the new Google Translate API v2. Source code as always is up on github - I'd love to hear from you if you're using this in your projects, and pull requests are welcome.