cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <>
Subject Re: ResourceBundles - was [RT] i18n
Date Mon, 12 Jun 2000 16:43:36 GMT
Mike Engelhart wrote:

> I've been following the i18n thread and last night had a few minutes to whip
> up some code.
> Here's my thoughts (I guess "random" thoughts :-))
> 1)  We all like XML for configuration.  Properties are OK but XML is better
> and portable.
> 2)  I've been using ResourceBundle's a lot and like them for several reasons
> some of which are that they've already been developed (my personal
> favorite), they're debugged, they're standard Java and really easy to use
> and caching is handled automatically so they only get loaded once by the
> classloader
> i've been using PropertyResourceBundle's in my code but have wanted an XML
> based solution. My suggestion is this (please remove code and ideas that
> suck and replace them with better code & ideas that don't suck).  Also be
> advised that I have not even looked at C2 yet so my understanding of the
> sitemap is basically non-existant so I didn't try and integrate this within
> the C2 architecture.. :-(  This is solely to allow us to use XML documents
> but still get all the ResourceBundle qualities that are cool.

I like using existing code to.  No sense in reinventing the wheel if it performs

your needs.

> Then use the following class, I'm calling it CocoonResourceBundle which
> reads in XML files of the following format (again replace XML that sucks
> with XML that doesn't suck).
> <!-- lang_en.xml -->
> <?xml version="1.0"?>
> <document xml:lang="en">
>     <word>
>         <key>_DATE</key>
>         <value>Date</value>
>     </word>
>     <word>
>         <key>_TIME</key>
>         <value>Time</value>
>     </word>
> </document>

I would propose a slightly different document style.  The style that you
proposed offers no advantage over Property files--its more verbose,
not as easy to follow.  I would propose the following style that incorporates
the concept of resource groups.

<?xml version="1.0"?>
<resource xml:lang="en">
  <group id="error">
    <value id="500">Internal Server Error</value>
    <value id="404">Page not found</value>
  <group id="uri">
    <value id="addUser">user/add</value>
    <value id="killUser">user/obliterate</value>
  <group id="form">
    <value id="userName">Enter the user's name here</value>

That way, we have the ability to group the informaiton into some form
of context.  It is simple, straight-forward, and provides a benefit over
simple property files.

Once we have our XMLResourceBundle object, we can get the resource
by id.  Something like this would be possible:

ResourceBundle res;
res = XMLResourceFactory.getResourceBundle(String role);
res.getString(String key);

View raw message