cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter C. Verhage" <pete...@zeelandnet.nl>
Subject OT: Built-in multilanguage support
Date Wed, 28 Mar 2001 21:12:57 GMT
Did you known XML/XSLT has built-in support for multi language XML files?
You can create a file similar to this one:

<page>
  <para xml:lang="en">
    <b>test....</b>
  </para>
  <para xml:lang="nl">
    <b>test.... (nl)</b>
  </para>
  <para>
    <b xml:lang="en-us">test...</b>
    <b xml:lang="nl">test... (nl)</b>
  </para>
</page>

In your stylesheet you can use the lang function to check in which language
a certain element is. For example if you want to show all the dutch b tags,
just use something like this:

<xsl:template match="page">
  <html>
  <body>
    <xsl:for-each select="para/b[lang('nl')]">
      <b><xsl:value-of select="."/></b>
    </xsl:for-each>
  </body>
  </html>
</xsl:template>

Please notice: tags inherit the language of their ancestors, but can
override it with their own...

Why I post this you ask? In the past there have been a lot people asking for
a feature like this in Cocoon. XML/XSL does have native support for a
feature like this, so you can just use XML/XSL, and don't have to mess with
XSP to do something like this.

Note, you might ask how do I know the users selected language? You can use
<xsl:param name="C_language"/>, <xsl:param name="S_language"/> or <xsl:param
name="language"/> in the root of your XSL stylesheet to get the cookie
language param, the session language param or the request language param. As
you can see, plenty of possibilities...

Regards,

Peter

P.S.
This is what the specs tell us about the lang function:

Function: boolean lang(string)
The lang function returns true or false depending on whether the language of
the context node as specified by xml:lang attributes is the same as or is a
sublanguage of the language specified by the argument string. The language
of the context node is determined by the value of the xml:lang attribute on
the context node, or, if the context node has no xml:lang attribute, by the
value of the xml:lang attribute on the nearest ancestor of the context node
that has an xml:lang attribute. If there is no such attribute, then lang
returns false. If there is such an attribute, then lang returns true if the
attribute value is equal to the argument ignoring case, or if there is some
suffix starting with - such that the attribute value is equal to the
argument ignoring that suffix of the attribute value and ignoring case. For
example, lang("en") would return true if the context node is any of these
five elements:
<para xml:lang="en"/>
<div xml:lang="en"><para/></div>
<para xml:lang="EN"/>
<para xml:lang="en-us"/>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

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


Mime
View raw message