I am implementing a way for a user to toggle the language shown (en || es). I have the following:
<asp:LinkButton ID="Lnk_cultChange" runat="server" Text="<%$Resources:mySource, cultbtn%>" OnClick="cultChange_Click" />
Code behind:
protected void cultChange_Click(object sender, EventArgs e)
{
if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en")
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES");
base.InitializeCulture();
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
base.InitializeCulture();
}
}
There is a postback, but nothing appears to happen. The English resource file is still displaying and no translation is made. Is my implementation correct?
Just like @Umriyaev suggested you have to override the InitializeCulture()
and use that to pull the culture after another redirection. See here https://stackoverflow.com/a/10672476/2596756