You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stefano Mazzocchi <st...@apache.org> on 2000/05/18 14:08:04 UTC

Natural Languages [was Re: external entities]

Mike Engelhart wrote:
> 
> Mike Engelhart wrote:
> 
> > I get the data out of the ResourceBundle by calling getString() on the
> > correct resourceBundle which returns say "Zus&auml;tzliche Details". Do you
> > think that has something to do with it?
> 
> on 5/17/00 5:28 PM, Paul Russell at paul@luminas.co.uk wrote:
> 
> > Ahh. Yeah, that won't work - the &auml; gets converted to unicode
> > during the parsing phase, however if you use getString from within
> > an XSP, the text will never be parsed. Two options - you could
> > either write a chunk of code that takes the above and turns it into
> > unicode by looking up the character code in a hash, or you could
> > put the actual character into the resourcebundle itself (using
> > some strange key combination or other). Either should work.
> Crap... this isn't going right.  I can't put them into my XSP's directly or
> else i'm going to have to put a bunch of non-data information like text
> labels into my XML documents and I completely lose separation of
> presentation/data which is why I'm using Cocoon in the first place.
> 
> any other ideas - anyone :-) I'm going to try posting to dev to see if
> anyone else has any ideas. thanks

Question: is it _necessary_ to use Java ResourceBundles?

I mean, the use of xml files as resource bundles could simplify your
job...

<resources>
 <resource xml:lang=".." name="..." value="..."/>
 ...
</resources>

then we could create some xsp taglib that does

<xsp:page>
 <i18n:resources href="..."/>
 <document>
  <title><i18n:resource name="title"/></title>
 </document>
 ...
</xsp:page>

which could generate some java code like

 String lang = request.getLocale().getLanguage();
 ...
 if (lang == "en")
   out("Hello World!");
 else if (lang == "it")
   out("Ciao a tutti!");
 else if (lang == "fr")
   out("Salut tout le monde!);

having parsed and interpreted the resources file at compilation time.

Not a trivial taglib, but I think it's impossible even today.

Ricardo, am I right?

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



Re: Natural Languages [was Re: external entities]

Posted by Mike Engelhart <me...@earthtrip.com>.
on 5/18/00 7:08 AM, Stefano Mazzocchi at stefano@apache.org wrote:

> Question: is it _necessary_ to use Java ResourceBundles?
> 
> I mean, the use of xml files as resource bundles could simplify your
> job...
> 
> <resources>
> <resource xml:lang=".." name="..." value="..."/>
> ...
> </resources>
> 
> then we could create some xsp taglib that does
> 
> <xsp:page>
> <i18n:resources href="..."/>
> <document>
> <title><i18n:resource name="title"/></title>
> </document>
> ...
> </xsp:page>
> 
> which could generate some java code like
> 
> String lang = request.getLocale().getLanguage();
> ...
> if (lang == "en")
> out("Hello World!");
> else if (lang == "it")
> out("Ciao a tutti!");
> else if (lang == "fr")
> out("Salut tout le monde!);
> 
> having parsed and interpreted the resources file at compilation time.
> 
> Not a trivial taglib, but I think it's impossible even today.
> 
> Ricardo, am I right?

That would be very, very nice but as the taglib documentation is still in
it's infancy, trying to make a taglib like that would be a laborious slow
process for me and I need to finish this project first.
But... having a big if/then to handle the language determination seems a
little verbose.  
Maybe what would be good would be to parse the xml file at application
start, maybe have a configuration setting where Cocoon looks for a
languages.xml document and then read that into a map of HashMap's. then in
the tablib do something like:
<xsp:page>
    <title><i18n:resource name="title"/></title>
</xsp:page>

which would generate:
    String lang = request.getLocale().getLanguage();
    out((String) ((Map) LanguageMap.get(lang)).get(name));

or something like that.  One thing to mention though is that
ResourceBundle's automatically fall back to their inherited ResourceBundle
so it's easy to use. This would probably be non-trivial to create in an XML
version but then again, I may just not have any idea how to do it.

Mike