Hawaiʻi's Technology Community

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)


Before translating things from your ruby application you first need to sign up for the Microsoft Translator API in the Windows Azure Datamarket.


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.


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 ='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 and here are all the language codes as a helpful reference.



Views: 879


You need to be a member of TechHui to add comments!

Join TechHui

Comment by Daniel Leuck on June 11, 2012 at 1:44pm

Now that Google stopped supporting a free tier for their translation service I imagine this will be very popular.

Comment by Joseph Lui on June 11, 2012 at 10:01am

Good job Chris. Thanks for contributing.

Comment by Douglas Ching on June 11, 2012 at 6:07am



web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service