Sunday, June 20, 2010

Translate content using Bing Service In ASP.net MVC

I used Translate Bing Service API in SharePoint Translate Web Part. Same API can be used with ASP.net 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 ASP.net MVC you should write this.

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

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

Hope this will help…….