A simple Ruby interface to Bing's translation API.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 93 commits behind relrod:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.rvmrc
Gemfile
Gemfile.lock
LICENSE
README.md
bing_translator.gemspec

README.md

Bing Translator

This gem wraps the Micrsoft Bing HTTP Translate API. I am in no way affiliated with Microsoft or Bing. Use this gem at your own risk.

Released under MIT. Tested with MRI 1.9.3 and 1.8.7.

Installation

To use this rubygem:

$ sudo gem install bing_translator

With bundler:

gem "bing_translator", "~> 2.0.0"

Information

Version 1.0.0+ of bing_translator use the new OAuth-based Bing authentication.

bing_translator is also smart about requesting the token, and handles this behind the scenes. It will only request a token if it knows the old one expired (X seconds from when we requested the last token, where X is given to us when we make the request. As of this writing, X is consistently 10 minutes).

Getting a Client ID and Secret

To sign up for the free tier (as of this writing), do the following:

  1. Go here
  2. Sign in with valid MSN credentials.
  3. On the right side, click 'SIGN UP', under the $0.00 option.
  4. Read and accept the terms and conditions and click the big 'SIGN UP' button.
  5. Create a new application. Fill in a unique client ID, give it a valid name, give it a valid redirect URI (not actually used by the Bing Translator API, so it can be anything) and hit 'CREATE'.
  6. Click on the name of your application to see the info again. You'll need the 'Client ID' and 'Client secret' fields.

Usage

require 'rubygems'
require 'bing_translator'
translator = BingTranslator.new('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET')
spanish = translator.translate 'Hello. This will be translated!', :from => 'en', :to => 'es'

# without :from for auto language detection
spanish = translator.translate 'Hello. This will be translated!', :to => 'es'

locale = translator.detect 'Hello. This will be translated!' # => :en