Re: [xsl] Multilanguage help

Subject: Re: [xsl] Multilanguage help
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Wed, 22 Feb 2006 21:49:44 +0100 (CET)
Antsnio Mota wrote:

> Extremely easy to do with the document() function. I
> don't have my XML tools here but from the top of my
> head it's something like this:

> Supose you have a XML like this

> xml_pt.xml

> <translations>
>     <word id='Descripcion'>Descrigco</word>
>    (...)
> </translations>

> then, in your xsl you should have something that tell
> what the language to translate to, a param for instance.
> Supose you pass 'pt' to it.

> <xsl:param name="lang"/>
> <xsl:variable name="filename"
> select="concat('/filepath/xml_',$lang,'.xml') />

  It's a way of doing this, sure.  And it works quite well for very
simple cases.  But the problem with I18N and L10N is the order of the
variable pieces of text, like amounts, numbers of chapter, nouns, etc.
(and it unfortunately always occurs while the L10N step).

  What I did here is the following.  I have such variables in my XSLT
script (the script is generated, but you can use doc() if you want,
this doens't matter):

    <xsl:variable name="l10n.all.entries">
      <l10n xml:lang="FR">
        <entry name="text">Un peu de texte.</entry>
        <entry name="chapter">Chapitre <num/></entry>
      <l10n xml:lang="EN">
        <entry name="text">Some text.</entry>
        <entry name="chapter">Chapter <num/></entry>

    <xsl:variable name="l10n.entries"
                            xml:lang eq $l10n.lang ]"/>

  The example doesn't show the order problem, but I trust your
imagination.  In the document, I have elements like these:

    <title i18n="chapter">
      <param name="num" select="..."/>
    <para i18n="text"/>

  With the help of a few functions for retrieving the right entry and
resolve the parameters, you get a more robust system, IMHO.  And you
can easily extend the parameters system.  I have for example 'choice'
elements (sort of hashtables):

    <entry name="...">... <what this='...' that='...'/>

    <para i18n="...">
      <choice name="what"
              select="if (...) then 'this' else 'that'"/>

as well as more specific formating elements:

    <para i18n="...">
      <address name="who"
               format="'%l %f, %S %s, %P %C'"/>

  I'm sure other improvements can be done.  Like putting the format
string for an address in the placeholder in the entry, for example:

    <entry name="...">... <who fmt='...'/> ...</entry>




Nouveau : tiliphonez moins cher avec Yahoo! Messenger ! Dicouvez les tarifs exceptionnels pour appeler la France et l'international.
Tilichargez sur

Current Thread