How to Edit a Resource Bundle File

Internationalizing and Localizing Pages 21-13 Figure 21–7 Adding a Locale to faces-config.xml After you have added the locales, the faces-config.xml file should have code similar to the following: locale-config default-localeendefault-locale supported-localearsupported-locale supported-localecasupported-locale supported-localecssupported-locale supported-localedasupported-locale supported-localedesupported-locale supported-localezh_Chsupported-locale locale-config To register the resource bundle: 1. Open the faces-config.xml file and click the Overview tab in the editor window. The faces-config.xml file is located in the View_ ProjectWEB-INF directory.

2. In the editor window, select Application.

3. In the Resource Bundle section, click Add to enable editor input. Enter the fully

qualified name of the base bundle that contains messages to be used by the application and a variable name that can be used to reference the bundle in an EL expression, as shown in Figure 21–8 . Figure 21–8 Adding a Resource Bundle to faces-config.xml After you have added the resource bundle, the faces-config.xml file should have code similar to the following: resource-bundle base-nameoracle.fodemo.storefront.StoreFrontUIBundlebase-name varresvar 21-14 Web User Interface Developers Guide for Oracle Application Development Framework resource-bundle

21.3.4 How to Use Resource Bundles in Your Application

With JSF 1.2 you are not required to load the base resource bundle on each page in your application with the f:loadBundle tag. To use a base resource bundle on your page: 1. Set your page encoding and response encoding to be a superset of all supported languages. If no encoding is set, the page encoding defaults to the value of the response encoding set using the contentType attribute of the page directive. Example 21–6 shows the encoding for a sample page. Example 21–6 Page and Response Encoding ?xml version=1.0 encoding=windows-1252? jsp:root xmlns:jsp=http:java.sun.comJSPPage version=2.0 xmlns:h=http:java.sun.comjsfhtml xmlns:f=http:java.sun.comjsfcore xmlns:af=http:xmlns.oracle.comadffaces xmlns:afc=http:xmlns.oracle.comadffaceswebcache jsp:output omit-xml-declaration=true doctype-root-element=HTML doctype-system=http:www.w3.orgTRhtml4loose.dtd doctype-public=-W3CDTD HTML 4.01 TransitionalEN jsp:directive.page contentType=texthtml;charset=UTF-8 f:view

2. Bind all attributes that represent strings of static text displayed on the page to the

appropriate key in the resource bundle, using the variable defined in the faces-config.xml file for the resource-bundle element. Example 21–7 shows the code for the View button on the myDemo page. Example 21–7 Binding to a Resource Bundle af:commandButton text={res[myDemo.buttonbar.view]} . . . 3. You can also use the adfBundle keyword to resolve resource strings from specific resource bundles as EL expressions in the JSF page. Tip: By default JDeveloper sets the page encoding to windows-1252. To set the default to a different page encoding: 1. From the menu, choose Tools Preferences. 2. In the left-hand pane, select Environment if it is not already selected. 3. Set Encoding to the preferred default. Tip: If you type the following syntax in the source editor, JDeveloper displays a dropdown list of the keys that resolve to strings in the resource bundle: af:commandButton text={res. JDeveloper completes the EL expression when you select a key from the dropdown list. Internationalizing and Localizing Pages 21-15 The usage format is {adfBundle[ bundleID ] [ resource_Key ]}, where bundleID is the fully qualified bundle ID, such as project.EmpMsgBundle, and resource_Key is the resource key in the bundle, such as Deptno_LABEL. Example 21–8 shows how adfBundle is used to provide the button text with a resource strings from a specific resource bundle. Example 21–8 Binding Using adfBundle af:commandButton text={adfBundle[’project.EmpMsgBundle’] [’Deptno_LABEL’]}

21.3.5 What You May Need to Know About Custom Skins and Control Hints

If you use a custom skin and have created a custom resource bundle for the skin, you must also create localized versions of the resource bundle. Similarly, if your application uses control hints to set any text, you must create localized versions of the generated resource bundles for that text.

21.4 Configuring Pages for an End User to Specify Locale at Runtime

You can configure an application so end users can specify the locale at runtime rather than the default behavior where the locale settings of the end user’s browser determine the runtime locale. Implement this functionality if you want your application to allow end users to specify their preferred locale and save their preference.

21.4.1 How to Configure a Page for an End User to Specify Locale

Create a new page or open an existing page. Configure it so that: ■ It references a backing bean to store locale information ■ An end user can invoke a control at runtime to update the locale information in the backing bean ■ The locale attribute of the f:view tag references the backing bean To configure a page for an end user to specify locale: 1. Create a page with a backing bean to store locale information. For more information, see Section 2.4.1, How to Create JSF JSP Pages . 2. Provide a control for example, a selectOneChoice component that an end user can use to change locale. For example, in the Components Palette, from the Common Components panel, drag and drop a Select One Choice anywhere onto the page. 3. Bind the control to a backing bean that stores the locale value, as illustrated in the following example. af:selectOneChoice label=Select Locale binding={backingBeanScope.backing_changeLocale.soc1} id=soc1 af:selectItem label=French value=FR binding={backingBeanScope.backing_changeLocale.si1} id=si1 ... af:selectOneChoice