By looking at Spanish-related locale IDs at Oracle
http://www.oracle.com/technetwork/java/javase/javase7locales-334809.html
Spanish Argentina es_AR
Spanish Bolivia es_BO
Spanish Chile es_CL
Spanish Colombia es_CO
Spanish Costa Rica es_CR
Spanish Dominican Republic es_DO
Spanish Ecuador es_EC
Spanish El Salvador es_SV
Spanish Guatemala es_GT
Spanish Honduras es_HN
Spanish Mexico es_MX
Spanish Nicaragua es_NI
Spanish Panama es_PA
Spanish Paraguay es_PY
Spanish Peru es_PE
Spanish Puerto Rico es_PR
Spanish Spain es_ES
Spanish United States es_US
Spanish Uruguay es_UY
Spanish Venezuela es_VE
I feel Java Locale IDs are different for each country. Put it another way, two countries do not share the same Locale ID. I understand that a country may have two or more locales.
Is my understanding right? I am unable to find clear description to support my understanding.
Thanks!
A
Locale
may include a country code, but they aren't intended to identify countries.A
Locale
is intended to represent a combination of rules for displaying translations/formatting/etc.Locales are identified with a combination of language, country, and variant.
So:
en
would be Englishen_US
would be the variant of English spoken in Americaen_US_WIN
might represent American English for a version of the software running on Windows (e.g. if you had text that needed to be different for Windows users).The language and country parts are based on ISO standards. But Locale doesn't really restrict what you do with the variant part.
You should not think of locales as having a one-to-one mapping with countries (or with languages).
e.g.
fr_FR
= Variety of French spoken in France.fr_CH
= Variety of French spoken in Switzerland.de_CH
= Variety of German spoken in Switzerland.Many systems that use Locales will follow a practice of falling back to more general Locales as needed. e.g.
ResourceBundle
which can be used to look up appropriate text translations based on a message key. If you told it to find a message in Localeen_US_WIN
and it didn't find it, it would then try with Localeen_US
and thenen
and then fall back on the 'root' Locale. This means that if American and British English translations used the same text for something, then their translation would only need to be recorded once. It also means that if the code doesn't know about a language it can fall back to a default language (stored in files for the root locale).If you're interested in getting a list of countries or languages, there are static methods on
Locale
to help with this.There are also methods for getting human readable names of languages:
And human readable names of countries: