You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2016/05/23 13:31:25 UTC

[2.1] Non-trivial uses of i18n transformer

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

All,

I'm finally getting around to internationalizing the XSLT-based parts
of my application, and I'm running into a problem with non-trivial
uses of <i18n:text> in a template.

Here's an excellent example of the kind of thing I'm having trouble
with. I have a single XML document going through a pipeline with a few
transformations in it. There is one major transform where pretty much
everything interesting happens. I'd like to use <i18n> in there to
produce an HTML <a> element with a localized "title" attribute.
Something like this:

<xsl:template match="p:foo">
  <a href="..." title="This is some English text">click me</a>
</xsl:template>

Localizing the "click me" text is trivial. Doing the same with the
"title" attribute is not.

   <a title="<i18n:text key="some.text" />"  [...] >

That obviously won't work because the attribute won't be parsed and
evaluated by the XSLT parser. Use of {} around it doesn't work because
it's an element, not an expression.

  <xsl:element name="a">
    <xsl:attribute name="title">
      <i18n:text key="some.text" />
    </xsl:attribute>
    [...]
  </xsl:element>

That doesn't work because <xsl:attribute> evidently can't contain
<i18n:text>. At first, this irritated me but then I realized that this
would never work, because the second case would basically degenerate
into the first case after the <map:transform> completed its work for
this template before I (later) ran the I18nTransformer.

The only idea I've had is to flip the current i18n process on its head
and instead do this:

  <map:match pattern="/foo">
    <map:generate src="my.xml.document.xml" />

    <map:transform src="cocoon://localized-transform.xsl" />

    <map:serialize />
  </map:match>

  <map:match pattern="/localized-transform.xsl">
    <map:generate src="original.xsl" />

    <map:transform type="i18n">
      <map:parameter name="locale" value="en_US" />
    </map:transform>

    <map:serialize />
  </map:match>

So instead of transforming the input document with an
internationalized stylesheet, then transforming the result with the
i18n transformer, I first transform the transformer itself to get a
localized transformer, and transform the input document with *that*.

Is that "recommended technique"? Alternatively, is that entirely stupid?

If this is a good idea, how specifically can I accomplish what I have
above? I haven't yet tried it, but I'm concerned I'll have the same
problem with elements not being allowed in other elements.

Any suggestions?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAldDBi0ACgkQ9CaO5/Lv0PC3HQCfQLoPna+oFFoWxXggz0rKwxis
vyAAn1IrMa5SNcy+8fhr6Wt5JxdJ8abT
=i48t
-----END PGP SIGNATURE-----

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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 23/05/2016 15:44, Christopher Schultz wrote:
> Francesco,
>
> On 5/23/16 9:41 AM, Francesco Chicchiricc� wrote:
> > On 23/05/2016 15:39, Marc Salvetti wrote:
> >>> Hi Chris, > > Try something like this <a
> > title="some.catalogue:some.text" I18n-attr="title"/> > > That's by
> > memory but should find the exact syntax in  the doc Here it is:
>
> > https://cocoon.apache.org/2.1/userdocs/i18nTransformer.html
>
> > <para title="first" name="article"  i18n:attr="title name">
> > <i18n:text>This text will be translated.</i18n:text> </para>
>
> Aw, geez. How did I miss that in the docs? That's WAY better than the
> stupid stuff I was coming up with.

You're welcome :-)

-- 
Francesco Chicchiricc�

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC,
Olingo PMC, CXF Committer, OpenJPA Committer
http://home.apache.org/~ilgrosso/



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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Francesco,

On 5/23/16 9:41 AM, Francesco Chicchiricc� wrote:
> On 23/05/2016 15:39, Marc Salvetti wrote:
>>> Hi Chris, > > Try something like this <a
> title="some.catalogue:some.text" I18n-attr="title"/> > > That's by 
> memory but should find the exact syntax in  the doc Here it is:
> 
> https://cocoon.apache.org/2.1/userdocs/i18nTransformer.html
> 
> <para title="first" name="article"  i18n:attr="title name"> 
> <i18n:text>This text will be translated.</i18n:text> </para>

Aw, geez. How did I miss that in the docs? That's WAY better than the
stupid stuff I was coming up with.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAldDCTIACgkQ9CaO5/Lv0PBt/ACgolWWUsFvXAHdCGehUxNoxN0F
TcwAmgKf5WgUHXvrvVTAzpi1IIvc5GOA
=xWAl
-----END PGP SIGNATURE-----

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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 23/05/2016 15:39, Marc Salvetti wrote:
>  > Hi Chris, > > Try something like this <a 
title="some.catalogue:some.text" I18n-attr="title"/> > > That's by 
memory but should find the exact syntax in  the doc
Here it is:

