1、这里介绍的是实现中文和英文的切换。首先多语言的实现是采用资源文件的形式,建立2个多语言的资源文件。Resource.resx和Resource.zh-CN.resx。
2、将多语言这个属性放到用户类中去。
public class TUserModels { public string UserName { get; set; } public string Password { get; set; } public string RoleKey { get; set; } public string Email { get; set; } public bool IsDisabled { get; set; } public string CurrentCulture { get; set; } }
3、由于写了一个BasePage 继承 System.Web.UI.Page,所以在BasePage InitializeCulture方法中
string lang = Request.QueryString["currentculture"]; if (lang == null) { lang = Lincoln3R.UI.Manager.UserSession.CurrentUser.CurrentCulture; } if (lang != CultureHelper.I18N_ZH_CN && lang != CultureHelper.I18N_EN_US) { lang = CultureHelper.I18N_EN_US; } Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang); Lincoln3R.UI.Manager.UserSession.CurrentUser.CurrentCulture = lang;
4、因为在login.aspx界面是System.Web.UI.Page的部分类,所以在login界面也要重写InitializeCulture方法。
protected override void InitializeCulture() { string lang = Request.QueryString["currentculture"]; if (lang == null) { lang = CultureHelper.GetDefaultCulture(); } if (lang != CultureHelper.I18N_ZH_CN && lang != CultureHelper.I18N_EN_US) { lang = CultureHelper.I18N_EN_US; } Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang); Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang); }
5、在Login的模版页面要写出这2个按钮
<div class="AccountHeader"> <span>V1.2</span> <% if (System.Threading.Thread.CurrentThread.CurrentUICulture.Name != Lincoln3R.Framework.I18N.CultureHelper.I18N_ZH_CN) { %> <span><a href="?currentculture=<%=Lincoln3R.Framework.I18N.CultureHelper.I18N_ZH_CN %>" title="<%=Lincoln3R.Resources.Resource.Lbl_Chinese %>">CN</a></span> <%} else { %> <span><a href="?currentculture=<%=Lincoln3R.Framework.I18N.CultureHelper.I18N_EN_US %>" title="<%=Lincoln3R.Resources.Resource.Lbl_English %>">EN</a></span> <% } %> </div>
自此多语言调用完成。
时间: 2024-11-20 10:55:40