扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:lovecherry 来源:博客园 2007年11月7日
关键字: Windows
<%$ resources: [applicationkey], resourcekey%> |
比如从Glossary.resx读取资源例子如下
<asp:ImageButton ID="btnIDesign" Runat="server" ImageUrl="~/Images/idesignlogo.jpg" AlternateText='<%$ Resources:Glossary, MissionSatatement%>' PostBackUrl="http://www.idesign.net" meta:resourcekey="ImageButtonResource1" /> |
当然你也可以直接用IDE的表达式对话框直接来选择
用程序读取方式如下:
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"></asp:Literal> </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> |
多语言实现:
|
从默认的资源文件复制一个新的的资源文件,只要在resx前面加上地区代号,逐项编辑即可,如下设置后浏览器会自动根据设置(工具-选项-语言)调用新的资源文件
<%@ Page UICulture="auto" Culture="auto"> |
当然你也可以通过web.config文件指定一种语言
<system.web> <globalization culture="es-ES" uiCulture="es"> </system.web> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者