I'm following this guide to create a multi language page : http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET But a problem is : I want my website default language is Hindi. But the browser often set English is default language. That cause when I load my site, the language on it is English, not Hindi (I change resx file in Hindi to default.aspx.resx and change English resx file to default.aspx.en-US.resx but the browser still display English). How can I set default my website default language is Hindi ?
Code :
default.aspx :
<form id="form1" runat="server">
<div>
<asp:Label ID="lblWelcome" runat="server" meta:resourcekey="lblWelcomeResource1"
Text="Welcome to Learning"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="hi-in">हिंदी</asp:ListItem>
<asp:ListItem Value="en-us">English</asp:ListItem>
</asp:DropDownList><br />
<br />
<asp:Label ID="lblNotice" runat="server" meta:resourcekey="lblNoticeResource1" Text="Today is:"></asp:Label>
<asp:Label ID="lblTime" runat="server" meta:resourcekey="lblTimeResource1"></asp:Label></div>
</form>
Default.aspx.cs :
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToShortDateString();
}
protected override void InitializeCulture()
{
if (Request.Form["DropDownList1"] != null)
{
UICulture = Request.Form["DropDownList1"];
Culture = Request.Form["DropDownList1"];
}
base.InitializeCulture();
}
Resx file in Hindi is : Default.aspx.resx and Resx file in English is Default.aspx.en-US.resx
Thanks and sorry for my English
One way to override the default behaviour is to set the culture programmatically like in Application_OnStart in Global.asax
, this function will run once for every new unique session.
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("hi-IN");
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;