How to expand the list of available Java languages

I am looking for a way to add more locales to the locales available in Java 1.6. But the locales that I want to create do not have the ISO-3166 country codes, as well as the ISO-639 language codes. Is there any way to do this anyway? The locales I want to add differ only in the names of languages, but the smaller the ethnic group, the more discriminating they learn about their personality; -)

So, I thought about expanding an existing Locale, something like

UserDefinedLocale extends Locale { UserDefinedLocale (Locale parentLocale) {...} } 

but java.util.Locale is final, which makes it especially difficult to hack something around ...

So, is the idea that the Java Locales list is exhaustive? Am I the first to miss a few more locales?

+7
source share
2 answers

Read the javadoc for java.util Locale .

It says: "Create a Locale object using the constructors in this class:"

It also says: "Because the Locale object is just an identifier for a region, validation fails when you build the locale."

It also says: "Locale is a mechanism for identifying the type of object (NumberFormat) you want to get. A locale is just a mechanism for identifying objects, not a container for the objects themselves."

And finally, javadoc for the getAvailableLocales () method says: "The returned array represents the union of the locales supported by the Java runtime and the installed LocaleServiceProvider implementations"

So, you just need to come up with a language code that is not on the standard list, and use it as an identifier for your locale.

+4
source

See this answer :

... You can connect support for additional locales via SPI (described here here ). For example, to provide a date format for a new locale, you do this by running DateFormatProvider . You could do this by decorating an existing implementation - I would look at the ICU4J library to see if it supports the support you want.

+1
source

All Articles