Create message catalogs

 

Before you begin

Identify strings that need to be localized.

 

Overview

We can create a catalog as either a java.util.ResourceBundle subclass or a Java properties file. The properties-file approach is more common, because properties files can be prepared by people without programming experience and swapped without modifying the application code.

 

Procedure

  1. For each string that is identified for localization, add a line to the message catalog that lists the string key and value in the current language. In a properties file, each line has the following structure

    key = string associated with the key
    

  2. Save the catalog, giving it a locale-specific name. To enable resolution to a specific properties file, the Java API specifies naming conventions for the properties files in a resource bundle as bundleName_localeID.properties. Give the set of message catalogs a collective name, for example, BankingResources. For information about locale IDs that are recognized by the Java APIs, see "Resources for learning."

 

Example

The following English catalog (BankingResources_en.properties)

supports the labels for the list and its two list items

accountString = Accounts
savingsString = Savings
checkingString = Checking

Do not create compound strings by concatenation (for example, combining the values of savingsString and accountString to form Savings Accounts in English. Success depends upon the grammar of the original language (in this case, English) and is not likely to extend to other languages.

The corresponding German catalog (BankingResources_de.properties) supports the labels as follows

accountString = Konten
savingsString = Sparkonto
checkingString = Girokonto

 

What to do next

Write code to compose the language-specific strings.


 

See Also


Internationalization: Resources for learning