Java Reference
In-Depth Information
DISPLAY LOCALE: en_US
FORMAT LOCALE: es_MX
Good morning!, 19/09/11 08:31 PM
DEFAULT LOCALE: en_US
DISPLAY LOCALE: en_US
FORMAT LOCALE: en_US
Good morning!, 9/19/11 8:31 PM
How It Works
The Locale class allows you to set the default locale for two different categories. The
categories are represented by the Locale.Category enumeration:
Locale.Category.DISPLAY
Locale.Category.FORMAT
Use the DISPLAY category for your application's user interface. Setting the default
DISPLAY locale means that the ResourceBundle class can load user interface re-
sources for that particular locale independently from the FORMAT locale. Setting the
FORMAT default locale affects how the various Format subclasses behave. For ex-
ample, a default DateFormat instance will use the FORMAT default locale to create a
locale-sensitive output format. Again, these two categories are independent, so you can
use different Locale instances for different needs.
In this recipe's sample code, the Locale.setDefault(Locale.FRANCE)
method call sets the default system, DISPLAY , and FORMAT locales to fr-FR
(French in France). This method always resets both the DISPLAY and FORMAT locales
to match the system locale. When creating a new resource bundle, the Re-
sourceBundle class uses the system locale by default. However, by providing a
Locale instance argument, you tell the bundle to load resources for a specific locale.
For example, even though the system locale is Locale.FRANCE , you can specify a
DISPLAY default locale and use that DISPLAY locale in your Re-
sourceBundle.getBundle() method call. For example, this code attempts to
load a language bundle for es-MX even though the system locale is still
Locale.FRANCE :
Search WWH ::




Custom Search