多国语言系统实现基本原理

资源文件结构:

 

App_GlobalResources

    -> Default.resx

    -> Default.en.resx

 

App_LocalResources

    -> Default.aspx.resx

    -> Default.aspx.en.resx

 

Default.aspx

 

 

页面Html:

中文 English
调用全局资源文件:<%= GetGlobalResourceObject("Default","welcome").ToString() %>
调用局部资源文件:<%= GetLocalResourceObject("answer").ToString() %>

 

后台Code:

using System.Globalization; using System.Threading; public partial class _Default : System.Web.UI.Page { protected override void InitializeCulture() { string language = Request.Form["ddlLanguage"]; //为空(默认显示中文) if (string.IsNullOrEmpty(language)) { //Thread.CurrentThread.CurrentUICulture = new CultureInfo(""); } //不为空(下拉框有回传,显示相应语言) else { Thread.CurrentThread.CurrentUICulture = new CultureInfo(language); } base.InitializeCulture(); } protected void Page_Load(object sender, EventArgs e) { } }

你可能感兴趣的:(C#,ASP.NET)