V | E | C | T | O | R | XD For The Future


Introduction

This article describes the usage of Bing Translation API in your Flash Lite client. This application can translate between international languages using the Bing translation engine (version 2.2) provided by Microsoft. Bing Translator (previously Live Search Translator and Windows Live Translator) is a service provided by Microsoft as part of its Bing services which allow users to translate texts or entire web pages into different languages

The author recommends reading google translator API article before this article. Both articles have lots of similar characteristics.

Outline

Here are the keys steps –

1. Request a Bing API Key from Bing site. As any API key it is used to track the request for service or in simple terms, it is an identifier of the requesting party to Microsoft.

2. Understand the various types of communication method available to communicate with the server. This can be found at the site http://msdn.microsoft.com/en-us/library/dd877872.aspx They are of three major types – JSON, XML, SOAP.

3. Process the result obtained.

Making the Request

I have already discussed how a JSON based client has to be implemented in Flash Lite in google translator api article. SOAP type of webservices are simple to implement with the webserviceconnector component. In this article, we focus on how XML implementation is done. Before beginning to code the XML usage of the API, we need to understand the request is made as a query and the return is of XML type.

In order to request for data in the XML mode, you can use the loadvars() function in Flash

lv.load("http://api.bing.net/xml.aspxAppId=XXXXXX&Query="+toTranslate+"&Sources=Translation&Version=2.2&Translation.SourceLanguage="+src_lang+"&Translation.TargetLanguage="+dest_lang);

Here, toTranslate is the sentence to be translated ( after escape() ), src_lang and dest_lang are source and target languages respectively.

Result Processing

In addition after some testing I found that some further processing of text was needed after unescape(). Quotation marks, apostraphe characters has some trouble in getting rendered. Hence I had to handle it myself as follows.

function process(ip:String):String {
	while (ip.indexOf("'") != -1) {
		var arr:Array = ip.split("'");
		ip = arr.join("'");
	}
	while (ip.indexOf(""") != -1) {
		var arr:Array = ip.split(""");
		ip = arr.join("\"");
	}
	return ip;
 
}

In order to handle the receipt of data, you will need to write a onData function that processes the incoming XML data structure. Parsing an XML tree is again quite simple and to conclude creating a translation engine client is quite simple in Flash Lite.

Screenshots

Download

The associated FLA is attached in this file. Media:Bing_translate.zip

Authored by

Manikantan

Advertisements

Comments on: "Using Bing translator API in Flash Lite" (1)

  1. […] — Tags: Bing translator API, How to, tutorial — Li YongFei @ 12:15 am krishna Raj has posted a new Flash Lite tutorial, the tutorial describes the usage of Bing Translation API in […]

Comments are closed.

Tag Cloud

%d bloggers like this: