cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: i18n questions
Date Fri, 09 Apr 2004 16:11:56 GMT
On 09.04.2004 12:36, Jeremy Quinn wrote:

> Hi All
> 
> I use i18n a lot with Woody and Flowscript. I prefer to keep all user 
> message strings out of woody files and flowscripts, regardless of 
> whether the project needs translating to another language.

I do the same for my project.

>  I have a couple of situations where I have not worked out how to use 
> i18n effectively. Both are related to dynamic selectionlists. Are there 
> solutions for these?
> 
> 1. We need to internationalise custom fail messages. Placing i18n tags 
> inside do not result in their being looked up. We cannot use Woody's 
> built-in message because it would mean nothing in to the User, as we are 
> testing to see if they have left the menu in it's default unset state by 
> checking the value is greater than 0.

Tested it with CForms samples and it works for me:

form1.xml

<fd:field id="birthdate" required="true">
   <fd:label>Your birthdate (dd/MM/yyyy):</fd:label>
   <fd:datatype base="date">
     <fd:convertor>
       <fd:patterns>
         <fd:pattern>dd/MM/yyyy</fd:pattern>
       </fd:patterns>
     </fd:convertor>
   </fd:datatype>
   <fd:validation>
     <fd:range min="Date(1850, 1, 1)" max="Date(2150, 1, 1)">
       <fd:failmessage><i18n:text key="deadnotborn"/></fd:failmessage>
     </fd:range>
   </fd:validation>
</fd:field>

output:

<fi:field id="birthdate" required="true">
   <fi:value>09/04/2204</fi:value>
   <fi:validation-message>
     <i18n:text xmlns:i18n="http://apache.org/cocoon/i18n/2.1" 
key="deadnotborn"/>
    </fi:validation-message>
   <fi:label>Your birthdate (dd/MM/yyyy):</fi:label>
   <fi:styling type="date" format="dd/MM/yyyy"/>
</fi:field>

Now using the i18n transformer afterwards everything should go on as 
normal. Hopefully the feature was not added between your Woody version 
and the recent CForms version.

> 2. We are making dynamic selectionlists by reading a db and outputting 
> value/label pairs for woody, we need to add an entry at the beginning 
> (representing the no selection above) whose text should be 
> internationalised. How would you go about internationalising the string 
> "Choose One" in the context of a flowscript below?
> 
> 
> Sitemap snippet (we want to fall-back on the built-in woody messages):
> 
> <map:transformer name="i18n" 
> src="org.apache.cocoon.transformation.I18nTransformer">
>     <catalogues default="woody">
>         <catalogue id="local" name="upload" location="content/i18n"/>
>         <catalogue id="woody" name="WoodyMessages"
>                 location="context://samples/woody/messages"/>
>     </catalogues>
>     <cache-at-startup>true</cache-at-startup>
> </map:transformer>
> 
> 
> Woody Model snippet:
> 
> <wd:field id="category" required="true">
>     <wd:label><i18n:text 
> i18n:catalogue="local">upload.category.label</i18n:text>: </wd:label>
>     <wd:hint><i18n:text 
> i18n:catalogue="local">upload.category.hint</i18n:text></wd:hint>
>     <wd:datatype base="long"/>
>     <wd:validation>
>         <wd:range min="1">
>             <!-- i18n this string -->
>               <wd:failmessage>Please choose one of these 
> items.</wd:failmessage>
>             </wd:range>
>     </wd:validation>
>     <wd:selection-list type="flow-jxpath"
>         list-path="categories" value-path="value" label-path="label"/>
> </wd:field>
> 
> 
> FlowScript snippet:
> 
> function upload (form) {
>     . . .
>     var categories = getSelectionList (session, ImageCategory.ROLE);
>     var types = getSelectionList (session, ImageType.ROLE);
>     . . .
>     form.showForm (screen, {categories: categories, types: types});
>     . . .
> }
> 
> function getSelectionList (session, classname) {
>     var list = SimpleDescriptorPeer.list (session, classname);
>     var selectionlist = new Array (list.size () +1);
>     selectionlist[0] = {value: SimpleDescriptor.NO_VALUE, label: "Choose 
> One"}; // i18n this string

Do not really know, but maybe it works when instead setting label to a 
string setting it to I18nMessage would work? Something like

var i18nLabel = new 
Packages.org.apache.cocoon.forms.util.I18nMessage("key");
selectionlist[0] = {value: SimpleDescriptor.NO_VALUE, label: i18nLabel};

>     for (var i = 0; i < list.size (); i++)
>         selectionlist[i+1] = {value: list.get (i).id, label: list.get 
> (i).name};
>     return out;
> }
> 
> These sample points out another gritty little issue.
> The flowscript uses SimpleDescriptor.NO_VALUE, fine, but Woody has to 
> use <wd:range min="1"> while they are both referring to the same value 
> (+1 in woody's case).

Don't understand this.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message