This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes ResourceBundle & defaultLocale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ResourceBundle & defaultLocale" Watch "ResourceBundle & defaultLocale" New topic
Author

ResourceBundle & defaultLocale

Jim Janssens
Ranch Hand

Joined: Sep 24, 2004
Posts: 210
I have a localization system which uses Locale to load the messages in different languages. I also have a 'default' file, which contains the messages in english. So I have:

file.properties (default english)
file_fr.properties (french)
file_nl.properties (dutch)

Now, if I get a bundle with an non existing language (a language that simply does not exist and/or for which no property file was present) I would like the default bundle to be used.

However, after some tests it seems that the path for resolving also includes the Locale.getDefaultLocale(). So what the getBundle does is something like (correct me if I'm wrong) :

a) try to load the locale using the steps explained in the api
b) if no valid bundle was found, try the getDefaultLocale() and repeat step a with this locale.
c) if step b did not return a bundle, try to load the default bundle

So, if I try to load a non existing language, I endup with the language specified on my machine. Only when there is no property file with that language either, it will load the default file.

I would like to eliminate step b. I want, that when there is no support for a certain language, the default file is used directly.

Is there a way ?
 
Consider Paul's rocket mass heater.
 
subject: ResourceBundle & defaultLocale