+

Search Tips   |   Advanced Search

JRas resource bundles

Create resource bundles in several ways. The best and easiest way is to create a properties file that supports a PropertiesResourceBundle resource bundle. This sample shows how to create such a properties file.


Resource bundle sample

The JRas framework described in this task and its sub-tasks is deprecated. However, we can achieve similar results using Java logging.

For this sample, four localizable messages are provided. The properties file is created and the key-value pairs are inserted into it. All the normal properties files conventions and rules apply to this file. In addition, the creator must be aware of other restrictions that are imposed on the values by the Java MessageFormat class. For example, apostrophes must be escaped or they cause a problem. Avoid the use of non-portable characters. WebSphere Application Server does not support the use of extended formatting conventions that the MessageFormat class supports, such as {1, date} or {0, number, integer}.

Assume that the base directory for the application that uses this resource bundle is baseDir and that this directory is in the class path. Assume that the properties file is stored in the subdirectory baseDir that is not in the class path (baseDir/subDir1/subDir2/resources). To allow the messages file to resolve, the subDir1.subDir2.resources.DefaultMessage name is used to identify the PropertyResourceBundle resource bundle and is passed to the message logger.

For this sample, the properties file is named DefaultMessages.properties:

# Contents of the DefaultMessages.properties file 
SG_KEY_00=A message with no substitution parameters. 
SG_KEY_01=A message with one substitution parameter: parm1={0} 
SG_KEY_02=A message with two substitution parameters: parm1={0}, parm2 = {1} 
SG_KEY_03=A message with three substitution parameters: parm1={0}, parm2 = {1}, parm3={2} 

When the DefaultMessages.properties file is created, the file can be sent to a translation center where the localized versions are generated.

  • Create JRas resource bundles and message files
  • Instrumenting an application with JRas extensions