DotNetNuke 本地化技术
2009-08-20 21:46
501 查看
<asp:Label ID="Label2" runat="server" Text="Input the Company Name" resourcekey="Label2Resource1"></asp:Label>label控件并没有resourcekey属性,而在dotnetnuke里面却可以根据这个属性获取资源文件里面相应的数据,这是为什么呢?
dotnetnuke里的每个aspx页面都是继承DotNetNuke.Framework.CDefault,CDefault同时又继承DotNetNuke.Framework.pagebase类。
cdfault类只包含一些简单的属性,我想应该在pagebase里面做了文章。研究了半天,终于确定的确是在这里实现根据resourcekey获取资源文件的内容。
Private Overloads Sub IterateControls(ByVal controls As ControlCollection, ByVal affectedControls As ArrayList, ByVal ResourceFileRoot As String) For Each c As Control In controls ProcessControl(c, affectedControls, True, ResourceFileRoot) Next End Sub 'IterateControls通过上面方法循环对页面中的控件进行处理,从资源文件获取resoucekey的value并把他赋给控件,例如label控件,设
label.Text=value,处理方法为:
Friend Sub ProcessControl(ByVal c As Control, ByVal affectedControls As ArrayList, ByVal includeChildren As Boolean, ByVal ResourceFileRoot As String)获取resourcekey的value的方法是:
value = Services.Localization.Localization.GetString(key, ResourceFileRoot)而怎样获取方法中的key呢?比如就是获取顶端的resoucekey的值Label2Resource1,方法如下:
Dim key As String = GetControlAttribute(c, affectedControls)
方法完整代码如下:
Friend Shared Function GetControlAttribute(ByVal c As Control, ByVal affectedControls As ArrayList) As String Dim ac As System.Web.UI.AttributeCollection = Nothing Dim key As String = Nothing If TypeOf c Is LiteralControl Then ' LiteralControls don't have an attribute collection key = Nothing ac = Nothing Else If TypeOf c Is WebControl Then Dim w As WebControl = DirectCast(c, WebControl) ac = w.Attributes key = ac(Services.Localization.Localization.KeyName) Else If TypeOf c Is HtmlControl Then Dim h As HtmlControl = DirectCast(c, HtmlControl) ac = h.Attributes key = ac(Services.Localization.Localization.KeyName) Else If TypeOf c Is UserControl Then Dim u As UserControl = DirectCast(c, UserControl) ac = u.Attributes key = ac(Services.Localization.Localization.KeyName) ' Use reflection to check for attribute key. This is a last ditch option Else Dim controlType As Type = c.GetType() Dim attributeProperty As PropertyInfo = controlType.GetProperty("Attributes", GetType(System.Web.UI.AttributeCollection)) If Not attributeProperty Is Nothing Then ac = DirectCast(attributeProperty.GetValue(c, Nothing), System.Web.UI.AttributeCollection) key = ac(Services.Localization.Localization.KeyName) End If End If End If End If ' If the key was found add this AttributeCollection 'to the list that should have the key removed during Render End If If Not key Is Nothing And Not affectedControls Is Nothing Then affectedControls.Add(ac) End If Return key End Function 'GetControlAttribute先验证控件类型,然后获取控件属性集合,从中获取keyname的value,keyname就是“resourcekey”。
就这么多了,
然后简要介绍dotnetnuke本地化方法:
如何使用aspx页面本地化资源文件?
直接在控件中加resourcekey属性,如:
<asp:Label ID="Label2" runat="server" Text="Input the Company Name" resourcekey="Label2Resource1"></asp:Label><br />resourcekey可以为例中的Lable2Resource1,也可以为Lable2Resource1.Text。
如何使用用户控件ascx页面的资源文件?
使用方法:
Label2.Text = Services.Localization.Localization.GetString("label2", Services.Localization.Localization.GetResourceFile(Me, MyFileName))即可。
相关文章推荐
- dotnetnuke 本地化技术杂谈
- Dotnetnuke的本地化
- dotnetnuke中文本地化加入中国货币和政区
- 【收藏】本周ASP.NET英文技术文章推荐[??/?? - 09/22]:VS 2008、.NET 3.5、asp:ListView、DotNetNuke、ASP.NET AJAX
- PSP团队、开源事业、DotNetNuke(DNN)中国本地化的一些情况
- 请下载DotNetNue的技术文档DotNetNuke Code Access Security中文翻译稿
- dotnetnuke 5.5.0 alpha版 内容本地化
- DotNetNuke 5.5.0终于发布了,支持内容本地化
- 本周ASP.NET英文技术文章推荐[??/?? - 09/22]:VS 2008、.NET 3.5、asp:ListView、DotNetNuke、ASP.NET AJAX
- 一起谈.NET技术,DotNetNuke 5 C#版本解读之--架构介绍
- 本周ASP.NET英文技术文章推荐[??/?? - 09/22]:VS 2008、.NET 3.5、asp:ListView、DotNetNuke、ASP.NET AJAX
- DotNetNuke 5 C#版本解读之3--DNN Membership
- DotNetNuke(DNN)3.0.4 Public Beta完全体验研究(2)-对比2.x真实改进
- DotNetNuke和SharePoint的比较(翻译)
- DotNetNuke独立项目模块开发资源引用路径设置
- DotNetNuke
- DNN(DotNetNuke)研究手札系列
- DotNetNuke - DNN中文搜索解决方案 (附下载)
- 在web host 的DotNetNuke中添加连接时出现的错误及解决办法
- 忘记DotNetNuke的host密码?-如何恢复丢失的DNN密码