cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Buckley" <brian.buck...@spectel.com>
Subject problems with i18n transformer in cocoon 2.0.2 - is this a bug?
Date Wed, 29 May 2002 10:20:34 GMT
cocoon version: 2.0.2
servlet engine: tomcat 4.0.3
OS: windows 2000
JDK: 1.4.0

I am trying to add internationalisation to my site by using i18n.  After a day fruitlessly
trying to figure out where I am going wrong I added some debug printlns to the I18nTransformer
source.  My setup is as follows:

******************** sitemap: ***************

<map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer">
        <catalogue-name>messages</catalogue-name>
        <catalogue-location>translations</catalogue-location>
        <cache-at-startup>true</cache-at-startup>       <----- I added this
to make debugging easier as the cache is a simple hash table
</map:transformer>
     .
     .
<map:match pattern="login">
   <map:act type="locale"/>
    <map:aggregate element="page" label="raw-xml">
        <map:part src="cocoon:/login.banner" />
         <map:part src="cocoon:/login.xml" />
    </map:aggregate>
    <map:transform type="i18n" label="trans-xml"/>
    <map:transform src="stylesheets/page2html.xsl" />
    <map:serialize />
</map:match>

******************* dictionary: **************

in $TOMCAT_HOME/webapps/myapp/translations
   /messages.xml
   /messages_en.xml
   /...etc,etc

******************* messages contain: *****
<catalogue xml:lang="en">
	<message key="login.redirect">Go to Secure Login</message>
	<message key="login.welcome">Welcome</message>
             ... etc, etc
</catalogue>

****************** xsp: **********************

<title name="login.welcome" i18n:attr="name"/>
<input type="submit"><i18n:text>login.redirect</i18n:text></input>

Now.  At the browser I am getting the 'login.welcome' and 'login.redirect' keys untranslated.
 My debug statements showed that the string passed into XMLResourceBundle.getString(String
key) was "/catalogue/message[@key='login.welcome']", but the XMLResourceBundle cache contained
the key "/message[@key='login.welcome']".  Clearly a mismatch. So I looked at the code:

I18nTransformer.getString() method prepends the key to be passed to the XMLResourceBundle.getString()
with I18N_CATALOGUE_PREFIX.  I18N_CATALOGUE_PREFIX is the string constant "/catalogue/message".
 XMLResourceBundle.cacheAll(Node parent, String pathToParent) is initially entered with a
pathToParent of "" from init().  The pathToChild StringBuffer takes this as the initial buffer
value in the line:

StringBuffer pathToChild = new StringBuffer(pathToParent).append(child.getNodeName());

If I change the initial call to cacheAll with a pathToParent of "/", and change the above
line to

StringBuffer pathToChild = new StringBuffer(pathToParent).append(parent.getNodeName()).append('/').append(child.getNodeName());

I reproduce the expected key in the cache hashtable, and everything works.

Is this a bug in cocoon 2.0.2 or is there an alternative solution to this without changing
cocoon source code?

Thanks,

Brian Buckley.




Mime
View raw message