|
Subject: [xsl] RE : [xsl] switching between multiple languages in XSL From: Florent Georges <darkman_spam@xxxxxxxx> Date: Tue, 27 Jun 2006 23:42:42 +0200 (CEST) |
Jason Viers wrote:
Hi
> We're transforming a XML file to HTML via XSL, and we'd
> like the XSL to be usable across multiple languages. The
> XML file being transformed does _not_ have the text we'd
> like to select between, just an indication as to what
> language should be used. There are things like static
If I understand right your problem, you can use external
XML files, dictionnaries, containing the actual translated
sentences. You'll access them via document(), for example
document(concat('i18n/dico-', $i18n-lang, '.xml')) where
$i18n-lang is the language name, for example 'EN', selected
in your input document, and the 'i18n' directory having a
file named 'dico-<lang>.xml', a dictionnary, for each
supported languages.
Depending on your problem, the dictionnaries can be a flat
set of named entries, or a highly structured XML document
organizing the entries. From my little experience, I
recommend a flat dictionnary, where structure can instead be
introduced in the entry names. But it depends on a lot of
things we don't know here IMHO.
So to be a little more concrete:
<!-- in your XSLT script -->
<xsl:variable name="i18n-lang" select="../in/your/input"/>
<xsl:variable name="i18n-dico"
select="document('use concat & $i18n-lang')"/>
<!-- use a named template in XSLT 1.0 -->
<xsl:function name="my:i18n-entry">
<xsl:param name="name"/>
<!-- return an entry or a string, depends on the
structure of your dictionnaries -->
</xsl:function>
<!-- in each dico -->
<dico lang="EN">
<entry name="an.entry">The actual text.</entry>
<entry name="other.entry">Other text.</entry>
...
</dico>
But a common problem with I18N is the placement in
variable text, as dates and other numbers extracted from
your input tree for example. So you'll need a way to
parametrize the entries. You can put named place holders in
the entries, with empty elements:
<entry name="footer.last.modified">This page was last
modified on <date/>.</entry>
and in XSLT:
<!-- i18n-entry uses my:i18n-entry() to get the entry,
and replaces the place holders, matched by name -->
<xsl:call-template name="i18n-entry">
<xsl:with-param name="name"
select="'footer.last.modified'"/>
<xsl:with-param name="params">
<param name="date" value="{XPath for date}"/>
</xsl:with-param>
</xsl:call-template>
These are basic ideas I use each day in my work. All that
depends on your specific needs. I think I already post a
message on XSL List describing all that. You can search the
archives.
Regards,
--drkm
___________________________________________________________________________
Yahoo! Mail riinvente le mail ! Dicouvrez le nouveau Yahoo! Mail et son interface rivolutionnaire.
http://fr.mail.yahoo.com
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] switching between multipl, Sara Mitchell | Thread | [xsl] RE : [xsl] switching between , Jason Viers |
| Re: [xsl] switching between multipl, Sara Mitchell | Date | RE: [xsl] Converting CSV to XML wit, Pantvaidya, Vishwaji |
| Month |