• 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

ResourceBundle.getBundle

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm loading all my messages from a properties file using the JSTL fmt:message tags. But now I have a case where I need to load a message from the same file, but from a Struts Action class.
How do I load a localized message from a properties file? I looked at ResourceBundle.getBundle, but I don't know how to specify the file. The API states that it must be a fully qualified class name, but where would it start looking for the file? In the WEB-INF/classes directory?
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Code snippet to explain the example.
String language = "en";
String country = "US";
Locale currentLocale;
java.util.ResourceBundle messages;
currentLocale = new Locale(language, country);
messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
MessageBundle.properties
========================
greetings = Hello.
farewell = Goodbye.
inquiry = How are you?
Depending on the MessageBundle properties file, the output will vary. Now its upto u to code to retrieve the MessageBundle.properties file.
Rgds,
Seetesh
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I had that part. What I wanted to avoid was hunting around as to where it would start loading the resource from. It turns out it does base the path on WEB-INF/classes. Now if I can only get the user's locale, JSTL isn't setting a session attribute after determining the browser-based locale. Over to the JSP forum...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic