Java – How should I structure resource bundle property files which are used by jsps

internationalizationjakarta-eejavajsp

I am currently working on converting an existing web application to support an additional language (namely Welsh). My proposed approach is to extract all displayed text into property files and then access the text using JSTL fmt tags.

My question is: how should these property files be structured? I know they need to be on the classpath for the web application, but rather than storing them directly in WEB-INF/classes I would prefer to copy them there during the build step. This leaves me a lot of flexibility in how to store the files in subversion. Since they are closely aligned with the jsps is it a good idea to create a new top-level directory (e.g. resources) and mirror the jsp structure under this folder? This would give me a structure like

resources/jsp/index.properties
resources/jsp/index_cy.properties

This seems like a reasonable approach and it is extensible to property files for classes too, if they should be required:

resources/com/mycompany/myapp/CustomObject.properties
resources/com/mycompany/myapp/CustomObject_cy.properties

The build process could then copy all of these files into WEB-INF/classes ready for packaging into the war file.

Is this approach in line with industry standards? This is the first multilingual application for my current company, so it is likely to be used as a blueprint for all others.

Edit: It has been pointed out that this approach could lead to a lot of duplicated strings in the various property files. While this is true, it would only be as many duplicated strings as currently exist in the jsps. Is it better to have a clear mapping from jsp to property files, at the cost of some duplication in the property files?

Best Solution

Is this approach in line with industry standards? This is the first multilingual application for my current company, so it is likely to be used as a blueprint for all others.

Yes, I think it is.

I believe Maven creates the following directory structure:

src
  +- main
  |    |- java
  |    |- resources
  +- test
       |- java
       |- resources

Which gives you a nice clean separation between your code and unit tests, and then between java code and resources such as property files etc.

Related Question