单击按钮时本地化应用程序
本文关键字:应用程序 本地化 按钮 单击 | 更新日期: 2023-09-27 17:57:14
我在我的项目主页母版页中找到了图像按钮:
<asp:ImageButton ID="RU" ImageUrl="/Images/RU.png" runat="server" onclick="RU_Click">
<asp:ImageButton ID="USA" ImageUrl="/Images/USA.png" runat="server" onclick="USA_Click" />
以下是 OnClick 函数:
protected void RU_Click(object sender, ImageClickEventArgs e)
{
Session["MyCulture"] = CultureInfo.CreateSpecificCulture("ru-RU");
Server.Transfer(Request.Url.LocalPath);
}
protected void USA_Click(object sender, ImageClickEventArgs e)
{
Session["MyCulture"] = CultureInfo.CreateSpecificCulture("en-AU");
Server.Transfer(Request.Url.LocalPath);
}
我也有两个.resx文件,但我如何将按钮与
<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Main, Name%>" />
你的问题不清楚,但让我为你澄清一件事,这可能是你的问题。
您只能在InitializeCulture
事件中设置区域性:
protected override void InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-AU");
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-AU");
base.InitializeCulture();
}
使用以下代码:
protected void RU_Click(object sender, EventArgs e)
{
SetCulture("ru-RU");
}
protected void USA_Click(object sender, EventArgs e)
{
SetCulture("en-UA");
}
public static void SetCulture(string culture)
{
CultureInfo cultureInfo = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
设置当前区域性,以便本地化可以生效。