首页 文章

多语言网站的优先语言

提问于
浏览
0

我正在按照本指南创建一个多语言页面:http://www.codeproject.com/Articles/334820/Using-Globalization-and-Localization-in-ASP-NET但问题是:我希望我的网站默认语言是印地语 . 但浏览器经常设置英语是默认语言 . 这是因为当我加载我的网站时,它的语言是英语,而不是印地语(我将印地语中的resx文件更改为default.aspx.resx并将英语resx文件更改为default.aspx.en-US.resx但浏览器仍然显示英语) . 如何设置默认我的网站默认语言是印地语?

代码:

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>

<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文件是:Default.aspx.resx,英文的Resx文件是Default.aspx.en-US.resx

谢谢,抱歉我的英语

1 回答

  • 2

    覆盖默认行为的一种方法是以编程方式设置文化,如 Global.asax 中的Application_OnStart,此函数将为每个新的唯一会话运行一次 .

    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("hi-IN");
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    

相关问题