您现在的位置: IT专家网 > Web服务子站 > WebService领域
在ASP.NET 2.0中实现本地化
由于越来越多的跨国公司需要跨语言的WEB应用,所以本地化工作变得尤其重要,在ASP.NET 1.1 中我们使用ResourceManager 类来实现这个工作,而2.0中提供了更加方便的方法和工具来实现。
用程序读取方式如下:
| ImageButton button1 = new ImageButton();
// other initialization code button1.ID = "btnIDesign"; button1.AccessKey = (string) base.GetLocalResourceObject("ImageButtonResource1.AccessKey"); button1.AlternateText = (string) base.GetGlobalResourceObject("Glossary", "MissionStatement"); button1.ImageUrl = (string) base.GetLocalResourceObject("ImageButtonResource1.ImageUrl"); button1.ToolTip = (string) base.GetLocalResourceObject("ImageButtonResource1.ToolTip"); button1.Visible = (bool) base.GetLocalResourceObject("ImageButtonResource1.Visible", typeof(Control), "Visible"); |
Html控件:html控件不能用前面说的两种表达式来指定资源,除非是让它runat=server,不过对于页面的title比较特殊,它也会作为页面的一个对象自动生成本地资源
< %@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" meta:resourcekey="PageResource1" %>
不过,我们也可以为它制定全局资源
| < head runat="server">
< title> < asp:Literal Text='<% $ Resources: Glossary, DefaultPageTitle %>' runat="server"> < /title> < /head> |
对于项目中很多静态的文本,我们可以使用Localize控件来包含这些文字,其实这个控件和Literal相似,但是它能在设计模式下随意修改里面的文字内容,看下怎么访问本地资源和全局资源
| < asp:Localize id="welcomeContent" runat="server" meta:resourcekey="welcome">Welcome!< /asp:Localize>
< asp:Localize id="welcomeContent" runat="server" text='< %$ resources: Glossary, welcomeText%>'>Welcome!< /asp:Localize> |
- 本文关键词:

