senderj
senderj

Reputation: 410

localizing xsl for different languages

I have some static xsl to translate dynamic xml into html to response to browser. The rest of the web pages use Spring MVC for view. So they can be localized by using Spring's messages.properties file written in my language. But I don't know how to localize the text nodes in the static xsl using the same method. More specific below.

In Spring's web page, I can

<title><spring:message code="title.MyTitle"/></title>

In my static xsl, I have

<xsl:stylesheet ........
<xsl:output method="html"/>
<xsl:template match="/">
.....
    <title>My Title</title>

and I want something like this

<xsl:stylesheet ........
<xsl:output method="html"/>
<xsl:template match="/">
.....
    <title><spring:message code="title.MyTitle"/></title>

Of course the above doesn't work. But I hope I can keep all titles and labels in messages.properties for easy changes between languages. How can I do this? Please help.

Upvotes: 0

Views: 316

Answers (1)

Tony Graham
Tony Graham

Reputation: 8068

Jirka Kosek has a technique for doing l10n lookups at http://www.xml.com/pub/a/2003/11/05/xslt.html. I thought he'd made a whole system for doing l10n with XSLT, but I can't find that now.

Separately, if your properties files are text rather than the XML property file format that Java also understands, the general technique would be:

  1. Use unparsed-text() to get the text of the properties file
  2. Tokenize on line-ends (those not preceded by /, that is)
  3. Make a variable that contains an element for each of those strings, where the key is in an attribute value and the text is the text content of the element

All that's done so far is mimic the XML property file format.

  1. Make a key that matches on the elements and uses the attribute value as the lookup
  2. Make a function that takes the string as a parameter and does a lookup on the key, using the string as the second parameter and the variable as the third

Upvotes: 1

Related Questions