谷歌翻译C#

Joh*_*ith 10 .net c# google-translate

我正在开发一个自然语言处理程序,我正在尝试实现Google翻译.在寻找在汇编中实现Google翻译的方法时,我遇到了以下代码段:

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;
}
Run Code Online (Sandbox Code Playgroud)

我对C#比较新,我主要使用Java,而且我不清楚隐含的参数

public static string Translate(string input, string languagePair, Encoding encoding)
Run Code Online (Sandbox Code Playgroud)

当我查看用于编码器的C#API时,有一些关于如何使用Encoding类的示例:(链接: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);
Run Code Online (Sandbox Code Playgroud)

我应该在参数中输入什么才能使用Google翻译将短语(例如"你好吗?")翻译成西班牙语.任何有关此事的帮助将不胜感激!

cdh*_*wie 4

这应该有效:

var result = Translate("How are you?", "es|en", Encoding.UTF8);
Run Code Online (Sandbox Code Playgroud)