Click here to Skip to main content
15,908,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two text boxes,txtenglish and txtMalay.

As soon as I finish editing txtenglish,ontextxganged event,I want txtmalay to be populated with the translation.

How to do that using Google API?[or something else?]
Posted

Hi,

have a look here:

http://martinnormark.com/2010/10/25/translate-text-in-c-using-google-translate-revisited[^]

You can find much more and most probably much better solutions by using GOOGLE.
 
Share this answer
 
Comments
avishekrc 26-Nov-10 8:05am    
Hi,
I am using the code as suggested here:<a href="http://blogs.msdn.com/b/shahpiyush/archive/2007/06/09/3188246.aspx"></a>
Please find my code below:
I have two text boxes,and in text_change event of one text box I am calling the method which will convert the text entered in English in the first text box into the second text box in some other language.
<pre>
protected void txtEnglish_TextChanged(object sender, EventArgs e)
{
// txtMalay.Text = txtEnglish.Text;
// "ar|en"
string langpair="en|ar";
txtMalay.Text = TranslateText(txtEnglish.Text,langpair);
}
public string TranslateText(string input,string languagePair)
{
try
{
// string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}", input, languagePair);
WebClient webClient = new WebClient();
//WebClient wc = new WebClient();
webClient.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("user:pass")));
// string a = ws.DownloadString("http://www.example.com");

webClient.Encoding = System.Text.Encoding.UTF8;
NetworkCredential netcredit = new NetworkCredential("archowdhury", "Secure*45", "corp");
webClient.Credentials = netcredit;
webClient.Proxy = new System.Net.WebProxy()
{
Credentials = new System.Net.NetworkCredential("archowdhury", "Secure*45", "corp")
};


string result = webClient.DownloadString(url);

result = result.Substring(result.IndexOf("id=result_box") + 22, result.IndexOf("id=result_box") + 500);

result = result.Substring(0, result.IndexOf("</div"));

return result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return ("failure");
}
</pre>
I am getting the following exception:"UNABLE TO CONNECT TO THE REMOTE SERVER! "
Whats wrong here?
If you are using the APIs then you can check the link below:

http://code.google.com/apis/ajax/playground/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900