当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > WEB页面多语言支持解决方案

ASP.NET
Asp.Net使用POST方法最简单的实现
实现.NET应用程序的自动更新
优秀ASP.NET程序员修炼之路
ASP.NET中实现模板页
在ASP.Net 2.0中实现多语言界面的方法
小议优化ASP.NET应用性能之Cache篇
.net开发投票机的思路
浅析CMS内容管理系统的两种方案
ASP.NET 2.0中动态修改页面标题
“您无权查看该网页”的原因和解决方法
将一个图片按比例缩放显示在一个Frame中
编程使用资源文件实现多语言页面(In Action)
.Net编程的多个小技巧
asp.net2.0学习历程-菜鸟到中级程序员的飞跃
asp.net如何连接sql server2000数据库
FCKeditor 2.6在ASP.NET中的配置方法
使用ASP.NET开发移动通讯的几种方法
ASP.NET 2.0的URL映射的实现方法
如何在Asp.net中使用HtmlArea编辑器
ASP.NET 2.0 中实现跨页提交

ASP.NET 中的 WEB页面多语言支持解决方案


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 67 ::
收藏到网摘: n/a

首先建立语言档,在项目中加入.resx文件
例如:
message.zh-cn.resx'简体中文
message.zh-tw.resx'繁体中文
message.en'英文
..............
=========================================
然后利用Name--Value键值对填入你要在页面上显示的语言
如:
namevalue
message.zh-cn.resx中:
res_loginbname登陆名:
message.zh-tw.resx中:
res_loginbname登陸名:
message.zh-cn.resx中:
res_loginbnameLoginName:

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

'=========================================
'Application_BeginRequestEvent
'
'TheApplication_BeginRequestmethodisanASP.NETeventthatexecutes
'oneachwebrequestintotheportalapplication.
'
'Thethreadcultureissetforeachrequestusingthelanguage
'settings
'
'=========================================
SubApplication_BeginRequest(ByValsenderAsObject,ByValeAsEventArgs)
Try
IfNotRequest.Cookies("resource")IsNothingOrRequest.Cookies("resource").Value=""Then
Thread.CurrentThread.CurrentCulture=CultureInfo.CreateSpecificCulture(Request.Cookies("resource").Value)
Else
Thread.CurrentThread.CurrentCulture=NewCultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
EndIf
Thread.CurrentThread.CurrentUICulture=Thread.CurrentThread.CurrentCulture
CatchexAsException
Thread.CurrentThread.CurrentCulture=NewCultureInfo(ConfigurationSettings.AppSettings("DefaultCulture"))
EndTry
EndSub'Application_BeginRequest

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

=========================================
<globalizationrequestEncoding="utf-8"responseEncoding="utf-8"/>
<appSettings>
<addkey="DefaultCulture"value="zh-cn"/>
<!--zh-cn:簡體中文zh-tw:繁體中文en:英文-->
</appSettings>

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

ImportsSystem.Resources

PublicClass类名
InheritsSystem.Web.UI.Page
ProtectedLocRMAsResourceManager=NewResourceManager("项目文件名.message",GetType(类名).Assembly)

PrivateSubPage_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
lblLogin.Text=LocRM.GetString("res_login")
EndSub
EndClass


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

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

这几个语言档吧