Thanks Jan for your response.

To my understanding, when I use the i18n tags from JSTL, I don't need to write any 
class to get locale information 
stored. Only task is to configure the locale information file. Please point it out if 
I am wrong.

If I need to use the PropertyResourceBundle class as the followings (this class, 
according to the JDK document, can't 
be subclassed by the way):

import java.util.Enumeration;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.PropertyResourceBundle;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;

public class BundleLocator {
   public PropertyResourceBundle locateBundle(ServletRequest request,
                                                                                       
 
          String base) 
                                                                                       
 
          throws JspException {
      Enumeration en = request.getLocales();
      Locale defaultLocale = Locale.getDefault();
      PropertyResourceBundle fallbackBundle = null;
   
      try {
         fallbackBundle = (PropertyResourceBundle)(ResourceBundle.getBundle(base, 
                                                  defaultLocale));
      }
      catch(MissingResourceException ex) {
                        throw new JspException(ex.getMessage());
      }

      while(en.hasMoreElements()) {
         Locale locale = (Locale)en.nextElement();
         PropertyResourceBundle bundle = null;

         try {
            bundle = (PropertyResourceBundle)ResourceBundle.getBundle(base, locale);
         }
         catch(MissingResourceException ex2) {
            // ignore missing bundles ...   
            continue;
         }
         if(bundle != fallbackBundle)
            return bundle;

         if(fallbackBundle != null && bundle == fallbackBundle) {
            String lang = locale.getLanguage();
            String defaultLanguage = defaultLocale.getLanguage();

            if(lang.equals(defaultLanguage))
               return bundle;
         }
      }
      return null;
   }
}

I can write my own tag and don't need use the JSTL. 

At this point, I am very frustrated by the fact of lacking JSTL documentation. I have 
searched all possible places and 
not much helpful information available. The document comes with JSTL doesn't help 
much. And the jwsdp document 
mentions JSTL, but still not much on i18n. I guess that I shall use i18n tags other 
than JSTL.5/17/2002 12:53:47 AM, 
Jan Luehe <[EMAIL PROTECTED]> wrote:

>Vernon:
>
>> I just start to use the JSTL since the day before. It seems to me
>> that the i18n messages have to be placed in a subclass of the
>> ListResourceBundle. The messages are stored in a two dimension
>> string array. And it can't be constructed in the object initiation
>> time (since it is in a static final data type). I prefer to store
>> the i18n messages in a porperty file. Is anyone out there who has
>> used the i18n portion JSTL with a property file? If so, please share
>> your experience.
>
>JSTL leverages java.util.ResourceBundle.getBundle() to locate
>a resource bundle, which means that your localized messages may be
>stored in any subclass of java.util.ResourceBundle.
>
>The JDK provides these two subclasses:
>java.util.ListResourceBundle and java.util.PropertyResourceBundle.
>The latter allows you to store your key/value pairs in a properties
>file.
>
>If neither of these fit your needs, you may provide your own
>ResourceBundle subclass, which must override the handleGetObject() and
>getKeys() methods.
>
>
>Jan
>
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to