cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vadim Gritsenko <va...@reverycodes.com>
Subject Re: i18n Translations to String
Date Fri, 17 Nov 2006 13:54:08 GMT
Jeremy Quinn wrote:
> 
> Now I need to work out how to do the above from FlowScript, when my i18n 
> messages may have parameters, eg :

:)

>   <message key="upload.progress.sent">Sent: {0}% ({1} of {2} bytes). 
> Filename: {3}.</message>
> 
> I have not worked out yet how I18nTransformer does this ....

All the work is done in ParamSaxBuffer. So instead of using 
XMLResourceBundle.getString(key), you should be using getObject(key):

   Map parameters = new HashMap();
   parameters.put("1", "1234567");
   ...
   ParamSaxBuffer message = (ParamSaxBuffer) bundle.getObject(key);
   message.toSAX(handler, parameters);


ParamSaxBuffer currently does not have toString(Map parameters) method in case 
if you want to get only text of the message, but between SaxBuffer.toString() 
and ParamSaxBuffer.toSAX(handler, parameters), I'm sure it won't take you long 
to implement toString(Map parameters). :)


> Ideally, one should be able to get a String which contains any tags that 
> were in the i18n Message, as widgets may want to use these, by injecting 
> them as InnerHTML.

You'd have to use some of those ContentHandler implementations which would 
serialize SAX events into String (using TrAX, or there is 
org.outerj.daisy.xmlutil.XmlSerializer from daisy-util.jar).


> JSON Serialization, we need better solutions ....
> 
> I am currently using JXT for serializing the JSON Response (as this 
> allows the use of XMLizable I18nMessage), but it is a pretty foul way of 
> doing it. I am not sure that JXT is able to determine the class of 
> Objects in a nice way, I tried this :
> 
>     <jx:when test"${item instanceof Packages.java.lang.Number}"> . . . 
> </jx:when>
> 
> But jexl does not like 'instanceof'.

It's not Java ;)


> This means that my serialization currently has to turn everything into a 
> String. (yuk)

Try testing for a presence of a method? In JavaScript, you'd do

   if (item.toSAX) {
     // XMLizable
   }


> What kind of Objects should we expect to be serializing to JSON ?
> 
>   JavaScript: Objects, functions and primitives: should be easy once 
> FlowScript is updated to have .toSource().
> 
>   Java: Maps, Collections, Strings, Numbers, Booleans, Dates, 
> primitives: use generic FlowScript (could be adapted from Dojo's code?)?
> 
>   Java: POJOs : use Jettison ?

No idea :)


>   Java: I18n Message Strings : a must-have ..... Dojo's i18n mechanism 
> is not in place yet, without this it will be very difficult to i18n dojo 
> widgets. We may not even want to have 2 i18n mechanisms with 2 types of 
> resource file format.

Sounds reasonable.


> ATM, we only have 2 widgets that use JSON, but IMHO this number will 
> grow. We also need a clear route for people developing their own 
> widgets, so can we all have a think about this ?

Yes, guys, please think about ... widgets! :)

Vadim

Mime
View raw message