0

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>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <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>&nbsp;
    <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

1 Answers1

2

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;
Vikrant
  • 4,920
  • 17
  • 48
  • 72
Daniel
  • 150
  • 11
  • I added that code to Global.asax. And Thread.CurrentThread.CurrentCulture on Global.asax = Thread.CurrentThread.CurrentUICulture = hi-IN but Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture on default.aspx still = en-US. How can I call session Culture from Global to default.aspx (defalt.aspx is not using a masterpage) – Duy Hưng Androgyne Tenor May 25 '15 at 03:05
  • Please provide us with your code and I'll have a look. The better you describe what you have tried to do, researched and encountered, the easier it is to give you a correct answer. – Daniel May 25 '15 at 06:28
  • I create a new page with a webform default.aspx like my question. I'd create a global.asax and add : <%@ Application Language="C#" %> <%@ Import Namespace="System.Threading" %> <%@ Import Namespace="System.Globalization" %> 2 files resx : default.aspx.resx in Hindi and default.aspx.en-US.resx in Eng. That's all – Duy Hưng Androgyne Tenor May 25 '15 at 06:47