我想将文本框值转换为特定语言,如西班牙语,Chinse,Deutsch等,这些都在下面的下拉列表中,我想在标签中显示文本框翻译的值,但不是在标签中显示转换值.
<asp:TextBox ID="txtmessage" runat="server" /> <asp:DropDownList ID="drop" runat="server" AutoPostBack="true" onselectedindexchanged="drop_SelectedIndexChanged" > <asp:ListItem Value="en-US">English</asp:ListItem> <asp:ListItem Value="ja-JP">Japanese</asp:ListItem> <asp:ListItem Value="zh-CN">Chinse</asp:ListItem> <asp:ListItem Value="de-DE">Deutsch</asp:ListItem> </asp:DropDownList> <asp:Label ID="lblWelcome" Meta:resourcekey="lblWelcome" Text="Welcome" runat="server" ></asp:Label>
protected void drop_SelectedIndexChanged(object sender,EventArgs e) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(this.drop.SelectedValue); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(this.drop.SelectedValue); lblWelcome.text=txtmessage.text; }
解决方法
谷歌是一个很棒的工具,可以在寻找这样的东西时使用.
谷歌有谷歌翻译.
谷歌有谷歌翻译.
这是一个代码示例,您需要将其更改为适合您正在执行的操作.
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; } //Get the HtmlAgilityPack here: http://www.codeplex.com/htmlagilitypack