简体   繁体   English

i18n找不到语言环境属性

[英]i18n can not find locale properties

java.util.MissingResourceException: Can't find bundle for base name xxx.i18n.base, locale en_US

I am currently implementing i18n, using Facelets. 我目前正在使用Facelets实现i18n。 I have three .properties files: 我有三个.properties文件:

  • xxx.i18n.base.properties xxx.i18n.base.properties
  • xxx.i18n.base_en_US.properties xxx.i18n.base_zh_CN.properties
  • xxx.i18n.base_nl_NL.properties xxx.i18n.base_nl_NL.properties

faces-config.xml faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">

    <application>
        <locale-config>
            <default-locale>nl_NL</default-locale>
            <supported-locale>en_US</supported-locale>
        </locale-config>
        <resource-bundle>
            <base-name>xxx.i18n.base</base-name>
            <var>base</var>
        </resource-bundle>
    </application>
</faces-config>

As the error stated, I have trouble locating the en_US file, but when I set my locale for nl_NL, it can not be found either. 如错误所述,我在查找en_US文件时遇到了麻烦,但是当我为nl_NL设置语言环境时,也找不到该文件。 Finally, putting the locale to something like de_DE will give me this result for de_DE, even though this locale is not defined as supported. 最后,将语言环境设置为类似de_DE的方法将为我提供de_DE的结果,即使该语言环境未定义为受支持。

I'm using the following syntax to retreive values from the .properties files 我正在使用以下语法从.properties文件检索值

#{base['msg']}

Does anyone have any idea as to why my application can not seem to find these locale files? 有谁知道为什么我的应用程序似乎找不到这些语言环境文件?

If you default locale is "nl_NL", so please change your faces-config.xml likes this. 如果您的默认语言环境是“ nl_NL”,那么请像这样更改faces-config.xml。

    <application>
      <locale-config>
        <default-locale>nl_NL</default-locale>
        <supported-locale>en_US</supported-locale>
      </locale-config>
      <resource-bundle>
        <base-name>xxx.i18n.base_nl_NL</base-name>
        <var>msg</var>
      </resource-bundle>
   </application>

And also make sure the path of properties files is correct or not. 还要确保属性文件的路径正确与否。

Seems that I had located my properties files in the wrong folder: java/xxx/i18n instead of resources/xxx/i18n 似乎我将属性文件放在错误的文件夹中:java / xxx / i18n而不是resources / xxx / i18n

After replacing the properties files my problem was solved. 替换属性文件后,我的问题解决了。 Everyone thanks for your help though! 大家都感谢您的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM