在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
[- This article had been published on C# corner by me on June 29,2011 , now I want to share with all friends here! -] [- Original URL:http://www.c-sharpcorner.com/uploadfile/3a1c50/how-to-implement-web-application-localization-in-net-4-0/ -]
In this article, we will explore the necessary details for working with resources in ASP.NET applications and for creating international ASP.NET applications based on embedded resources and the integrated localization support.
Double-click it and you will see:
<asp:Button ID="ButtonLogin" runat="server" Text="Login" OnClick="ButtonLogin_Click"meta:resourcekey="ButtonLoginResource1" />
1 public partial class Login : System.Web.UI.Page 2 { 3 string strUserNameError; 4 } 5 protected void Page_Load(object sender, EventArgs e) 6 { 7 strUserNameError = Resources.Messages.strUserNameError.ToString(); 8 } 9 protected void ButtonLogin_Click(object sender, EventArgs e) 10 { 11 if (TextBoxUserName.Text == "") 12 { 13 ScriptManager.RegisterStartupScript(this, GetType(), "nameOrPwdError", "alert('" + strUserNameError + "');", true); 14 } 15 }
1 protected override void InitializeCulture() 2 { 3 if (Request.Form["DropDownListLogin"] != null) 4 { 5 string selectedLanguage = Request.Form["DropDownListLogin "]; Response.Cookies["EasyUpdateLanguage"].Value = selectedLanguage; 6 m_strLanguage = selectedLanguage; 7 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); 8 Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); 9 10 } 11 else if ( Request.Cookies["EasyUpdateLanguage"] != null ) 12 { 13 14 string selectedLanguage = Request.Cookies["EasyUpdateLanguage"].Value; 15 16 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); 17 Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); 18 } 19 base.InitializeCulture(); 20 }
Step 4 Wrap the code follow into a class (ChangeCulture):System.web.ui.page, Let other page's classes inherit ChangeCulture. 1 protected override void InitializeCulture() 2 { 3 if (Request.Form["ctl00$ctl00$ DropDownListMaster "] != null) 4 { 5 string selectedLanguage = Request.Form["ctl00$ctl00$DropDownListMaster"]; 6 Response.Cookies["EasyUpdateLanguage"].Value = selectedLanguage; 7 String m_strLanguage = selectedLanguage; 8 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); 9 Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); 10 } 11 else if (Request.Cookies["EasyUpdateLanguage"] != null) 12 { 13 string selectedLanguage = Request.Cookies["EasyUpdateLanguage"].Value; 14 Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(selectedLanguage); 15 Thread.CurrentThread.CurrentUICulture = new CultureInfo(selectedLanguage); 16 } 17 base.InitializeCulture(); 18 }
|
请发表评论