gpt4 book ai didi

c# - 将文本框输入翻译成西类牙语、中文、德语

转载 作者:太空狗 更新时间:2023-10-29 21:10:12 29 4
gpt4 key购买 nike

我想将文本框值翻译成特定语言,如西类牙语、中文、德语等,它们都在下面的下拉列表中,我想在标签中显示文本框翻译值,但不在标签中显示翻译值。

<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;
}

最佳答案

Google 是一款非常棒的工具,可用于查找此类内容。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;
}

//Get the HtmlAgilityPack here: http://www.codeplex.com/htmlagilitypack

关于c# - 将文本框输入翻译成西类牙语、中文、德语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8358237/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com