How to Set Resource Bundle Options

Internationalizing and Localizing Pages 21-7

21.3 Manually Defining Resource Bundles and Locales

A resource bundle contains a number of named resources, where the data type of the named resources is String. A bundle may have a parent bundle. When a resource is not found in a bundle, the parent bundle is searched for the resource. Resource bundles can be either Java classes, property files, or XLIFF files. The abstract class java.util.ResourceBundle has two subclasses: java.util.PropertyResourceBundle and java.util.ListResourceBundle. A java.util.PropertyResourceBundle is stored in a property file, which is a plain-text file containing translatable text. Property files can contain values only for String objects. If you need to store other types of objects, you must use a java.util.ListResourceBundle class instead. For more information about using XLIFF, see http:docs.oasis-open.orgxliffxliff-corexliff-core.html To add support for an additional locale, replace the values for the keys with localized values and save the property file, appending a language code mandatory and an optional country code and variant as identifiers to the name, for example, UIResources_it.properties. The java.util.ListResourceBundle class manages resources in a name and value array. Each java.util.ListResourceBundle class is contained within a Java class file. You can store any locale-specific object in a java.util.ListResourceBundle class. To add support for an additional locale, you create a subclass from the base class, save it to a file with a locale or language extension, translate it, and compile it into a class file. The ResourceBundle class is flexible. If you first put your locale-specific String objects in a java.util.PropertyResourceBundle file, you can still move them to a ListResourceBundle class later. There is no impact on your code, because any call to find your key will look in both the java.util.ListResourceBundle class and the java.util.PropertyResourceBundle file. The precedence order is class before properties. So if a key exists for the same language in both a class file and a property file, the value in the class file will be the value presented to you. Additionally, the search algorithm for determining which bundle to load is as follows: 1. baseclass+specific language+specific country+specific variant 2. baseclass+specific language+specific country 3. baseclass+specific language 4. baseclass+default language+default country+default variant 5. baseclass+default language+default country 6. baseclass+default language For example, if your browser is set to the Italian Italy locale and the default locale of the application is US English, the application attempts to find the closest match, looking in the following order: 1. it_IT 2. it 3. en_US 4. en 5. The base class bundle 21-8 Web User Interface Developers Guide for Oracle Application Development Framework

21.3.1 How to Define the Base Resource Bundle

You must create a base resource bundle that contains all the text strings that are not part of the components themselves. This bundle should be in the default language of the application. You can create a resource bundle as a property file, as an XLIFF file, or as a Java class. After a resource bundle file has been created, you can edit the file using the Edit Resource Bundles dialog. To create a resource bundle as a property file or an XLIFF file: 1. In JDeveloper, create a new file. ■ In the Application Navigator, right-click where you want the file to be placed and choose New from the context menu to open the New Gallery. ■ In the Categories tree, select General, and in the Items list, select File. Click OK . ■ In the Create File dialog, enter a name for the file using the convention name_lang.properties for the using the properties file or name_ lang.xlf for using the XLIFF file, where the _lang suffix is provided for translated files, as in _de for German, and omitted for the base language. 2. Enter the content for the file. You can enter the content manually by entering the key-value pairs. You can use the Edit Resource Bundle dialog to enter the key-value pairs, as described in Section 21.3.2, How to Edit a Resource Bundle File . ■ If you are creating a property file, create a key and value for each string of static text for this bundle. The key is a unique identifier for the string. The value is the string of text in the language for the bundle. If you are creating a localized version of the base resource bundle, any key not found in this version will inherit the values from the base class. Tip: The getBundle method used to load the bundle looks for the default locale classes before it returns the base class bundle. If it fails to find a match, it throws a MissingResourceException error. A base class with no suffixes should always exist as a default. Otherwise, it may not find a match and the exception is thrown. Note: If you are creating a localized version of the base resource bundle, save the file to the same directory as the base file. Note: If you are creating a localized version of a base resource bundle, you must append the ISO 639 lowercase language code to the name of the file. For example, the Italian version of the UIResources bundle is UIResources_it.properties. You can add the ISO 3166 uppercase country code for example it_CH, for Switzerland if one language is used by more than one country. You can also add an optional nonstandard variant for example, to provide platform or region information. If you are creating the base resource bundle, do not append any codes.