Home > Uncategorized > Mobile version of Google Translate

Mobile version of Google Translate

Here’s some code to plug into Google Transate in C# – Not using the API:

 /// <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, Encoding encoding)
            string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}&quot;, input, languagePair);

            string result = String.Empty;

            using (WebClient webClient = new WebClient())
                webClient.Encoding = encoding;
                result = webClient.DownloadString(url);

            string strRegex = @"this.style.backgroundColor=’#fff’..(?<Text>[ws+]+)";
            Match m = Regex.Match(result, strRegex);
            return m.Groups["Text"].Value;

Orginal version from dnknormark.net, but I fixed his regex.

Check out http://translate.freebiesms.mobi/ for a demo

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: