加入两个不同的资源包

时间:2017-09-25 08:32:41

标签: jsf internationalization resourcebundle

我们已经创建了一个基础jsf项目,其中包含所有常用功能和实用程序,这些功能和实用程序将用作其余应用程序的框架。因此,所有新应用程序都将导入此应用程序。

我们正面临国际化的问题。

父应用程序将有一个消息文件,其中包含可能对所有项目通用的所有字符串 com.parent.i18n.messages

mandatory-field=Field is mandatory
numeric-field=Field must be numeric
...

将使用父项目的应用程序将拥有自己的i18文件以及特定于应用程序的消息

com.child.i18n.messages

add-customer=Add customer
delete-customer=Delete customer
...

应用程序的faces-config.xml将包含两个文件

<!-- Parent messages -->
<resource-bundle>
    <base-name>com.parent.i18n.messages</base-name>
    <var>msgbase</var>
</resource-bundle>
<!-- Application messages -->
<!-- Include base i18n for the wms-base pages -->
<resource-bundle>
    <base-name>com.child.i18n.messages-base</base-name>
    <var>msg</var>
</resource-bundle>

从视图中我可以轻松地将这些属性称为:

<h:outputText value="#{msg['add-customer']}" />
<h:outputText value="#{msgbase['mandatory-field']}" />

我们想要实现的是能够引用资源包而不知道消息是在父项目上还是在项目本身中,例如:

<h:outputText value="#{allmsg['add-customer']}" />
<h:outputText value="#{allmsg['mandatory-field']}" />

有没有办法实现这个目标?

0 个答案:

没有答案
相关问题