cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
Subject Re: ResourceBundles - was [RT] i18n
Date Tue, 13 Jun 2000 11:19:49 GMT
Berin Loritsch wrote:
> 
> 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>
>   <group id="uri">
>     <value id="addUser">user/add</value>
>     <value id="killUser">user/obliterate</value>
>   </group>
>   <group id="form">
>     <value id="userName">Enter the user's name here</value>
>   </group>
> </resource>
> 
> 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);

Hey, I like this and I think this is general enough to be incorporated
into Avalon as a very common block (like logging, thread management,
object storing and such).

Just one thing on the schema: the use of "id" could create naming
problems since ids cannot be repeated inside the same file. So I'd
suggest:

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

Note how the syntax

 <resource name="xxx" value="yyy">

is equivalent to

 <resource name="xxx>yyy</resource>

which is perfectly legal and allows you to use the markup you like the
most.

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<stefano@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------



Mime
View raw message