• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ROOT locale

 
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 333
Firefox Browser Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved at OP’s suggestion.
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what is job of ROOT locale in that example please elaborate.thanks
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what example, yours or the default implementation of ResourceBundle?
 
Enkita mody
Ranch Hand
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, in both case.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 333
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic