cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Engelhart <mengelh...@earthtrip.com>
Subject Re: Multiple (human) language support
Date Wed, 17 May 2000 20:23:37 GMT
on 5/17/00 3:05 PM, Ross Burton at ross.burton@mail.com wrote:

> This sounds cool - to avoid re-inventing the wheel could you post some code
> snippets?
> 
> Ross Burton
Sure -
First create your properties files in your project.  Read the javadoc's on
ResourceBundle's. There really isn't any code to show you for this.  Just
look at the docs and you'll see what I mean.
Below is a simple XSP page and associated stylesheet that pulls info out of
a resource bundle using Xalan extensions.  This sample assumes you have a
ResourceBundle containing a key/value with the key being 'WORD_TO_LOCALIZE'.
There's more info on extensions at http://xml.apache.org/xalan/

*** xsp ****
<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<document>
<xsp:attribute 
name="lang"><xsp:expr>request.getLocale().getLanguage()</xsp:expr></xsp:attr
ibute>
<xsp:attribute 
name="country"><xsp:expr>request.getLocale().getCountry()</xsp:expr></xsp:at
tribute>
</document>
</xsp:page>

You can pass the "country" and "lang" attributes as elements if you want,
just change your corresponding stylesheet.

**** stylesheet *****
<?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"  
    xmlns:java="http://xml.apache.org/xslt/java"
    exclude-result-prefixes="java">
    
    
    <!-- LOCALIZATION VARIABLES -->
    <xsl:variable name="language" select="string(/document/@lang)"/>
    <xsl:variable name="country" select="string(/document/@country)"/>
    <xsl:variable name="locale" select="java:java.util.Locale.new($language,
$country)"/>
    <xsl:variable name="bundle"
select="java:java.util.ResourceBundle.getBundle('com.earthtrip.resource.Page
s', $locale)"/>

    <xsl:template match="document">
        <html>
        <head>
            <title><xsl:value-of select="java:getString($bundle,
'WORD_TO_LOCALIZE')"/></title>
        </head>
        <body></body>
        </html>
     </xsl:template>
</xsl:stylesheet>



mike


Mime
View raw message