File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ROOT locale Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ROOT locale" Watch "ROOT locale" New topic
Author

ROOT locale

Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Locale.ROOT
ROOT

public static final Locale ROOT

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.

Since:
1.6



If a locale hasn't language/country info then how is it a locale object? what is the use of that ?


OCA7
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
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.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Some properties files for example are
RBControl.properties
RBControl_zh.properties
RBControl_zh_cn.properties
RBControl_zh_hk.properties
RBControl_zh_tw.properties

then i found Locale.ROOT represent RBControl.properties file.

Correct me if i am wrong.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Moved at OP’s suggestion.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

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.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
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.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

#RBControl.properties
region: global
language: English

#RBControl_zh.properties
language: Simplified Chinese

#RBControl_zh_CN.properties
region: China

#RBControl_zh_HK.properties
region: Hong Kong

#RBControl_zh_TW.properties
region: Taiwan
language: Traditional Chinese


---------- Run ----------
locale: zh_CN
region: China
language: Simplified Chinese
locale: zh_HK
region: global
language: English
locale: zh_TW
region: global
language: English
locale: en_CA
region: global
language: English

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.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
I said so because i did a test

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.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

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

region: global
language: English

which is of RBControl.properties file, not RBControl_zh_HK.properties and RBControl_zh_TW.properties files.

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
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.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Then what is job of ROOT locale in that example please elaborate.thanks
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
In what example, yours or the default implementation of ResourceBundle?
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Yes, in both case.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1935
    
  28
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.

In the default implementation of ResourceBundle the API docs says:
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
baseName
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.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ROOT locale
 
Similar Threads
Class Locale
Calender & Holidays
what is locale class.
new Locale() from country code, but no lang code?
How to Allow User to Select a Locale