JPublish and Localization
"Derick Fernando" <[email protected]>
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <000a01c2757b$0d522670$0501a8c0@xenom> |
Hello,
I was just trying to figure out how to do i18n in JPublish and saw Anthonys Post on the list.
I think the model you propose is too simple. What if we allow variables to be decalred within the page descriptor such as index.xml. I like this approach because its simple and allows everything to be in one place instead of multiple templates:
<?xml version="1.0" encoding="iso-8859-1"?>
<page>
<property name="Title">Address Book</property>
<page-action name="LoadAddresses.py"/>
<!--
If this element is not set. The locale defaults to the one specified in
jpublish.xml. If default is set here it overrides the default set for the
entire app in jpublish.xml
--->
<page-localization default="en">
<!--
Identify a variable in the template that will change with each
locale and enter it here.
--->
<entry name="sorrymsg" />
<en>Sorry, you do not have the permission to add new answers!<en>
<fr>Désolé, vous n'avez pas la permission d'ajouter de nouvelles réponses!</fr>
</entry>
<entry name="welcomeimage" />
<en>images/common/welcome.gif</en>
<fr>images/common/fr/welcome.gif</fr>
</entry>
<entry name="eatsugar" />
<!-- If a country is not specified, use default -->
<en country="us">I want some candy!</en>
<en country="uk">I want some sweets!</en>
</entry>
<page-localization>
</page>
And then in the template index.html:
<img src="${request.ContextPath}/$loc.welcomeimage" alt="Embossed Welcome Text">
<b>$loc.sorrymsg<b>
<br>
<b>$loc.eatsugar<b>
Would display the appropriate version of welcomeimage, sorrymsg.
Thoughts:
This might not be an attractive option because of the way XML handles certain characters. What if we do the same thing in a .properties file? Like so:
In jpublish.xml set the localization folder, perhaps allow it to map paths to locales?:
<localization folder="/locales" />
And in index.xml allow it pick a language? which takes precedence over the value set in
jpublish.xml:
<page-locale>en</page-locale>
Then in /locales map /pages/index.xml to /locales/index.properties, to make that clearer:
map /pages/subsection/mypage.xml to /locales/subsection/mypage.properties etc.
Then in the index.properties file:
en.us.eatsugar = I want candy!
en.uk.eatsugar = I want sweets!
en.sorrymsg = Sorry, you do not have the permission to add new answers!
fr.sorrymsg = Désolé, vous n'avez pas la permission d'ajouter de nouvelles réponses!
And then in the template index.html:
<b>$loc.sorrymsg<b>
<br>
<b>$loc.eatsugar<b>
And it would be nice to have setLang("en"), setLocale("us") methods available?
On a seperate not, I have been sort of working on a DTD for jpublish.xml. Is this useful? Should I spend some more time on it?. I just wanted it to know all the legal options in jpublish.xml, also helps to see when new features like the preevaluation action have been added.
Thanks,
Derick Fernando