How should I structure the resource package properties files used by jsps?

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

My question is: how to structure these property files? I know that they should be in the classpath for the web application, but instead of storing them directly in WEB-INF / classes, I would rather copy them at the build stage. This leaves me with great flexibility in how to store files in subversion. Since they are closely related to jsps, is it a good idea to create a new top-level directory (e.g. resources) and mirror the jsp structure in this folder? That would give me a structure like

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

This seems like a reasonable approach, and it also expands for property files for classes, if needed:

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

The build process can then copy all these files to WEB-INF / classes, ready to be packaged into a war file.

Does this approach meet industry standards? This is the first multilingual application for my current company, so it will most likely be used as a plan for everyone else.

Edit: It has been pointed out that this approach can lead to a lot of duplication of strings in different property files. Although this is true, in jsps there will only be as many duplicate lines as there currently are. Is it better to have a clear mapping from jsp to property files due to some duplication in the property files?

+3
source share
3 answers

Does this approach meet industry standards? This is the first multilingual application for my current company, so it will most likely be used as a plan for everyone else.

Yes, I think so.

I believe Maven creates the following directory structure:

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

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

+2
source

It has been pointed out that this approach can lead to duplicate lines in various property files. Although this is true, it will only be as many duplicates as currently exist in JSPs. Is it better to have a clear mapping from jsp to property files, at the cost of some duplication to property files?

Yes, it is always better. Although you can "reuse" the string in different places / JSPs in English, it may still not be possible in other languages. Reusing localized strings can also create unwanted and complex dependencies between components that are otherwise unrelated. Translators also need to know the use of the texts that they translated into your application.

+2
source

I’m not sure that it is a good idea to establish too strong a link between resource files and code files that use them, as this can lead to unnecessary duplication of texts that can be reused.

This is especially problematic when texts are translated by a third party, because the same expression, when it occurs several times in different files, can be translated in a different way, which can be very confusing for the user.

I would structure the resource files individually and try to find an organization that makes sense in its essence, for example. UiLabels.properties, ErrorMessages.properties.

0
source

All Articles