What are some of the strategies for internationalising JSP pages, without duplicating the JSP page for each language?

Govind Seshadri

Internationalizing a JSP-based web application is a task best initiated at the design stage itself. The internationalization process involves identifying all locale-specific textual data (aka resources) that constitute the user interface of the application, such as page headers and trailers, user messages, form button labels, dates, currencies and so forth, and isolating them from the application within external property files known as resource bundles. Typically, you need to provide a version of the resource bundle for each locale your application serves, with the locale defined as a geographical region or political entity that shares a common language, culture and customs. The process of creating these locale-specific bundles themselves, along with the associated translation of text, is called localization.

The property files for bundles must follow some standard naming conventions. The suffix must always be “.properties”. Also, since a locale is typically defined in Java via a country code and/or a language code, the name of the bundle has to correlate with the locale it serves.

For example, the property file serving as the bundle for Germany may be named Message_de_DE.properties. Similarly, the bundle for France can be named Message_fr_FR.properties, and so on. Later, when your application needs to service a specific locale, it can do so using predefined constants like Locale.GERMANY, Locale.FRANCE, and so forth. Then, using the class java.util.PropertyResourceBundle, it should be able to load the corrosponding resource bundle serving the locale and access the values for the resources by name, just like you would with a Hashtable object.