ASP.NET 中内联标记的全球化差异

发布于 2024-11-07 12:19:26 字数 316 浏览 6 评论 0原文

使用内联写入标签而不是资源标签有什么优点/缺点吗?示例:

<%=Resources.Site.SampleString %>

在任何 MSDN 示例中看到的资源标记(表达式标记):

<asp:Literal id="Literal1" runat="server" text="<%$ Resources:Site, SampleString %>" />

我发现第一个选项更容易使用,并且它具有 IntelliSense,但也许它的功能不一样?

Is there any advantage/downfalls between using the inline write tag instead of the resource tag? Example:

<%=Resources.Site.SampleString %>

The resources tag (expression tag) as seen in any MSDN example:

<asp:Literal id="Literal1" runat="server" text="<%$ Resources:Site, SampleString %>" />

I find the first option far easier to use, and it has IntelliSense, but maybe it won't function the same?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我纯我任性 2024-11-14 12:19:26

这些方法的功能完全相同。后者只是调用第一个;在后台生成强类型资源访问代码是有原因的。因此,您可以使用任何您喜欢的方法。

顺便说一句,还有另一种方法 - 通过使用 meta:resourcekey 属性。所以你应该能够写:

<asp:Literal id="Literal1" runat="server"
             meta:resourcekey="SampleString" text="Default one" />

并且一切都应该完全相同。

编辑隐式本地化。

我忘记提到的是,使用 meta:resourcekey 必须满足某些条件。条件是:

  • 值取自 App_LocalResources,因此需要存在相关资源文件
  • 相关资源文件名必须为 pagename.resx,例如:Default.aspx.resx、Default.aspx.es.resx
  • 资源文件必须包含以下键形式的resourcekey.propertyname,例如SampleString.Text,SampleString.ID(尽管我不会本地化控件ID)
  • 由于资源的生成方式,上述密钥必须存在于不变资源文件(Default.aspx.resx)中,否则它不会被本地化。

These methods will function exactly the same. The latter simply calls first one; there is a reason why strongly-typed resources access code is being generated in the background. Therefore you can use whatever method you please.

By the way, there is also another way - by using meta:resourcekey attribute. So you should be able to write:

<asp:Literal id="Literal1" runat="server"
             meta:resourcekey="SampleString" text="Default one" />

and it all should work exactly the same.

EDIT on implicit Localization.

What I forgot to mention, is that with meta:resourcekey certain conditions have to be met. The conditions are:

  • Values are taken from App_LocalResources, therefore related resource file need to exist
  • Related resource file name must be pagename.resx, for example: Default.aspx.resx, Default.aspx.es.resx
  • The resource file must contain keys in form of resourcekey.propertyname, for example SampleString.Text, SampleString.ID (although I wouldn't localize control ID's)
  • Because of how resources are generated, the key mentioned above must exist in invariant resource file (Default.aspx.resx), or it won't be localized.
旧时光的容颜 2024-11-14 12:19:26

一段时间后我意识到 <%=Resources.Site.SampleString %> 方法没有设计器支持(这是可以理解的)。这并不困扰我,但这是一个区别(对于未来的读者)。

因此,如果您需要或想要设计师支持,则需要第二种选择。

I realised after some time that the <%=Resources.Site.SampleString %> method does not have designer support (which is understandable). This doesn't bother me, but it is a difference (for future readers).

So if you need or want designer support, the second option would be necessary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文