How to organize Java property records for internationalization?

Our application has a messages.properties file that contains all the lines that will be displayed in the user interface. We have a small application with several screens, and it is already becoming cumbersome with repeating string values.

Right now, we organized it with page lines separated by spaces and comments, with a section for each jsp with a property name that has a page name prefix. We also have sections for objects, for example, wherever we display the user's email address, we will refer to the user.email property for the label for this input or output field. We have another section for error messages and status, and finally one last section with global messages like "Send" and "Cancel"

There should be a better way, and I wonder if you know what it is.

+4
source share
1 answer

I do not think there is a universal “best way”. I tried Googling for a “best practice” recommendation and found nothing that said how to best structure the property namespace for i18n.

(I found this somewhat unexpected. Usually there is someone who is willing to put their imprudent opinions to something like this as “best practice.” Or maybe I'm too cynical.)

FWIW, my general advice is:

  • be systematic and consistent with respect to property names and property file structure.
  • don't be afraid to use resource package inheritance if there is a lot of duplication,
  • if the property files or resource packages become too large, separate them.

But I expect that you already know and will do it all.

Finally, don’t get too focused on getting it “right.” There is no perfect solution, and what you are doing now is probably good enough ... according to the criteria of the one who pays you to do this work.

+5
source

All Articles