Skip to content

Microsoft Translator Ruby Gem

September 13, 2012

Stolen from http://www.techhui.com/profiles/blogs/microsoft-translator-ruby-gem

I know “Microsoft” is not the first word that comes mind when you’re writing a ruby application but since Google dropped the free tier for their translation service the Microsoft Translator API is a good alternative for a small/personal project that you don’t want to have to bother with the monthly bill.  

 

Recently I’ve had to use this API in a project and this weekend I extracted the functionality out into a simple gem.  I present to you ‘microsoft_translator’  (queue applause) https://github.com/ikayzo/microsoft_translator

 

Before translating things from your ruby application you first need to sign up for the Microsoft Translator API in the Windows Azure Datamarket.  https://datamarket.azure.com/dataset/1899a118-d202-492c-aa16-ba21c3…

 

Don’t worry, they have a free tier! (up to 2 million translated characters/month) Once you sign up for the Translator API you will also need to register your application with the Azure Datamarket.  https://datamarket.azure.com/developer/applications/

 

Also, you shouldn’t stress about what to put for the Redirect URI. For the purposes of this gem you won’t be using it so your project’s homepage will work just fine. You’ll use the Client ID and Client secret to authenticate your requests to the API. Once this is done you’ll install it like you would any other gem…

 

First create a MicrosoftTranslator::Client with your Client ID & secret. To translate pass in the foreign text allong with the language codes for the language you are going from/to and the content type. The content type is either “text/plain” or “text/html”

translator = MicrosoftTranslator::Client.new('your_client_id', 'your_client_secret')
spanish = "hasta luego muchacha"translator.translate(spanish,"es","en","text/html")
# => "until then girl"

That’s about it! This is a list of the supported languages by the Microsoft Translate API http://www.microsofttranslator.com/help/?FORM=R5FD and here are all the language codes as a helpful reference. http://www.loc.gov/standards/iso639-2/php/code_list.php

Advertisements

From → General

2 Comments
  1. I was wondering if you ever thought of changing the layout of your blog?
    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or 2 images.
    Maybe you could space it out better?

  2. Good day I am so thrilled I found your weblog, I really found you
    by error, while I was researching on Digg for
    something else, Regardless I am here now and would just like to say many thanks for
    a incredible post and a all round interesting blog (I also love the theme/design), I don’t have time
    to look over it all at the moment but I have saved it and also added your RSS feeds, so when I
    have time I will be back to read more, Please do keep up the
    superb work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: