esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

How is my .properties ResourceBundle found?
Suppose we have a .properties file called LabelsBundle_nl_BE.properties and assume also our default locale is en_US. To get access to that bundle, you can invoke ResourceBundle.getBundle("LabelsBundle", "nl", "BE"). Notice that a resource bundle consists of two parts: a family name and a locale part. The locale part contains a language code, a country code and an optional variant code. In our example, it will try to locate the bundle in the following way:

 
This code sample is only viewable to esus.com members
Login or become a member!


Notice that once the .propreties file has been located, it will still continue to look for parent resourcebundles by shortening the locale part delimited by an underscore.

Now assume we only have a .properties file called LabelsBundle_en and we invoke ResourceBundle.getBundle("LabelsBundle", "nl", "BE"). Notice here that it will start from our desired locale and build its way up the tree, including searching for a match with the default locale.

 
This code sample is only viewable to esus.com members
Login or become a member!



Assume we have a .properties file called LabelsBundle_nl_BE.properties and a .properties file called LabelsBundle.properties.

 
This code sample is only viewable to esus.com members
Login or become a member!


In this example, LabelsBundle.properties has become a parent resource bundle of LabelsBundle_nl_BE. You can use the property keys from both these files through the instance that you get back from invoking ResourceBundle.getBundle(...). Also notice that if the resource bundle has been found using the desired locale, the default locale will not be used in looking for a parent. The default locale is only used if locating a bundle with the desired locale failed.

As a last note, you must specify the fully qualified name for the family name (or baseclass) when requesting a resource bundle object. For example, if LabelsBundle_nl_BE.properties is in the package mypackage, you will have to say:

 
This code sample is only viewable to esus.com members
Login or become a member!




Further Information
Author of answer: Joris Van den Bogaert

Comments to this answer are only viewable by members. Login or become a member!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.