You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jeremy Quinn <je...@media.demon.co.uk> on 2004/04/09 12:36:29 UTC
i18n questions
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 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.
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
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).
I have other situations where I would like to use Class constants as
part of i18n message keys.
thanks for any suggestions
regards Jeremy
Re: i18n questions
Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 10 Apr 2004, at 13:48, Joerg Heinicke wrote:
> On 10.04.2004 12:13, Jeremy Quinn wrote:
>
>>> 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.
>> Was this a recent addition ?
>
> Not that I'm aware of. I only wrote it as I did not want to write just
> "works for me", for the case you already tested it more intensively.
It works now ;)
>>> var i18nLabel = new
>>> Packages.org.apache.cocoon.forms.util.I18nMessage("key");
>>> selectionlist[0] = {value: SimpleDescriptor.NO_VALUE, label:
>>> i18nLabel};
>> Ah Ha !!!!
>> That looks like it would work !!
>
> I hope so and would be interested if it does.
works beautifully :
importClass (Packages.org.apache.cocoon.woody.util.I18nMessage);
function getSelectionList (session, classname) {
var list = SimpleDescriptorPeer.selectionlist (session, classname);
var selectionlist = new Array (list.size () +1);
selectionlist[0] =
{ value: SimpleDescriptor.NO_VALUE, label: new I18nMessage
("upload.choose.one", "local") };
for (var i = 0; i < list.size (); i++)
selectionlist[i+1] = { value: list.get (i).getId (), label:
list.get (i).getName () };
return selectionlist;
}
>
>> We have several situations where it would be useful to be able to use
>> Package references to static properties from i18n keys or woody model
>> declarations.
>> eg.
>> <wd:range min="#{Packages.blah.SimpleDescriptor.MIN_VALUE}">
>> or
>> <message
>> key="search.#{Packages.blah.Query.EQUALS_MATCH}.match">exactly
>> matches</message>
>> as this saves you keeping declarations of the same value synchronised
>> between display and backend.
>> I suppose I could turn all of my i18n message files and woody models
>> into JX Templates, but I am not fond of the idea.
>
> That's not my part :) Though it sounds interesting. Personally I would
> not like to have the functionality doubled from JXTemplate to I18n,
> but would prefer a cocoon:/ internal pipeline catalogue. Caching is
> important then of course.
Not sure you can do that because of the negotiation down the locale
tree done by the catalogue loader.
I can probably solve this stuff by being smarter in my JX Templates,
and maybe begin to generate woody models via JXTemplate too.
Thanks
regards Jeremy
Re: i18n questions
Posted by Joerg Heinicke <jo...@gmx.de>.
On 10.04.2004 12:13, Jeremy Quinn wrote:
>> 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.
>
> Was this a recent addition ?
Not that I'm aware of. I only wrote it as I did not want to write just
"works for me", for the case you already tested it more intensively.
>> var i18nLabel = new
>> Packages.org.apache.cocoon.forms.util.I18nMessage("key");
>> selectionlist[0] = {value: SimpleDescriptor.NO_VALUE, label: i18nLabel};
>
> Ah Ha !!!!
> That looks like it would work !!
I hope so and would be interested if it does.
> We have several situations where it would be useful to be able to use
> Package references to static properties from i18n keys or woody model
> declarations.
>
> eg.
>
> <wd:range min="#{Packages.blah.SimpleDescriptor.MIN_VALUE}">
>
> or
>
> <message key="search.#{Packages.blah.Query.EQUALS_MATCH}.match">exactly
> matches</message>
>
> as this saves you keeping declarations of the same value synchronised
> between display and backend.
>
> I suppose I could turn all of my i18n message files and woody models
> into JX Templates, but I am not fond of the idea.
That's not my part :) Though it sounds interesting. Personally I would
not like to have the functionality doubled from JXTemplate to I18n, but
would prefer a cocoon:/ internal pipeline catalogue. Caching is
important then of course.
Joerg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: i18n questions
Posted by Jeremy Quinn <je...@media.demon.co.uk>.
On 9 Apr 2004, at 17:11, Joerg Heinicke wrote:
> 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:
<snip/>
I had better try again ...
>
> 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.
Was this a recent addition ?
<snip/>
>> 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};
Ah Ha !!!!
That looks like it would work !!
>> 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.
Sorry, I did not explain that very well.
We have several situations where it would be useful to be able to use
Package references to static properties from i18n keys or woody model
declarations.
eg.
<wd:range min="#{Packages.blah.SimpleDescriptor.MIN_VALUE}">
or
<message key="search.#{Packages.blah.Query.EQUALS_MATCH}.match">exactly
matches</message>
as this saves you keeping declarations of the same value synchronised
between display and backend.
I suppose I could turn all of my i18n message files and woody models
into JX Templates, but I am not fond of the idea.
Thanks
regards Jeremy
Re: i18n questions
Posted by Joerg Heinicke <jo...@gmx.de>.
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