This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locale Class

 
Duleep Thivanka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Locale's getAvailableLocales() method I can list all locales in Java Virtual Machine.Is there a way to add new Locale to Java Virtual Machine ?.Thank You
 
Sondre Kval�
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the implementation of java.util.Locale.getAvailebleLocales() (JSE 5.0):

The class LocaleData has the fully qualified name sun.text.resources.LocaleData and the source code for this is unfortunately no publically available. Browsing through the OpenJDK makes me believe that the list of available locale should be defined at compile-time. If this is correct there is now way of edit this list at run time.

You can however define your own locale using one of the constructors in the Locale class, and use this as input to the java.util.Locale.setDefault(Locale) method (and of course to whatever method that requires a Locale object as input).
 
Duleep Thivanka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.But I want to install a new locale.How I can do that.setDefault method doesn't work because before that I want to install a new locale.
 
Paul Clapham
Sheriff
Pie
Posts: 20967
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be pretty clear from the API documentation that the Locale class doesn't have any methods to install a new locale.

If you then click on the "Use" button at the top of the documentation page for Locale, that shows you everything in the standard API which uses Locale. You can check for yourself that there's nothing in this long list which installs a new Locale either.

An interesting thing you might notice in the list is that there are methods whose descriptions are like, for example, "Gets the date formatter with the given formatting style for the given locale". That implies that internally a Locale has a whole lot more baggage attached to it -- date formatters, number formatters, collators, and so on. You can't define any of that when you create a new Locale but the built-in Locales do have it.

Even the String class has a toLowerCase(Locale) method which uses the rules of the Locale for lower-casing. You wouldn't have any way of dealing with that, either. So installing a new Locale wouldn't be all that useful any way, since you don't have a way of specifying all those Locale-dependent objects and behaviours.
 
Duleep Thivanka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your thoughts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic