Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Resouce Bundle - strange behavior or my mistake??

Thread view: 
Swetha - 01 Feb 2006 14:52 GMT
Hello

I am using Resource Bundles in a Swing application. I have a method
that requests the appropriate resource bundle based on the current
locale.

public ResourceBundle getPPBundle()
   {
       logger.log(Level.INFO, "locale is " + loc.toString());
       PPBundle = ResourceBundle.getBundle("PP", loc);
       logger.log(Level.INFO, "locale is " +
PPBundle.getLocale().toString());
       return PPBundle;
   }

As shown above : loc is of type Locale and when I print its value, it
shows "ar" in this case. I have 2 properties files : PP.properties(the
default) and PP_ar.properties(the arabic properties file). However when
I execute the code, the ResourceBundle locale is blank ("") when
printed and the string returned is in the default language instead of
in Arabic.

The same code worked some time back, and I can't seem to figure out
what has changed to change the behavior.

Can someone think of a reason??

Thanks
Swetha
Thomas Weidenfeller - 01 Feb 2006 15:40 GMT
> As shown above : loc is of type Locale and when I print its value, it
> shows "ar" in this case. I have 2 properties files : PP.properties(the
> default) and PP_ar.properties(the arabic properties file).

They have to be at the right location in the class path, since
getBundle() uses ClassLoader.getResource() to locate the file. See the
API documentation of getResource() for how this is done.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Roedy Green - 01 Feb 2006 21:07 GMT
>The same code worked some time back, and I can't seem to figure out
>what has changed to change the behavior.

The usual problem is not having the resource inside the proper package
tree in the jar or getting confused about lead dots and slashes and
level of qualification. Everything is case sensitive.  

see http://mindprod.com/jgloss/resource.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Swetha - 02 Feb 2006 10:37 GMT
Thanks for the suggestions.

It turned out that there was a manual error in one of the unicode
values and so the file was viewed as corrupt and the default properties
file was being returned.

Swetha


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.