https://cocoon.apache.org/2.1/userdocs/i18nTransformer.html

<para title="first" name="article"  i18n:attr="title name">
   <i18n:text>This text will be translated.</i18n:text>
</para>

HTH
Regards.

> Le 23 mai 2016 8:31 PM, "Christopher Schultz" <chris@christopherschultz.net <ma...@christopherschultz.net>> a �crit :  >
> All,
>
> I'm finally getting around to internationalizing the XSLT-based parts
> of my application, and I'm running into a problem with non-trivial
> uses of <i18n:text> in a template.
>
> Here's an excellent example of the kind of thing I'm having trouble
> with. I have a single XML document going through a pipeline with a few
> transformations in it. There is one major transform where pretty much
> everything interesting happens. I'd like to use <i18n> in there to
> produce an HTML <a> element with a localized "title" attribute.
> Something like this:
>
> <xsl:template match="p:foo">
>   <a href="..." title="This is some English text">click me</a>
> </xsl:template>
>
> Localizing the "click me" text is trivial. Doing the same with the
> "title" attribute is not.
>
>    <a title="<i18n:text key="some.text" />"  [...] >
>
> That obviously won't work because the attribute won't be parsed and
> evaluated by the XSLT parser. Use of {} around it doesn't work because
> it's an element, not an expression.
>
>   <xsl:element name="a">
>     <xsl:attribute name="title">
>       <i18n:text key="some.text" />
>     </xsl:attribute>
>     [...]
>   </xsl:element>
>
> That doesn't work because <xsl:attribute> evidently can't contain
> <i18n:text>. At first, this irritated me but then I realized that this
> would never work, because the second case would basically degenerate
> into the first case after the <map:transform> completed its work for
> this template before I (later) ran the I18nTransformer.
>
> The only idea I've had is to flip the current i18n process on its head
> and instead do this:
>
>   <map:match pattern="/foo">
>     <map:generate src="my.xml.document.xml" />
>
>     <map:transform src="cocoon://localized-transform.xsl" />
>
>     <map:serialize />
>   </map:match>
>
>   <map:match pattern="/localized-transform.xsl">
>     <map:generate src="original.xsl" />
>
>     <map:transform type="i18n">
>       <map:parameter name="locale" value="en_US" />
>     </map:transform>
>
>     <map:serialize />
>   </map:match>
>
> So instead of transforming the input document with an
> internationalized stylesheet, then transforming the result with the
> i18n transformer, I first transform the transformer itself to get a
> localized transformer, and transform the input document with *that*.
>
> Is that "recommended technique"? Alternatively, is that entirely stupid?
>
> If this is a good idea, how specifically can I accomplish what I have
> above? I haven't yet tried it, but I'm concerned I'll have the same
> problem with elements not being allowed in other elements.
>
> Any suggestions?
>
> Thanks,
> -chris

-- 
Francesco Chicchiricc�

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC,
Olingo PMC, CXF Committer, OpenJPA Committer
http://home.apache.org/~ilgrosso/



Re: [2.1] Non-trivial uses of i18n transformer

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 23/05/2016 16:24, Christopher Schultz wrote:
> Francesco,
>
> On 5/23/16 9:58 AM, Francesco Chicchiricc� wrote:
>> On 23/05/2016 15:55, Christopher Schultz wrote:
>>> Marc,
>>>
>>> On 5/23/16 9:39 AM, Marc Salvetti wrote:
>>>> Try something like this <a title="some.catalogue:some.text"
>>>> I18n-attr="title"/>
>>>> That's by memory but should find the exact syntax in  the doc
>>> Yep, this totally works.
>>>
>>> Since I'm on a roll, how about this:
>>>
>>> <script type="text/javascript"><xsl:comment>
>>>    function whatever() {
>>>      document.getElementById('link').title = 'translated-text';
>>>    }
>>> </xsl:comment></script>
>>>
>>> Probably the simplest way is to just remove the <xsl:comment> from
>>> around the script, since I don't think that's actually been necessary
>>> since the days of MSIE4. Is there another convenient way to do it?
>> Why not
>>
>> <script type="text/javascript">
>> <![CDATA[
>>    function whatever() {
>>      document.getElementById('link').title = 'translated-text';
>>    }
>> ]]>
>> </script>
> Since the 'translated-text' is really <i18n:text>, it would be ignored
> if it were in a CDATA section.
>
> <script type="text/javascript">
> <![CDATA[
>    function whatever() {
>      document.getElementById('link').title = '<i18n:text key="foo" />';
>    }
> ]]>
> </script>
>
> That's not going to work any better than the javascript embedded within
> an <xsl:comment> element, right?

