Even for applications not created with localization in mind, it is reasonable to separate any resources presented by the program to the user (such as strings, sounds, or icons) from the program code. The reason is not only program modularization, but also a division of responsibility (i.e., icons are designed by artists and not by programmers).
In order to support this approach, Java defines the abstract class ResourceBundle along with the two concrete implementations: ListResourceBundle and PropertyResourceBundle. PropertyResourceBundle reads its key/value pairs from a file, the name of which must correspond to the following naming schema:
name[_language[_country[_variant]]].propertiesThe language and country fields are the two-letter codes discussed in the main article.
The parts in square brackets are optional. The file format consists of lines of key/value pairs, where the key and the value are separated by an equal sign (=) or a colon (:). Lines beginning with a pound sign (#) or an exclamation mark (!) are ignored. Values spanning multiple lines can be defined by ending incomplete lines with a backslash (\) [7].
ListResourceBundle stores its key/value pairs internally. In contrast to PropertyResourceBundle, it can store not only String values, but objects of arbitrary type as well. To use it, subclass ListResourceBundle and override the method getContents to return a two-dimensional Object array containing the key/value pairs. The names of the derived classes must conform to the following naming conventions:
name[_language[_country[_variant]]]Again, the parts in square brackets are optional.
Thus every resource bundle can be identified by a name and a locale. A set of resource bundles consists of resource bundles with the same name, but with different locale suffixes. ResourceBundle objects search for resource bundles by name, the requested locale (1), and the current default locale as returned by Locale.getDefault (2), in the following order:
name + "_" + language1 + "_" + country1 + "_" + variant1 name + "_" + language1 + "_" + country1 + "_" + variant1 + ".properties" name + "_" + language1 + "_" + country1 name + "_" + language1 + "_" + country1 + ".properties" name + "_" + language1 name + "_" + language1 + ".properties" name + "_" + language2 + "_" + country2 + "_" + variant2 name + "_" + language2 + "_" + country2 + "_" + variant2 + ".properties" name + "_" + language2 + "_" + country2 name + "_" + language2 + "_" + country2 + ".properties" name + "_" + language2 name + "_" + language2 + ".properties" name name + ".properties"Odd lines denote Java classes while even lines identify property files, so classes may hide property files with the same name. The name must be fully qualified it must contain the full package name. A key/value pair defined in a parent-level bundle must not be specified in a lower-level bundle if its value does not change. A search for a key thats undefined in a lower-level bundle will find the value of the corresponding key from the parent-level bundle.
Further information about resource bundles can be found in the Java API documentation for the classes java.util.ResourceBundle, java.util.PropertyResourceBundle, and java.util.ListResourceBundle [6, 8].