如何将资源分组到资源包中?

发布于 2024-11-14 09:14:50 字数 454 浏览 2 评论 0原文

在资源包文件中对资源进行分组的最佳方法是什么?我看到最常见的是按网页对资源进行分组,一个例子是:

# -- company page 
company.name.lbl=Name: 
company.address.lbl=Address:

# -- contact page 
contact.name.lbl=Name: 
contact.email.lbl=Email: 

这样做的问题是许多同名的字段是重复的。那么您是否会建议识别所有常用名称并将它们单独分组?类似:

name.lbl=Name: 
address.lbl=Address: 
email.lbl=Email: 

当然这也有一些缺点,如果您想将公司名称标签更改为“公司名称”,那么您可能会无意中更改联系人姓名标签。当然,您应该为此创建一个新资源,但进行更改的人可能会忽略创建新资源。

What is the best approach for grouping resources in a resource bundle file? The one I see most common is to group resources by web page, an example would be:

# -- company page 
company.name.lbl=Name: 
company.address.lbl=Address:

# -- contact page 
contact.name.lbl=Name: 
contact.email.lbl=Email: 

The problem with this is that a lot of fields with the same name are duplicated. Would you then recommend identifying all the common names and group them separately? Something like:

name.lbl=Name: 
address.lbl=Address: 
email.lbl=Email: 

Of course this also has some drawbacks, if you want to change the company name label to 'Company Name' then it is possible you change the contact name label without meaning to. Of course you should create a new resource for this, but it is possible the person making the change might overlook creating a new resource.

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

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

发布评论

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

评论(2

娇柔作态 2024-11-21 09:14:50

我将保留前面按网页分组的示例,因为每个页面上显示的文本都有其自己单独的上下文。

您可以尝试保持事物干燥并识别所有常见文本,但是如果任何页面的上下文发生变化,您可能会发现自己创建了新资源,如果您将页面资源分开,那么您可能已经完成了这些操作。

将资源按页面分开的另一个原因是,如果您需要翻译资源,则创建翻译的上下文将是不言而喻的。这可以帮助您保持关注点的清晰分离,因此您的编码人员不必担心如何翻译单词,并且您的翻译人员也不必弄乱任何代码。

I would keep to the former example of grouping by web page, since the text displayed on each page has its own separate context.

You could try to keep things DRY and identify all of the common text, but should the context of any page change, you may find yourself creating new resources that you would have already done if you kept the page resources separate.

Another reason for keeping the resources separated by page is that if you ever need to translate your resources, the context for creating translations will be self-evident. That helps you keep a clean separation of concerns, so your coders will not have to worry about how words might be translated, and your translators will not have to mess with any code.

乖乖兔^ω^ 2024-11-21 09:14:50

第一个选项可能意味着重复文本,但更灵活。例如,如果公司名称与个人名称完全不同会怎样?或者,如果明天您的老板决定将公司名称的标签从“名称”更改为“公司名称”。

如果您使用第二个选项,您将失去使用资源包的大部分优势。

The first option may mean repeating texts, but is more flexible. What happens if, for example, company name is completely different from personal name? Or if tomorrow you boss decides that the label for the name of the company should change from "Name" to "Company name".

If you use the second option you are losing most of the advantages of using resource bundles.

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