You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Hans Ulrich Niedermann <ni...@isd.uni-stuttgart.de> on 2000/05/16 23:32:15 UTC
Multiple (human) language support
Hi all,
does anybody incidentally have some Cocoon-based site that delivers
pages in the language determined by HTTP content negotiation and can
publish some source code for that?
If yes, please tell us how. :-) I'd volunteer for writing docs for
inclusion into the Cocoon package.
If not, I'll have to develop something myself.
I've been thinking about somehow using XML source data with <para
lang="fr"> and <para lang="en"> (or "xml:lang" instead of "lang")
Cheers,
Uli
P.S.: BTW, I'm already writing some docs about how to use HTTP request
params within XSL stylesheets.
Re: Multiple (human) language support
Posted by Mike Engelhart <me...@earthtrip.com>.
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
Re: Multiple (human) language support
Posted by Ross Burton <ro...@mail.com>.
> I do this for my whole site but my site doesn't have huge chunks of text
> content so I don't need to put stuff into a database which would be slow
to
> access. Anyway, I use java.util.ResourceBundle objects to store all my
> localized information and then use the simple Xalan extensions to handle
the
> on-the-fly translation into whatever language the browser is set to and I
> have supported (default is English).
This sounds cool - to avoid re-inventing the wheel could you post some code
snippets?
Ross Burton
Re: Multiple (human) language support
Posted by Mike Engelhart <me...@earthtrip.com>.
on 5/17/00 6:35 AM, Michele Bianchi at mic@exsense.com wrote:
> On 16 May 2000, Hans Ulrich Niedermann wrote:
>
>> does anybody incidentally have some Cocoon-based site that delivers
>> pages in the language determined by HTTP content negotiation and can
>> publish some source code for that?
>
> i haven't, but i'm interested about that. i'm plannig smth and i have no
> probs
> to leave it open.
I do this for my whole site but my site doesn't have huge chunks of text
content so I don't need to put stuff into a database which would be slow to
access. Anyway, I use java.util.ResourceBundle objects to store all my
localized information and then use the simple Xalan extensions to handle the
on-the-fly translation into whatever language the browser is set to and I
have supported (default is English).
I attempted an all XML version using key/map in XSL but it's not even close
to being ready for prime time. The current XSL (or maybe it's just xalan)
spec doesn't support i18n well at all. If you're only switching between say
2 languages it may work but if you want to support 10 or 20 languages,
you'll have to wait until another version which supports it better is
available.
Mike
Re: Multiple (human) language support
Posted by Michele Bianchi <mi...@exsense.com>.
On 16 May 2000, Hans Ulrich Niedermann wrote:
> does anybody incidentally have some Cocoon-based site that delivers
> pages in the language determined by HTTP content negotiation and can
> publish some source code for that?
i haven't, but i'm interested about that. i'm plannig smth and i have no probs
to leave it open.
-------------------------------------------------------------------------------
michele_bianchi exsense | integrated_solutions
phone://+39_348_7651874 via_scrimiari_45b
http://mic.aesthetica.it 37132_verona_italy