asp.net中的多語言使用

类别:.NET开发 点击:0 评论:0 推荐:

private ResourceManager MultiLang = new ResourceManager("Demo.Languages.test", Assembly.GetExecutingAssembly());
 //Web站台名.放置多語方的目錄.要使用的語言包(會自動根據進程的語言狀態選擇test.zh-tw.resx,test.zh-cn.resx,test.en-us.resx,......)

  private void Page_Load(object sender, System.EventArgs e)
  {
       if (!IsPostBack)
       {
            if (Session["Language"] == null)
            {
                 if (Request.Cookies["Lan"] != null)
                 {
                      Session["Language"] = Request.Cookies["Lan"].Value;    //暫存當前用戶所選擇的語言
                 }
                 else
                 {
                      Session["Language"] = "en-us";
                 }
            }
            this.ci = new CultureInfo(Session["Language"].ToString());
            Thread.CurrentThread.CurrentUICulture = this.ci;
             txtA.Text = MultiLang.GetString("txtA");  //在語言包中設置的txtA的值
       }
}

本文地址:http://com.8s8s.com/it/it43723.htm