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

ASP.NET
用ASP.NET加密Cookie数据
用ASP.NET开发Web服务的五则技巧
ASP.NET数据库缓存依赖
ASP.Net开发者常见Datagrid错误
asp.net 2.0多语言网站解决方案
在ASP.NET中值得注意的两个地方
用.net静态变量取代Application 速度更快
ASP.NET图象处理详解(1)
ASP.NET图象处理详解(2)
使用JScript.NET创建asp.net页面
ASP.NET中水晶报表的使用
数据库连接字在Web.config里的用法
浅谈在ASP.NET中数据有效性校验的方法
ASPX页Web服务调用性能优化
从 PHP 迁移到 ASP.NET
ASP.NET中编程杀死进程
ASP.NET保持用户状态的九种选择(上)
ASP.NET保持用户状态的九种选择(下)
使用更精简的代码保证ASP.NET应用程序的安全
为ASP.NET应用缓存Oracle数据

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


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

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


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

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