i18n via XSLT import?

D

Darren Davison

Hi,
I have a documentation tool based on Java and XSLT that I want to add i18n
capability to. There are around 8 stylesheets that process a Source
generated by the Java code and some of the static labels across the
stylesheets are the same.

Ideally I'd like to import a set of variables into each template, and
preferably based on an XSLT parameter (the locale) but this obviously
doesn't work:

<xsl:param name="locale">lang-en_GB.xslt</xsl:param>
<xsl:import href="$locale"/>

I don't want to define the generic stylesheets as imports from the
language specific ones because then I would have 8 duplicates for each
supported langauge. So is there a suitable mechanism I can use?

Regards,
 
D

Darren Davison

(replying to my own post here)

don't know if this is the best way to do this, but I solved it for now by
importing a stylesheet containing only parameter declarations into each of
the other stylesheets. The parameters themselves are set in the Java
code. Seems to work ok.

Regards,
 
T

Tjerk Wolterink

Darren said:
(replying to my own post here)

don't know if this is the best way to do this, but I solved it for now by
importing a stylesheet containing only parameter declarations into each of
the other stylesheets. The parameters themselves are set in the Java
code. Seems to work ok.

Regards,


A better solution is to make your own xml document containing all
translations, like this:

i18n_en_GB.xml:

<i18n lang="en_GB">
<lang id="help_msg"> Click here if you want help</lang>
<lang id="error_msg"> An error occured</lang>
</i18n>


You can create different translation documents for each language,
now in the xsl you do this

<xsl:variable name="lang" value="'en_GB'"/>
<xsl:param name="i81n" value="document(./i18n_{$lang}.xml)"/>

And now if you want to put a help_msg somewhere you do:

<xsl:value-of select="$i18n//lang[@id='help_msg']"/>

Understand?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top