CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

您现在的位置: IT专家网 > Web服务子站 > WebService领域

在ASP.NET 2.0中实现本地化

作者: 佚名,  出处:中国IT实验室, 责任编辑: 包春林, 
2008-05-15 04:00
  由于越来越多的跨国公司需要跨语言的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控件: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>

共5页。 9 1 2 3 4 5 :

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅

       
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i