I am working on a Natural Language Processing program in which I am trying to implement Google Translate. While looking for ways to implement Google translate in Assembly I came across the following code segment:
public static string Translate(string input, string languagePair, Encoding encoding)
{
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 = encoding;
result = webClient.DownloadString(url);
}
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
return doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText;
}
I am relatively new to C#, I have mainly used Java, and I unclear on the implicit parameters for
public static string Translate(string input, string languagePair, Encoding encoding)
When I look in the C# API for Encoder, there were examples as to how to use the Encoding class: (link: http://msdn.microsoft.com/en-us/library/h5y3703w(v=vs.71).aspx )
Byte[] thirdcharNoFlush = new Byte[encoder.GetByteCount(chars, 2, 1, bFlushState)];
encoder.GetBytes(chars, 2, 1, thirdcharNoFlush, 0, bFlushState);
What should I input in my parameters in order to translate a phrase, such as "How are you?", into Spanish using Google Translate. Any help on this matter would be greatly appreciated!
这应该有效:
var result = Translate("How are you?", "es|en", Encoding.UTF8);
var text = Translate("How are you?", "es|en", Encoding.UTF8);
http://msdn.microsoft.com/zh-CN/library/system.text.encoding(v=vs.110).aspx#Y8900
https://github.com/han6man/Google_Translate Google_Translate C# Google Translate without API first install GoogleTranslateWinForms\\lib\\awesomium_1_7_5_1_sdk_win.exe Without api key. Limited string lengh 5000 5 translations per second 200000 per day
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.