|
Java™ by example!
|
|
|
What is a locale?
A locale identifies a particular language and region. Optionally, you can specify a custom parameter called a variant. A locale object is useful for internationalization. For example: in the US the decimal symbol is point whereas in Belgium it's a comma. To format the number correctly to the user, your application must consult the Locale object to determine the current language or region. Whenever you create a locale object without specifying language or region, you'll get the default one. This one is automatically determined as follows:
To get the default locale:
You can create your own locale object as follows:
Optionally, you can specify a variant:
Classes that depend on a language (NumberFormat, DateFormat, ...) or region are called locale-sensitive. Typically, you can call the static method getAvailableLocales on that class to find out the locales that work with that class. A resource bundle (see the category resourcebundles) also makes heavily use on locales, as it needs them to determine the correct class name or properties file. Once you have a particular locale identified through one of the constructors, you have access to several methods to find out more about that locale. Look at the API for more information. Here's an example:
outputs:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|