Localize the application at the click of a button

In my mainMaster project, my page found imageButtons buttons:

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

here are the OnClick Functions:

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

In addition, I have two .resx files, but how can I associate buttons with buttons

<asp:Literal ID="Literal1" runat="server" Text="<%$ Resources:Main, Name%>" />
+3
source share
2 answers

Your question is not clear, but let me clarify one thing for you, which may be your problem.

You can set Culture only in the event 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();
}
+1
source

Use this code:

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

to establish a current culture so that localization can take effect.

-1
source

All Articles