Bing Translator for developers

by Bashar Kokash 19. April 2010 12:16

Recently Microsoft announced the latest version of Bing Translator, this new version (v2) added some cool and new features, including collaborative translations, customizable widgets, powerful API, and Translate-to-Speak. In this post I will describe the simplest way to use those new APIs, provide simple example and demonstrate new features.

Bing translator APIs could be easily targeted through the various available APIs: AJAX, HTTP and SOAP. But first, you should obtain a valid Bing AppID. Sign-in using your live ID then get it from here. The AppID will be used as a validation parameter when calling any API such as Detect, Translate, and Speak.

Simple Hello World Translate example using Ajax interface

The Translate method requires the following parameters:

AppID: Which is a string of a valid Bing AppId.
From: A code represents the language of the translated text. (You could get the available translate language using GetLanguagesNamesMethod)
To: Another code that represents the language to translate text into.
Text: and of course the text that's to be translated.
OnComplete: The Call back function that will be called on the completion of the request.

The Request URL should look like this:

http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=MyAppID&from=en&to=ar&text=hello&oncomplete=doneCallback

All you have to do is just replace MyAppID with your own valid Bing AppID and define the doneCallback function.

The following is a full simple example that calls the Translate method passing the parameters described above.

Notice that the doneCallback function receives a response parameter and simple displays it inside a div.

   1:  <html>
   2:   <head>
   3:    <title>Bing Translator Test</Title>
   4:   </head>
   5:  <body>
   6:   
   7:   <div id="englishText">
   8:   Hello
   9:   </div>
  10:   
  11:   <div id="arabicText">
  12:   Arabic: 
  13:   </div>
  14:   
  15:   <input type="button" value="en 2 ar" onClick="translate();"/>
  16:   
  17:  <script type="text/javascript">
  18:  var text = document.getElementById("englishText").innerHTML ;
  19:  function translate() {
  20:   window.doneCallback = function(response) {
  21:   document.getElementById("arabicText").innerHTML +=response; }
  22:   var s = document.createElement("script");
  23:   s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?oncomplete=doneCallback&appId=MyAppID&
  24:   from=en&to=ar" + "&text=" + text;
  25:   document.getElementsByTagName("head")[0].appendChild(s);
  26:  }
  27:  </script>
  28:   
  29:  </body>
  30:  </html>

Where to start?

Tags: , , , , , ,

Microsoft | Bing | Source code

Comments

24/03/2011 3:45:14 AM #

Manish Gupta

sounds interesting, does google translator provides such features. I will check that myself. I am a big fan of google services.

Manish Gupta India | Reply

27/05/2011 6:20:53 PM #

some angry guy

Google is shutting down its Google Translate API on december 1st. That said, are there any limits on the Bing Translation API usage?

some angry guy United States | Reply

03/06/2011 10:52:39 PM #

pingback

Pingback from seangw.com

Google Translate API: Shutting Down, is there an alternative? | Sean Walther’s Blog

seangw.com | Reply

30/06/2011 3:18:04 AM #

cheap web hosting

As an experienced webmaster I recommend BH web hosting which I’m sure it would work for you and fulfill all your requirements. They have a really great offer for hosting & I have used them for over 3 yrs now, and have never had a single problem with them.

cheap web hosting United States | Reply

05/07/2011 10:31:15 AM #

pet insurance


Excellent article and easy to understand explanation.

pet insurance United States | Reply

07/07/2011 5:01:18 PM #

Replica Tissot Watches

good article. Thanks for your sharing!

Replica Tissot Watches United States | Reply

07/07/2011 5:02:21 PM #

Meizitang

Bing translator is good but it still sounds not better than google translator.

Meizitang United States | Reply

07/07/2011 5:03:20 PM #

Meizitang

are you a technical staff in microsoft?

Meizitang United States | Reply

07/07/2011 5:04:09 PM #

Meizitang

nice post. very informative

Meizitang United States | Reply

07/07/2011 7:33:53 PM #

London Hotels

I really wanted to send a small word to say thanks to you for the fantastic points you are writing on this site. My time-consuming internet lookup has at the end been honored with extremely good ideas to exchange with my pals. I ‘d express that many of us site visitors actually are extremely endowed to exist in a notable community with so many lovely individuals with useful points. I feel really fortunate to have used your webpage and look forward to so many more fun moments reading here. Thanks a lot again for a lot of things.

London Hotels United States | Reply

20/07/2011 9:19:30 AM #

Decret

Nice spam dude!

Decret Spain | Reply

10/07/2011 10:01:21 PM #

miniclip

I'm typically to running a blog and i actually admire your content. The article has actually peaks my interest. I'm going to bookmark your web site and keep checking for brand spanking new information.

miniclip United States | Reply

11/07/2011 8:44:16 AM #

SJR BUILDERS

I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.

SJR BUILDERS India | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.6.1.0

About

Yes that's right!

I'm a Microsoft guy, also a Computer Systems Engineer using the .NET framework stack to develop Web and Windows applications

Log in