欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【WEB页面多语言支持解决方案】,下面是详细的分享!
WEB页面多语言支持解决方案
首先建立语言档,在项目中加入.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'英文
这几个语言档吧
以上所分享的是关于WEB页面多语言支持解决方案,下面是编辑为你推荐的有价值的用户互动:
相关问题:如何实现WEB系统的多页同时显示
答:a和b页面之间的关系是什么? 他们之间需要有个关系,比如a是父页面,b是通过a打开的子页面,这样的话在a中的点击内容可以通过父页面和子页面之间的关系中b中呈现出来,反之亦然。 父页面和子页面的交互lz可以百度,网上大把,内容比较多,我就不... >>详细
相关问题:web开发语言有哪些?
答:ASP全名Active Server Pages,是一个WEB服务器端的开发环境,利用它可以产生和执行动态的、互动的、高性能的WEB服务应用程序。ASP采用脚本语言VBScript(Java script)作为自己的开发语言。 PHP是一种跨平台的服务器端的嵌入式脚本语言。它大量... >>详细
相关问题:目前常用的WEB标准静态页面语言是
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
