RE: JPublish and Localization
"Anthony Eden" <[email protected]>
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <000f01c27590$ade82d90$01000001@mobile1> |
Derick,
Thanks for your thoughts and feedback. i18n will be an ongoing
development task I am sure, because there will always be ways to make it
easier.
You mentioned a previous post of mine regarding i18n - could you please
specify which message that is? I just want to make sure that we are on
the same channel.
With respect to the current localization features, how does your version
below differ significantly from the current system? The current system
is as follows:
<property name="title">Title</property>
<property name="title" locale="fr">Titre</property>
Would it be sufficient to add support for the following alternate
syntax?
<property name="title">
<value>Title</value>
<value locale="fr">Titre</value>
</property>
That would solve the XML syntax issue, I think. As for having the
localized version automatically returned I imagine wrapping the existing
Page object in a wrapper which knows the current Locale and then would
return a request to the get() method with an appropriate localized
version:
public class PageWrapper{
public PageWrapper(Page page){
this.page = page;
}
// all of the Page methods which are not localizable would just call
the correct Page method
public String get(String name){
page.get(name, locale);
}
public void setLocale(Locale locale){
this.locale = locale;
}
// add additional shortcut methods for setLanguage() and
setCountry()
private Page page;
private Locale locale;
}
What exactly do you mean by this: This might not be an attractive option
because of the way XML handles certain characters. If you use UTF-16
encoding shouldn't you be able to use any character? I honestly don't
know so please tell me what kind of problems you have encountered.
Finally, there is already a DTD for the jpublish.xml, page.xml and
pages.xml configuration files. They are in the
jpublish-docs/content/xml directory. I try to keep them up to date, but
I will admit that I occasionally forget to update them (for example, I
just added the property locale attribute in the page.dtd).
-Anthony
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
Derick Fernando
Sent: Wednesday, October 16, 2002 9:18 PM
To: [email protected]
Subject: [JPublish-developer] JPublish and Localization
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