加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 将文本框输入翻译成西班牙语,中文,deutsch

发布时间:2020-12-15 04:29:30 所属栏目:百科 来源:网络整理
导读:我想将文本框值转换为特定语言,如西班牙语,Chinse,Deutsch等,这些都在下面的下拉列表中,我想在标签中显示文本框翻译的值,但不是在标签中显示转换值. asp:TextBox ID="txtmessage" runat="server" / asp:DropDownList ID="drop" runat="server" AutoPostBack=
我想将文本框值转换为特定语言,如西班牙语,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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读