English 中文(简体)
为什么这条本地化路线会这样?
原标题:Why does this line of localization behave this way?

我正在本地化一个ASP.NET网站。通常,为了本地化.aspx页面中的文本,我只使用

<;%=Resources.ResourceFile.ResourceName%>

对于asp.net控件,这是行不通的。我必须使用语法

<;%$资源:资源文件,资源名称%>

但是,如果我有一个按钮,并以这种方式本地化Text属性,但在其后面添加任何其他字符,则本地化将中断,并显示为纯文本。

So Text="<%$ Resources:ResourceFile, ResourceName %> &raquo;" displays as
<%$ Resources:ResourceFile, ResourceName %> »

我确信这是有正当理由的,我只是在MSDN上找不到关于Text属性如何评估这一点的解释。我甚至不能100%确定<;%$实际上做到了。

最佳回答

发生的情况是ASP.net正在调用表达式生成器。这里有效地发生的是,ASP.net编译器没有翻译您的:

<asp:AControlWithATextProperty runat="server" Text="Some Text">

收件人:

AControlWithATextProperty ctl1 = new AControlWithATextProperty();
ctl1.Text = "Some Text";

当它将.aspx文件中的标记转换为.cs与代码隐藏相结合的文件时,它实际上会执行类似的操作:

<asp:AControlWithATextProperty runat="server" Text="<%$ Resources:ResourceFile, ResourceName %>">

成为:

AControlWithATextProperty ctl1 = new AControlWithATextProperty();
ctl1.Text = ResourceExpressionBuilder.EvaluateExpression("ResourceFile, Resourcename");

asp.net编译器似乎无法处理连接<code><;%$%的内容>标记,其中包含来自标记的属性中的任何其他文本。要么是错误,要么是故意的。即您最终不会得到ctl1.Text=ResourceExpressionBuilder.EvaluateExpression(“ResourceFile,Resourcename”)+“&;raquo;”

您可以阅读有关ResourceExpressionBuilder在msdn上,ExpressionBuilder一般来说,或者如果您真的想这样做的话;一个用于本地化的实现(数据库支持,因此我没有使用ResourceExpressionBuilder)关于我的博客(3部分)。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!