I am learning Asp.Net globalisation and localisation, and I found this example.
The example is working fine, but when I change the month in the calendar, the calendar text is automatically changing to English.
I tried it with
<asp:Calendar ID="Calendar1" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="language_Drp_SelectedIndexChanged">
</asp:Calendar>
But I am still having a problem. Can anyone help me?
The example you found is not a very good one. The correct place to set the culture in ASP.NET is to override the method InitializeCulture
. I normally implement that method in a common base class for all my web forms.
You could implement something like this:
protected override void InitializeCulture()
{
if (Session["locale"] != null)
{
string selectedLanguage = Session["locale"];
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage);
}
base.InitializeCulture();
}
Somewhere you have to store the selected language in the Session variable, e.g. like this:
Session["locale"] = langDropdown.SelectedValue;