http://code.google.com/apis/language/translate/overview.html
Add this line to your application's Gemfile:
gem 'google_translate'
And then execute:
$ bundle
Or install it yourself as:
$ gem install google_translate
from_language = 'es'
to_language = 'en'
@gt = Google::Translate.new(from_language, to_language, {:api_key => 'YOUR_API_KEY'})
puts @gt.translate('perro')
By default, the translator caches term translations in order to avoid unnecessary requests. This can be globally disabled passing:
:cache => false
in the options hash.
You can also skip the caching only for certain translation requests by passing
:cache => false
to the translate method.
@gt.translate('A longer sentence that won't likely be repeated', { :cache => false })
See Google Translate API v2 for details about parameters, including supported language codes.
Note: Google::Translator can still be used instead of Google::Translate for backwards compatibility
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright © 2011 Christian Hein, released under the MIT license