You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Martin van Dijken <mv...@madocke.nl> on 2003/10/01 10:05:39 UTC

RE: XML ResourceBundles

Hey Keyur,

I'm not certain since I don't have a test setup, but try the following:

Have your XMLResourceBundle class print out super.getLocale() in the handleGetObject() method. What you need to know is whether super.getLocale() returns the desired Locale (fr) or the default Locale since it couldn't find the fr class nor the fr properties. If the getLocale() call returns the desired Locale(in your example fr), then you've got something to go by. 

I'm not 100% certain, but I'm afraid things won't work this way and then I think it simply is impossible to create what you describe. The framework is quite clear and rather simple and has no public or protected methods to indicate anything can be done.

Greetz,

Martin

> -----Original Message-----
> From: Keyur Shah [mailto:kshah@esri.com]
> Sent: dinsdag 30 september 2003 1:35
> To: 'taglibs-user@jakarta.apache.org'
> Subject: XML ResourceBundles
> 
> 
> I want to localize my messages using XML files. Now, I want 
> to have only one
> MyXMLResourceBundle (which extends ResourceBundle) as such:
> 
> 
> 
> 
> public class MyXMLResourceBundle extends ResourceBundle {
> 
> 
>    private Locale locale;
> 
> 
>    public MyXMLResourceBundle(Locale locale) {
> 
> 
>       this.locale = locale;
> 
> 
>       //load resources from an XML file based on the locale
> 
> 
>    }
> 
> 
>    //override ResourceBundle.getLocale()
> 
> 
>    public Locale getLocale() { return this.locale; }
> 
> 
>    //other methods
> 
> 
> }
> 
> 
> I will be using a combo of JSTL and JSF tags in my 
> application to output
> texts. As per my understanding, both of these taglibs call
> ResourceBundle.getBundle(baseName, locale) to get the 
> appropriate bundle.
> Now, the problem is this:
> 
> Say, the locale is french - "fr". The getBundle() method tries to find
> MyXMLResourceBundle_fr.class first and then it attempts to find
> MyXMLResourceBundle.properties. Now, I have none of these 
> files in my app.
> (What I have are MyXMLResourceBundle.class and 
> MyXMLResourceBundle_fr.xml
> files.) Since it cannot find the mentioned files; what ends 
> up happening is
> that the getBundle() method always ends up using the same
> MyXMLResourceBundle instance with the default locale.
> 
> What I want to see happen is this: for every different locale 
> it should
> create a new instance of MyXMLResourceBundle and use the appropriate
> localized XML file i.e. the ResourceBundle.getBundle() method 
> should call
> the MyXMLResourceBundle(locale) constructor with the 
> appropriate locale.
> 
> Now, since I don't have any control over the ResourceBundle 
> methods(!), I'd
> like to know if there is any other way for me to use XML 
> resource bundles
> and make them work with the existing JSTL / JSF tags all the same.
> 
> Thanks.
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org