ok got this thing working in case someone wants it here it is(the big catch someone told me is that Google will block the ip from which this is being called if you do it too many times)1. Create following translate.cs fileusing System;using System.Net;using System.Text;using System.Text.RegularExpressions; public static class Translator { /// <summary> /// Translates the text. /// </summary> /// <param name="input">The input.</param> /// <param name="languagePair">The language pair.</param> /// <returns></returns> public static void Main(string[] args) { TranslateText(args[1], args[2]); } /// <summary> /// Translate Text using Google Translate /// </summary> /// <param name="input">The string you want translated</param> /// <param name="languagePair">2 letter Language Pair, delimited by "|". /// e.g. "en|da" language pair means to translate from English to Danish</param> /// <param name="encoding">The encoding.</param> /// <returns>Translated to String</returns> public static string TranslateText(string input, string languagePair) { string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair); string result = String.Empty; using (WebClient webClient = new WebClient()) { webClient.Encoding = System.Text.Encoding.UTF7; result = webClient.DownloadString(url); } Match m = Regex.Match(result, "(?<=<div id=result_box dir=\"ltr\">)(.*?)(?=</div>)"); if (m.Success) result = m.Value; return result; } }
2. run the following utility for c# that creates a dll. csc /target:library [LOCATION_OF_translate.cs ]:\translate.cs 3. Copy the translate.dll to a location where the security context you are running as has full rights to4. CREATE ASSEMBLY translate from '[LOCATION_WHERE_YOU_COPIED_translate.dll]:\translate.dll' WITH PERMISSION_SET = EXTERNAL_ACCESSCREATE FUNCTION [dbo].[translate](@input nvarchar(4000), @languagePair nvarchar(4000) )RETURNS nvarchar(max)WITH EXECUTE AS CALLEREXTERNAL NAME [translate].[Translator].[TranslateText]GOSELECT [dbo].[translate] ( 'Hello beautiful French lady. Could I have this dance with you?' ,'EN|FR')
<><><><><><><><><><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion