存储在资源文件中的HTML标签的最佳实践/技巧 [英] best practices / tips for storing html tags in resource files

查看:188
本文介绍了存储在资源文件中的HTML标签的最佳实践/技巧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情形:假设我有以下格式显示的数据。

I have the following situation: assume I have to display the data in the following format.

我20岁。我需要数20为粗体。

I am 20 years old. I need the number 20 to be in bold.

我从获取这样的资源文件,这个字符串

I'm fetching this string from a resource file like this

string.Format(HttpContext.GetGlobalResourceObject("ResourceFile","Key"),age);



我应该考虑添加标签< B> < / b> 资源文件中?这算是一个最佳实践?任何人都可以提供本地化有用的链接呢?

Should I consider adding the tags <b> and </b> within the resource file? Is that considered a "best practice"? Could anyone provide useful links on localization as well?

推荐答案

有关代码/数据/演示分离的目的,我建议你不要储存标签的资源文件。这将使其难以维持(由具有ASPX标签/ ASCX文件以及资源,甚至在DB)

Don't store tags that change visual style in resources

For code/data/presentation separation purposes I suggest you don't store tags in your resource file. It will make it harder to maintain (by having tags in aspx/ascx files as well as in resources and maybe even in the DB)

您应该遵循的分离关注模式,让事情分开。

You should follow separation of concerns pattern and keep things separated.

Key        Value
"UserAge"  "It seems you are {0} year(s) old."



有些松散的限制可能会帮助

,而使用一些嵌套标记的时候最安全的事情是有标记,不提供任何造型本身。在你的情况我会使用<跨度> 标记最多(因为它是一个内联样式而这正是你所需要的)。 。CSS将定义它到底视觉表达中

Some loose restrictions may help
But when using some nested markup the most safe thing to do is having tags that don't provide any styling per se. In your case I'd use <span> tag at most (because it's an inline style and that's exactly what you need). CSS would define it's visual representaion in the end.

Key        Value
"UserAge"  "It seems you are <span>{0}</span> year(s) old."



但你应该了解的含义。这样做,这样还可能会比具有根本没有标签更糟。想象一下,当你改变你的表示层会发生什么。让我们以一个服务或Windows桌面应用程序说。标签,如<跨度> 目前在这方面没有任何意义。它们可以被省略,但是为什么你把他们摆在首位即可。

But you should understand the implications. Doing it this way may still be worse than having no tags at all. Imagine what happens when you change your presentation layer. Let's say to a Service or a Windows desktop app. tags like <span> present no meaning in this context. They can be omitted, but why would you put them in in the first place then.

这篇关于存储在资源文件中的HTML标签的最佳实践/技巧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