Java Reference
In-Depth Information
Locale names are two-letter ISO-639 language codes (lowercase), and normally abbreviate
the country's
endonym
(the name its language speakers refer to it by), thus Sweden is
sv
for
Sverige
, etc.; locale variations are two-letter ISO country codes (uppercase).
Setting the locale
On Windows, go into Regional Settings in the Control Panel. Changing this setting may en-
tail a reboot, so exit any editor windows.
On Unix, set your LANG environment variable. For example, a Korn shell user in Mexico
might have this line in her
.profile
:
export LANG=es_MX
On either system, for testing a different locale, you need only define the locale in the System
Properties at runtime using the command-line option
-D
, as in:
java -Duser.language=es i18n.Browser
to run the Java program named
Browser
in package
i18n
in the Spanish locale.
Listing Available Locales
Problem
You want to see what locales are available.
Solution
Call
Locale.getAvailableLocales()
.
Discussion
A typical runtime may have dozens of locales available. The program
ListLocales
uses the
method
getAvailableLocales()
and prints the list: