不带_xx的JSF / Seam messages.properties是哪种语言?

| 我只是想知道默认的messages.properties被读取为哪种语言。 我认为这是在faces-config.xml中配置的默认语言环境是:
<locale-config>
  <default-locale>de</default-locale>
  <supported-locale>de</supported-locale>
  <supported-locale>en</supported-locale>
</locale-config>
它不包含“ 1”标记,我创建了messages.properties,messages_en.properties和messages_de.properties。要访问值,我使用此代码
ResourceBundle resourceBundle = SeamResourceBundle.getBundle();
String bundleMessage = resourceBundle.getString(\"key.something\");
在菜单中,我用它来显示(和切换)语言,什么有效
<h:selectOneMenu value=\"#{localeSelector.localeString}\">
  <f:selectItems value=\"#{localeSelector.supportedLocales}\"/>
</h:selectOneMenu>
现在我选择哪种语言都没有关系,je始终使用messages.properties,而不使用_de或_en。我是否需要
<message-bundle>
的具体类才能找到_de和_en资源束? 编辑:
ResourceBundle resourceBundle = SeamResourceBundle.getBundle();
java.util.Locale locale = resourceBundle.getLocale();
始终包含正确的语言环境,但始终使用messages.properties,并且如果删除了此文件,则仅返回密钥,就好像他没有找到其他文件一样。消息* .properties位于/ WEB-INF / classes文件夹中。 我现在尝试取
Map<String, String> messages = org.jboss.seam.international.Messages.instance();
,它还包含来自messages.properties的值,而不是_de或_en 在* .xhtml文件中使用
#{messages[key.label]}
还仅返回messages.properties值,而不返回_de或_en。 但是直接在xyz.war文件中使用
<a4j:loadBundle var=\"i18n\" basename=\"messages\"/>
的messages_de属性或_en确实可以工作。 (这就是我在\“ not Java \”前端中执行i18n的方式) 再进行两次尝试总是仅返回默认属性,而不返回_de或_en
resourceBundle =  context.getApplication().getResourceBundle(context, \"messages\");

java.util.Locale locale = new java.util.Locale(\"de\");
resourceBundle = ResourceBundle.getBundle(\"messages\",locale);
如果我创建一个新的messages2_de.properties和* _en *并使用上​​面的代码,则一切正常。
java.util.Locale locale = new java.util.Locale(\"de\");
resourceBundle = ResourceBundle.getBundle(\"messages2\",locale);
    
已邀请:
        编辑(显然,JBoss Seam有点不同) 如本文档所述,您可能不应该自己实例化bundle。 相反,您将定义要使用的包,并让Seam为您读取消息:
@In(\"#{messages[\'Hello\']}\") private String helloMessage;
通常,如果省略
Locale
参数,则任何
ResourceBundle
派生实现中的
getBundle()
方法都将给出不变的包。这是设计使然。 如果需要访问本地化版本,则需要从UIViewRoot获取语言环境:
Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
ResourceBundle resourceBundle = SeamResourceBundle.getBundle();
String bundleMessage = resourceBundle.getString(\"key.something\");
我不知道您的localeSelector bean是如何编码的,但是它也应该在UIViewRoot中设置Locale。     
        通常,如果在当前语言的任何更特定的捆绑软件中都没有找到键,则不带_xx的捆绑软件就是该捆绑软件。 尽管我不知道SeamResourceBundle到底能做什么,但是您必须在某处告诉它“当前”语言是什么。您说切换语言有效,但是切换后您会怎么做?您在什么时候执行
SeamResourceBundle.getBundle()
? 实际上在所有3个捆绑包中都定义了“ 17”吗?     
        我的错。您找不到错误。该项目在/ WEB-INF / classes中有一个messages.properties,在Web内容目录中直接有第二个具有相同名称的集合(但没有默认属性)。 所以我猜他是从classes文件夹中获取了仅有的默认defaults.properties,从web-content文件夹中获取了messages_de / en.properties。     

要回复问题请先登录注册