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!
Google Translate is free, fast, and pretty accurate. Thanks to its massive database, the software can deliver decent translations that can help you get the main idea of a text.
However, as of January 2019, Google has stopped providing access to new website translator widgets. In addition, the Google Translate widget (which Google calls “Google Translate's Website Translator”) is phasing out on websites where it is active now (as shown below).
What is your name? 이름이 뭐야?
super, (chouette)
This should work:
var result = Translate("How are you?", "es|en", Encoding.UTF8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With