Creating a resource bundle

A resource bundle contains a series of strings to be presented at run time. With resource bundles, you can localize your applications by including a different resource bundle for each language that you want to support.

Each resource bundle must define a string for each key that is used in the application. If a Web page lists a key and the resource bundle for the current user's language does not define a string for that key, a fatal error will be generated.

To create a resource bundle:
  1. In the Project Explorer view, right-click the folder in which you want to create the resource bundle. This folder must be within the Java™ Resources folder of an EGL Web project.
  2. From the menu, click New > Other. The New window opens.
  3. In the New window, expand General and click File.
  4. Click Next.
  5. In the File name field, type a name for the new resource bundle. The file name of the resource bundle must be in this format:
    prefix_locale.properties
    prefix
    The prefix of the resource bundle file name is arbitrary, but the prefix must be the same for each resource bundle in the application.
    locale
    The locale of the resource bundle, such as en_US. The locale identifies the language of the strings in the bundle and, optionally, more specific information about the specialization of the language, such as the dialect, variety, or geographic location. For more information on locales, see Locales for resource bundles.
    For example, a resource bundle that contains English as it is spoken in the United States might be named resourceBundle_en_US.properties.
  6. Click Finish.

    The new file is created in the folder that you right-clicked, and the new file opens in the editor.

  7. Add strings to the new resource bundle in the following format:
    keyname=stringtext
    keyname
    The key name of the string. This key is placed in the Web pages to indicate which text from the resource bundle to insert. For example, a key named WelcomeText might indicate introductory text to be shown at the top of a page.
    stringtext
    The text that is associated with the key.
  8. Save and close the file.

You can create as many resource bundles for your application as you want, but each resource bundle must have a different locale and the same prefix.


Feedback