Given the following ResourceBundle properties files:
- messages.properties
- messages_en.properties
- messages_es.properties
- 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:
- Rename messages.properties to messages_en.properties (essentially, swap the contents of messages.properties and messages_en.properties)
- 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>