How were the Locale constants chosen?
Asked Answered
J

3

15

The Java class java.util.Locale has a set of public static final fields for languages/countries for direct references to specific locales. Other locales can easily be used via the appropriate constructors.

However, the selection of values seems rather arbitrary to me.

The languages are (in the order in which they appear in the source): English, French, German, Italian, Japanese, Korean, Chinese, Simplified Chinese, Traditional Chinese

The countries are: France, Germany, Italy, Japan, Korea, China, PRC, Taiwan, UK, US, Canda and Canada French (for the locale fr_CA).

Does anyone have an idea (or even a guess) how those languages/countries where chosen?

Jukebox answered 11/4, 2011 at 13:13 Comment(2)
I don't know but one stupid thing I found out today is that there is a constant named Locale.UK but UK is not a valid country code - the corresponding country code is GB...Attenweiler
@Attenweiler Regarding GB versus UK, we have an entire Question from someone getting tripped up on that.Avaria
O
15

Those codes are defined by ISO standards 3166 for country codes and 639 for language codes. See also the W3C Internationalization Activity page.

Edit:

Re-reading the question, the OP already knew this :-)

According to the Sun article Internationalization: Understanding Locale in the Java Platform those values are chosen as examples and it even tells us:

Because so few premade locales exist, you should probably just avoid these static objects altogether

In Java 19+, use the convenient Locale.of methods.

  • Locale.of( "en" , "CA" ) for English in Canada.
  • Locale.of( "fr" , "CA" ) for French in Canada.
  • Locale.of( "en" , "US" ) for English in United States.
Orthodontics answered 11/4, 2011 at 13:27 Comment(1)
In other words, it was likely just a fundamental mistake in early Java versions and they are just kept for backwards compatibility or something.Philately
V
6

I'd guess it's simply the most often used locales as a convenience for developers.

From the Javadoc:

The Locale class provides a number of convenient constants that you can use to create Locale objects for commonly used locales.

Vertebral answered 11/4, 2011 at 13:23 Comment(4)
I am confident that the OP already knows that. This is also not exactly what the OP is asking. The OP is asking why specifically this subset of locales are used as constants. Under what conditions is a locale definied as a constant? Why does it for example not contain SPANISH which is world's second most spoken native language?Philately
@BalusC: Mandarin is first, Spanish second and English third? Well, I am not sure about it but it is definitely one of the top :) Also, I think that Mexico should be on countries list (as es-MX is typically used for software translations).Enzymolysis
@Philately I'm not sure why Spanish isn't in there but there might be a historic reason of most software being written in the above languagues or Spanish countries not having that big a role in software development. This might not be true anymore but those constants date back to Java 1.1 (i.e. 1997) and it might have been true by then.Vertebral
My personal guess is that this set of constants is a small viewport into the geographical distribution of Sun customers in 1997 ;-)Jukebox
P
0

My guess is that they use their Tier 1 languages - the ones that JRE is localized to. As for countries, I think they simply match it with languages. Well, we probably will never know unless somebody involved speak up.

Professoriate answered 11/4, 2011 at 13:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.