I had the same problem while working on one of my projects [Translation of localization of language resources]
I did the same and used .. System.Text.Encoding.UTF8.GetBytes (), and because of the utf8 encoding, they received special characters, for example, yours, for example, 239, 191, 189 in the result line.
Please take a look at my solution ... hope this helps
Do not use encoding at all. Google translation will return correctly, as well as in the line itself. do some string manipulation and read the string as it is ...
Generic Solution [works for every language translation that supports Google]
try { //Don't use UtF Encoding // use default webclient encoding var url = String.Format("http://www.google.com/translate_t?hl=en&text={0}&langpair={1}", "►" + txtNewResourceValue.Text.Trim() + "◄", "en|" + item.Text.Substring(0, 2)); var webClient = new WebClient(); string result = webClient.DownloadString(url); //get all data from google translate in UTF8 coding.. int start = result.IndexOf("id=result_box"); int end = result.IndexOf("id=spell-place-holder"); int length = end - start; result = result.Substring(start, length); result = reverseString(result); start = result.IndexOf(";8669#&");//◄ end = result.IndexOf(";8569#&"); //► length = end - start; result = result.Substring(start +7 , length - 8); objDic2.Text = reverseString(result); //hard code substring; finding the correct translation within the string. dictList.Add(objDic2); } catch (Exception ex) { lblMessages.InnerHtml = "<strong>Google translate exception occured no resource saved..." + ex.Message + "</strong>"; error = true; } public static string reverseString(string s) { char[] arr = s.ToCharArray(); Array.Reverse(arr); return new string(arr); }
as you can see from the code, the encoding was not done, and I send 2 special charachters as “►” + txtNewResourceValue.Text.Trim () + “◄” to determine the beginning and end of the return transfer from Google.
I also tested hough my language tool. Am I getting Cómo Estás? when sending How do you feel about the Google translation ... :)
Regards [Shaz]
--------------------------- Edited ------------------- --- ---
public string Translate (String input, String languagePair) {
try { //Don't use UtF Encoding // use default webclient encoding //input [string to translate] //Languagepair [eg|es] var url = String.Format("http://www.google.com/translate_t?hl=en&text={0}&langpair={1}", "►" + input.Trim() + "◄", languagePair); var webClient = new WebClient(); string result = webClient.DownloadString(url); //get all data from google translate int start = result.IndexOf("id=result_box"); int end = result.IndexOf("id=spell-place-holder"); int length = end - start; result = result.Substring(start, length); result = reverseString(result); start = result.IndexOf(";8669#&");//◄ end = result.IndexOf(";8569#&"); //► length = end - start; result = result.Substring(start + 7, length - 8); //return transalted string return reverseString(result); } catch (Exception ex) { return "Google translate exception occured no resource saved..." + ex.Message"; } }