将文本框输入翻译为西班牙语、中文、德语

发布于 2024-12-19 03:33:12 字数 1197 浏览 4 评论 0原文

我想将文本框值翻译为特定语言,如西班牙语、中文、德语等,这些语言都在下面的下拉列表中,并且我想在标签中显示文本框翻译值,但不显示标签中的翻译值。

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

I want to translate textbox value to specific language like spanish ,Chinse,Deutsch etc which all are having in below dropdown and i want to display textbox translated value in label but not gettin transalted value in label.

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

code-behind:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清君侧 2024-12-26 03:33:12

当寻找这样的东西时,谷歌是一个很棒的工具。
谷歌有谷歌翻译。

这是一个代码示例,您需要对其进行更改才能适合您正在做的事情。

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

Google is an amazing tool to use when looking for something like this.
Google has Google Translate.

here is a code example you will need to alter it to work for what it is you are doing.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文