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" <ch...@christopherschultz.net 
<mailto:ch...@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/


Reply via email to