Ouch, you're definitely right :-)

Regards.

-- 
Francesco Chicchiricc�

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC,
Olingo PMC, CXF Committer, OpenJPA Committer
http://home.apache.org/~ilgrosso/


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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Marc Salvetti <sa...@gmail.com>.
Hello,

I don't think you can have translated text embeded in js code like this. I
think you have to move the string to the xml markup as in your first
message, then let js handle strings that are already translated

2016-05-23 21:24 GMT+07:00 Christopher Schultz <chris@christopherschultz.net
>:

> Francesco,
>
> On 5/23/16 9:58 AM, Francesco Chicchiriccò wrote:
> > On 23/05/2016 15:55, Christopher Schultz wrote:
> >> Marc,
> >>
> >> On 5/23/16 9:39 AM, Marc Salvetti wrote:
> >> > Try something like this <a title="some.catalogue:some.text"
> >> > I18n-attr="title"/>
> >>
> >> > That's by memory but should find the exact syntax in  the doc
> >>
> >> Yep, this totally works.
> >>
> >> Since I'm on a roll, how about this:
> >>
> >> <script type="text/javascript"><xsl:comment>
> >>   function whatever() {
> >>     document.getElementById('link').title = 'translated-text';
> >>   }
> >> </xsl:comment></script>
> >>
> >> Probably the simplest way is to just remove the <xsl:comment> from
> >> around the script, since I don't think that's actually been necessary
> >> since the days of MSIE4. Is there another convenient way to do it?
> >
> > Why not
> >
> > <script type="text/javascript">
> > <![CDATA[
> >   function whatever() {
> >     document.getElementById('link').title = 'translated-text';
> >   }
> > ]]>
> > </script>
>
> Since the 'translated-text' is really <i18n:text>, it would be ignored
> if it were in a CDATA section.
>
> <script type="text/javascript">
> <![CDATA[
>   function whatever() {
>     document.getElementById('link').title = '<i18n:text key="foo" />';
>   }
> ]]>
> </script>
>
> That's not going to work any better than the javascript embedded within
> an <xsl:comment> element, right?
>
> Thanks,
> -chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: [2.1] Non-trivial uses of i18n transformer

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Francesco,

On 5/23/16 9:58 AM, Francesco Chicchiricc� wrote:
> On 23/05/2016 15:55, Christopher Schultz wrote:
>> Marc,
>>
>> On 5/23/16 9:39 AM, Marc Salvetti wrote:
>> > Try something like this <a title="some.catalogue:some.text"
>> > I18n-attr="title"/>
>>
>> > That's by memory but should find the exact syntax in  the doc
>>
>> Yep, this totally works.
>>
>> Since I'm on a roll, how about this:
>>
>> <script type="text/javascript"><xsl:comment>
>>   function whatever() {
>>     document.getElementById('link').title = 'translated-text';
>>   }
>> </xsl:comment></script>
>>
>> Probably the simplest way is to just remove the <xsl:comment> from
>> around the script, since I don't think that's actually been necessary
>> since the days of MSIE4. Is there another convenient way to do it?
> 
> Why not
> 
> <script type="text/javascript">
> <![CDATA[
>   function whatever() {
>     document.getElementById('link').title = 'translated-text';
>   }
> ]]>
> </script>

Since the 'translated-text' is really <i18n:text>, it would be ignored
if it were in a CDATA section.

<script type="text/javascript">
<![CDATA[
  function whatever() {
    document.getElementById('link').title = '<i18n:text key="foo" />';
  }
]]>
</script>

That's not going to work any better than the javascript embedded within
an <xsl:comment> element, right?

Thanks,
-chris

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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 23/05/2016 15:55, Christopher Schultz wrote:
> Marc,
>
> On 5/23/16 9:39 AM, Marc Salvetti wrote:
> > Try something like this <a title="some.catalogue:some.text"
> > I18n-attr="title"/>
>
> > That's by memory but should find the exact syntax in  the doc
>
> Yep, this totally works.
>
> Since I'm on a roll, how about this:
>
> <script type="text/javascript"><xsl:comment>
>   function whatever() {
>     document.getElementById('link').title = 'translated-text';
>   }
> </xsl:comment></script>
>
> Probably the simplest way is to just remove the <xsl:comment> from
> around the script, since I don't think that's actually been necessary
> since the days of MSIE4. Is there another convenient way to do it?

