首先建立语言档,在项目中加入.resx文件
例如:
message.zh-cn.resx '简体中文
message.zh-tw.resx '繁体中文
message.en '英文
..............

======================================================================
然后利用Name --Value 键值对 填入你要在页面上显示的语言
如:
name value
message.zh-cn.resx中:
res_loginbname 登陆名 :
message.zh-tw.resx中:
res_loginbname 登陸名 :
message.zh-cn.resx中:
res_loginbname Login Name :



======================================================================
然后在Golbal.asax中加入多语言设定支持代码(浏览器需要支持Cookie)

'=============================================================================================
' Application_BeginRequest Event
'
' The Application_BeginRequest method is an ASP.NET event that executes
' on each web request into the portal application.
'
' The thread culture is set for each request using the language
' settings
'
'=============================================================================================
protected void Application_BeginRequest(Object sender, EventArgs e)
  {
   try
   {
  
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(this.Request.UserLanguages[0]);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.Request.UserLanguages[0]);
   }
   catch(Exception ee)
   {
    ee=null;
    String strDefaultCulture=System.Configuration.ConfigurationSettings.AppSettings["DefaultCulture"];
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(strDefaultCulture);
   }


  }

在Web.Config中加入如下代码,用于设定编码和默认语种,在Global.asax中有调用:

======================================================================
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
  <appSettings>
       <add key="DefaultCulture" value="zh-cn" />
       <add key="strResource" value="WebApplication1.message"/>//WebApplication1为工程名
  </appSettings>


======================================================================
页面代码中使用多语言支持:

private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   String strResource=System.Configuration.ConfigurationSettings.AppSettings["strResource"];
   ResourceManager MultiLanguageSource = new System.Resources.ResourceManager(strResource,Assembly.GetExecutingAssembly());
   CultureInfo ci = new CultureInfo("en");//显示英文,默认为中文
   lLoginName.Text=MultiLanguageSource.GetString("loginName",ci);
  }

======================================================================

到这里多语言支持的工作就作完了,接下来自己去慢慢Key
message.zh-cn.resx '简体中文
message.zh-tw.resx '繁体中文
message.en '英文

这几个语言档吧,这是一个痛苦的回忆!


语言的后缀 如:
zh-cn'简体中文
zh-tw'繁体中文
en '英文

可以参考 IE选项---网际网络设定--〉一般选项卡语言--〉新增里边的内容

posted on 2007-08-08 09:15  LanceLang  阅读(120)  评论(0)    收藏  举报
使用Live Messenger联系我
关闭