Resin3x 中的 ResourceBundle 后备分辨率是否已损坏?

发布于 2024-08-23 13:17:16 字数 2082 浏览 9 评论 0原文

给定以下 ResourceBundle 属性文件:

  1. messages.properties
  2. messages_en.properties
  3. messages_es.properties
  4. messages_{some locale}.properties

注意:messages.properties 包含默认区域设置的所有消息。 messages_en.properties 实际上是空的 - 它只是为了正确性而存在。 messages_en.properties 将回退到 messages.properties!

并在 web.xml 中给出以下配置参数:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>messages</param-value>
</context-param>

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
    <param-value>en</param-value>
</context-param>

我希望如果所选区域设置是“es”,并且资源未翻译为“es”,那么它将回退到“en”,最后回退到“messages” .properties'(因为 messages_en.properties 为空)。

这就是 Jetty 中的工作方式。我还在 WebSphere 上对此进行了测试。

Resin 是问题

问题出在我使用 Resin (3.0.23) 时。后备分辨率根本不起作用!为了显示消息,我必须执行以下操作:

  1. messages.properties 重命名为 messages_en.properties(本质上,交换 messages.properties 和 messages_en.properties 的内容)
  2. 将 messages_en.properties 也在 messages_{every other locale}.properties 中定义(即使完全相同)。

如果我不这样做,我会得到“???some.key???”在 JSP 中。

请帮忙!这令人费解。

-- LES

解决方案

将以下内容添加到 pom.xml (如果您使用的是 maven)

...
<properties>
    <taglibs.version>1.1.2</taglibs.version>
</properties>
...

    <!--
        Resin ships with a crappy JSTL implementation that doesn't work with
        fallback locales for resource bundles correctly; we therefore include
        our own JSTL implementation in the WAR, and avoid this problem. This
        can be removed if the target container is not resin.
    -->
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>${taglibs.version}</version>
        <scope>compile</scope>
    </dependency>

Given the following ResourceBundle properties files:

  1. messages.properties
  2. messages_en.properties
  3. messages_es.properties
  4. messages_{some locale}.properties

Note: messages.properties contains all the messages for the default locale. messages_en.properties is really empty - it's just there for correctness. messages_en.properties will fall back to messages.properties!

And given the following config params in web.xml:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>messages</param-value>
</context-param>

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
    <param-value>en</param-value>
</context-param>

I would expect that if the chosen locale is 'es', and a resource is not translated in 'es', then it would fall back to 'en', and finally to 'messages.properties' (since messages_en.properties is empty).

This is how things work in Jetty. I've also tested this on WebSphere.

Resin Is the Problem

The problem is when I get to Resin (3.0.23). Fallback resolution does not work at all! In order to get an messages to display, I must do the following:

  1. Rename messages.properties to messages_en.properties (essentially, swap the contents of messages.properties and messages_en.properties)
  2. Make sure ever key in messages_en.properties is also defined in messages_{every other locale}.properties (even if the exact same).

If I don't do this, I get "???some.key???" in the JSPs.

Please help! This is perplexing.

--
LES

SOLUTION

Add following to pom.xml (if you're using maven)

...
<properties>
    <taglibs.version>1.1.2</taglibs.version>
</properties>
...

    <!--
        Resin ships with a crappy JSTL implementation that doesn't work with
        fallback locales for resource bundles correctly; we therefore include
        our own JSTL implementation in the WAR, and avoid this problem. This
        can be removed if the target container is not resin.
    -->
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>${taglibs.version}</version>
        <scope>compile</scope>
    </dependency>

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

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

发布评论

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

评论(2

时光沙漏 2024-08-30 13:17:16

我不做 Resin,所以不要把我强加在它身上,但这些症状听起来像是它附带了一个糟糕的 JSTL 实现。例如,尝试在 web 应用程序的 /WEB-INF/lib 中使用更合适的版本覆盖它。如果是 Servlet 2.5,请获取 jstl-1.2.jar ,或者如果是 Servlet 2.4,则获取 jstl.jar 和 standard.jar

I don't do Resin, so don't pin me on it, but the symptoms make it sound like that it ships with a poorly baked JSTL implementation. Try for instance to override it with a more decent one in the webapp's /WEB-INF/lib. If Servlet 2.5, get jstl-1.2.jar, or if Servlet 2.4, get jstl.jar and standard.jar.

奢望 2024-08-30 13:17:16

只是一个想法,但您也可以尝试添加此上下文参数:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
    <param-value>en</param-value>
</context-param>

Resin 可能使用类似的东西作为“后备”语言环境。

Just an idea, but you could try adding this context-param as well:

<context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
    <param-value>en</param-value>
</context-param>

It's possible that Resin is using something like that as the 'fallback' locale.

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