Sunday, June 20, 2010

Translate content using Bing Service In MVC

I used Translate Bing Service API in SharePoint Translate Web Part. Same API can be used with MVC. Here i am writing small extension method for HtmlHelper.

public static class HtmlHelperExtention
        public static string Tranlate(this System.Web.Mvc.HtmlHelper objHelper,string inputContent,string sourceLanguage,string targetLanguage)
            string apikey = System.Configuration.ConfigurationManager.AppSettings["BingAPI"];
            Soap s = new Soap();
            string frenchoutputtext = s.Translate(apikey, inputContent, sourceLanguage, targetLanguage);
            return frenchoutputtext;           

In View Of MVC you should write this.

    <%=  Html.Tranlate("<div>This is Translation test.</div>","en","fr") %>

1. Valid API key required.
2. Need to Add Proxy Class to user “Bing Translate Service”.

Hope this will help…….