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

ASP.NET
用ASP/ASP.NET实现网络空间管理
ASP.NET程序中用Repeater实现分页
在ASP.NET中上传图片并生成缩略图的C#源码
Asp.net动态生成html页面
DataGrid同时具有分页和排序功能及注意点
建立自己的RSS
Asp.net中处理一个站点不同Web应用共享Session的问题
创建完全可编辑的 DataGrid
调试ASP.NET应用程序的方法和技巧
让你的.NET程序兼容不同版本的Dll文件
用ASP.NET实现简单的文字水印
ASP.NET中实现中文简/繁体自动转换的类
ASP.NET技巧:为Blog打造个性日历
ASP.NET中使用IFRAME建立类Modal窗口
WEB页面多语言支持解决方案
涉及网络编程时,需要用到的几个常用方法
2个页面间不通过Session与url的传值方式
ASPX中的用户控件与ASP中的INCLUDE方法对比
使用HttpWebRequest向网站模拟上传数据
在asp.net中操作sql server数据库的一些小技巧

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 53 ::
收藏到网摘: 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'英文

这几个语言档吧