Useful constant for the root locale. The root locale is the locale whose language, country, and variant are empty ("") strings. This is regarded as the base locale of all locales, and is used as the language/country neutral locale for the locale sensitive operations.
If a locale hasn't language/country info then how is it a locale object? what is the use of that ?
Just because it is language and country neutral doesn't mean it's not a Locale, its just not a locale that relates to a physical place.
I don't suppose there are many uses for it but there may be occasions when you want to work with dates, times etc in a locale neutral way in which case you would need this Locale.
If I remember correctly, if you look at the source code for Locale you'll see that for a lot of the built-in constant Locales (like Locale.FRANCE) it basically uses ROOT and then adds the required properties to it. So it looks like it gives a convenient way of handling things common to many Locales.
Joined: Aug 07, 2007
then i found Locale.ROOT represent RBControl.properties file.
Correct me if i am wrong.
I take it you are referring to what happens when you call ResourceBundle.getBundle().
The simple answer is it depends on what locale you have set your system to default to and the locale you pass into the getBundle() method. I suggest you read the api docs for the getBundle method for a fuller explanation.
---------- Run ----------
language: Simplified Chinese
Output completed (0 sec consumed) - Normal Termination
I said so because i did a test.Note that i commented all locales else than Locale.ROOT in List,now when you will see output then you would know that it was representing RBControl.properties file.
I don't understand what your test is supposed to prove other than the validity of your earlier statement which it only does because you've replaced the normal ResourceBundle controller with one that returns candidate locales of Locale.ROOT.
It's very easy, there isn't any locale in list for HK and TW other than ROOT.See output for hk and tw that is
which is of RBControl.properties file, not RBControl_zh_HK.properties and RBControl_zh_TW.properties files.
Joined: Aug 07, 2007
But that's because your controller has told ResourceBundle that ROOT is the only candidate for those locales. That is not how ResourceBundle normally works which was the point I was making when I said "The simple answer is it depends on what locale you have set your system to default to and the locale you pass into the getBundle() method." Your original question did not say you were using a non standard ResourceBundle.
In your example I'm not sure why you are doing what you are doing but if there is a genuine reason why you should return the base name file when a particular locale is specified then your code (ie returning a candidate of Locale.ROOT) is a good way to do it.
Conceptually, getBundle uses the following strategy for locating and instantiating resource bundles:
getBundle uses the base name, the specified locale, and the default locale (obtained from Locale.getDefault) to generate a sequence of candidate bundle names. If the specified locale's language, country, and variant are all empty strings, then the base name is the only candidate bundle name. Otherwise, the following sequence is generated from the attribute values of the specified locale (language1, country1, and variant1) and of the default locale (language2, country2, and variant2):
baseName + "_" + language1 + "_" + country1 + "_" + variant1
baseName + "_" + language1 + "_" + country1
baseName + "_" + language1
baseName + "_" + language2 + "_" + country2 + "_" + variant2
baseName + "_" + language2 + "_" + country2
baseName + "_" + language2
Therefore, if you pass in a locale who's language, country, and variant are all empty strings (ie Locale.ROOT) the base name file will be returned. So in this case Locale.ROOT can be used to force to base name file to be returned.