Why not

<script type="text/javascript">
<![CDATA[
   function whatever() {
     document.getElementById('link').title = 'translated-text';
   }
]]>
</script>

?

-- 
Francesco Chicchiricc�

Tirasa - Open Source Excellence
http://www.tirasa.net/

Involved at The Apache Software Foundation:
member, Syncope PMC chair, Cocoon PMC,
Olingo PMC, CXF Committer, OpenJPA Committer
http://home.apache.org/~ilgrosso/



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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marc,

On 5/23/16 9:39 AM, Marc Salvetti wrote:
> Try something like this <a title="some.catalogue:some.text" 
> I18n-attr="title"/>
> 
> That's by memory but should find the exact syntax in  the doc

Yep, this totally works.

Since I'm on a roll, how about this:

<script type="text/javascript"><xsl:comment>
  function whatever() {
    document.getElementById('link').title = 'translated-text';
  }
</xsl:comment></script>

Probably the simplest way is to just remove the <xsl:comment> from
around the script, since I don't think that's actually been necessary
since the days of MSIE4. Is there another convenient way to do it?

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAldDC+EACgkQ9CaO5/Lv0PDbdQCfet+DodTVUTYu/zw0Y6FKu07a
QLkAn2RZgvnbABrZBM0P+eCFG7aCHNr+
=4NcC
-----END PGP SIGNATURE-----

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


Re: [2.1] Non-trivial uses of i18n transformer

Posted by Marc Salvetti <sa...@gmail.com>.
Hi Chris,

Try something like this <a title="some.catalogue:some.text"
I18n-attr="title"/>

That's by memory but should find the exact syntax in  the doc

Hope this helps,
Marc
Le 23 mai 2016 8:31 PM, "Christopher Schultz" <ch...@christopherschultz.net>
a écrit :

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> All,
>
> I'm finally getting around to internationalizing the XSLT-based parts
> of my application, and I'm running into a problem with non-trivial
> uses of <i18n:text> in a template.
>
> Here's an excellent example of the kind of thing I'm having trouble
> with. I have a single XML document going through a pipeline with a few
> transformations in it. There is one major transform where pretty much
> everything interesting happens. I'd like to use <i18n> in there to
> produce an HTML <a> element with a localized "title" attribute.
> Something like this:
>
> <xsl:template match="p:foo">
>   <a href="..." title="This is some English text">click me</a>
> </xsl:template>
>
> Localizing the "click me" text is trivial. Doing the same with the
> "title" attribute is not.
>
>    <a title="<i18n:text key="some.text" />"  [...] >
>
> That obviously won't work because the attribute won't be parsed and
> evaluated by the XSLT parser. Use of {} around it doesn't work because
> it's an element, not an expression.
>
>   <xsl:element name="a">
>     <xsl:attribute name="title">
>       <i18n:text key="some.text" />
>     </xsl:attribute>
>     [...]
>   </xsl:element>
>
> That doesn't work because <xsl:attribute> evidently can't contain
> <i18n:text>. At first, this irritated me but then I realized that this
> would never work, because the second case would basically degenerate
> into the first case after the <map:transform> completed its work for
> this template before I (later) ran the I18nTransformer.
>
> The only idea I've had is to flip the current i18n process on its head
> and instead do this:
>
>   <map:match pattern="/foo">
>     <map:generate src="my.xml.document.xml" />
>
>     <map:transform src="cocoon://localized-transform.xsl" />
>
>     <map:serialize />
>   </map:match>
>
>   <map:match pattern="/localized-transform.xsl">
>     <map:generate src="original.xsl" />
>
>     <map:transform type="i18n">
>       <map:parameter name="locale" value="en_US" />
>     </map:transform>
>
>     <map:serialize />
>   </map:match>
>
> So instead of transforming the input document with an
> internationalized stylesheet, then transforming the result with the
> i18n transformer, I first transform the transformer itself to get a
> localized transformer, and transform the input document with *that*.
>
> Is that "recommended technique"? Alternatively, is that entirely stupid?
>
> If this is a good idea, how specifically can I accomplish what I have
> above? I haven't yet tried it, but I'm concerned I'll have the same
> problem with elements not being allowed in other elements.
>
> Any suggestions?
>
> Thanks,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEARECAAYFAldDBi0ACgkQ9CaO5/Lv0PC3HQCfQLoPna+oFFoWxXggz0rKwxis
> vyAAn1IrMa5SNcy+8fhr6Wt5JxdJ8abT
> =i48t
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>