I want to translate text in Indian languages. I have gone through many articles but can not understand clearly how to do so. I have also seen some articles on google translator but none of them provide guide to use it in code.
Please guide me how can I do so. Do I need to add fonts for all languages in my application?
I have pasted the following code and now getting error. Can't understand what is that error.
The error is "Index and length must refer to a location within the string.
Parameter name: length".
Below is my code.
public 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);
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;
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;
}
protected void btnTranslate_Click(object sender, EventArgs e)
{
string convertTo="en|"+ddlLanguages.SelectedValue;
txtTarget.Text = TranslateText(txtLanguage.Text, convertTo);
}
ID of both the textboxes are "txtLanguage" for source language and "txtTarget" for target language.
Best Answer
Why not try these?
google-language-api-for-dotnet
http://code.google.com/p/google-language-api-for-dotnet/
Translate text in C#, using Google Translate
http://dnknormark.net/post/Translate-text-in-C-using-Google-Translate.aspx
Google Translator
http://www.codeproject.com/KB/IP/GoogleTranslator.aspx
Translate your text using Google Api's
http://blogs.msdn.com/shahpiyush/archive/2007/06/09/3188246.aspx
Calling Google Ajax Language API for Translation and Language Detection from C#
http://www.esotericdelights.com/post/2008/11/Calling-Google-Ajax-Language-API-for-Translation-and-Language-Detection-from-C.aspx
Translation Web Service in C#
http://www.codeproject.com/KB/cpp/translation.aspx
Using Google's Translation API from .NET
http://www.reimers.dk/blogs/jacob_reimers_weblog/archive/2008/06/18/using-google-s-translation-api-from-net.aspx
Link