You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-dev@portals.apache.org by Ken Ramirez <kr...@thejavathinktank.org> on 2005/01/23 02:07:09 UTC
Locale and ResourceBundles
Hi Guys,
I'm writing a locale aware portlet that utilizes the
PortletConfig.getResourceBundle method to retrieve a resource bundle.
When I call the getLocale method of the returned resource bundle, it
appears to be null. I inspected the ResourceBundle and sure enough the
locale member is null. However, it is loading the specified resource
file correctly based on the locale being passed to the method.
The problem is that if you pass it one locale (say French for example)
and it cannot find a matching resource, it will default to whatever the
default language is (say English for example). How then can you test to
assure that the language it returned for the resource bundle is what you
expected or not. Here's a snippet of code to help drive the point:
// Define a resource bundle and retrieve the locales.
ResourceBundle rb = null;
Enumeration locales = request.getLocales();
// Enumerate over the locales until we find a
// matching resource bundle.
while(locales.hasMoreElements())
{
Locale locale = (Locale)locales.nextElement();
rb = getResourceBundle(locale);
// Did we find the one we were looking for?
if(rb != null && locale.equals(rb.getLocale()))
break;
}
The purpose of the above code is to look up the resource bundles in the
order specified by the browser locale header in the request. However,
this will never work because returned resource bundle's locale is null.
Is this a bug in Pluto or is it suppose to leave the locale set to null?
It just doesn't seem right to me.
Thanks,
--
*----*----*----*----*----*----*----*----*----*----*----*----
Stay on top of all things regarding JSR-168 Portlet and
Portal development by bookmarking the authority on the
subject: http://community.java.net/portlet
*
* News
* Weblogs
* Community Tips
* Portlet and Portal Projects
* Featured Articles
* And much more
*
*----*----*----*----*----*----*----*----*----*----*----*----
Ken Ramirez
Send mail to: mailto://kramirez@TheJavaThinkTank.org
Check out the website: http://www.TheJavaThinkTank.org
Check out my Blog at: http://weblogs.java.net/blog/ken_ramirez
*----*----*----*----*----*----*----*----*----*----*----*----