【发布时间】:2011-12-02 15:01:43
【问题描述】:
我想将文本框值翻译成特定语言,如西班牙语、中文、德语等,它们都在下面的下拉列表中,我想在标签中显示文本框翻译值,但不在标签中显示翻译值。
<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;
}
【问题讨论】:
-
您是否需要自动翻译功能? .NET 框架中没有这样的东西,本地化提供了完全不同的功能。
标签: c# asp.net globalization