.NET Extension Methods For Microsoft Translator API

| by Roopesh Shenoy Follow 0 Followers on Aug 29, 2011. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

 Microsoft Translator API exposes Translation services for developers using REST-based and SOAP based end-points. An open source project, Bing (Microsoft) Translator .NET, creates a wrapper around these APIs by using extension methods, making it much easier to build .NET applications that can use translation.

The Microsoft Translator API provides a lot of features such as -

  • Detecting a language
  • Translation text from one language to another
  • Text-to-speech conversion for a selected set of languages
  • Reformatting text, such as breaking text into a set of sentences

When using these features in a .NET application though, they have to be called using HttpWebRequest object, which is not very intuitive and also quite verbose. What the Bing .NET Extensions library does, is provide extension methods to .NET objects, to make these calls much simpler.

For example to translate a text input in English to Arabic, instead of

string uri =  appId + "&text=" + 
  tobetranslated + "&from=" + fromLang +  "&to=Arabic”;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
WebResponse response = request.GetResponse();
Stream strm = response.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
translatedText = reader.ReadToEnd();

using the Translator .NET library, you can now just write

translatedtext = tobetranslated.BingTranslate(BingLanguage.English,BingLanguage.Arabic)

In fact, you can even use the language detection feature to avoid mentioning the source language -

translatedText =  tobetranslated.BingTranslate(BingLanguage.Arabic);

There are other extension methods provided for the other Bing Translation API features listed above. A full description of how to use these features is mentioned in Mohammed’s blog post.

To learn more about Microsoft Translator APIs, you can refer the developer documentation

Extension methods is a NET feature introduced in .NET Framework 3.0 that allows you to add methods to existing types, without creating a new derived type, recompiling or otherwise modifying the original type. 


Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you