David Leangen wrote:
Hello,
I did some searching, but could only find info about i18n at the message
level. I am interested in i18n at the page level.
In other words, I have a site that needs to support more than one
locale. The user should be able to switch between them from any point in
the site.
This is how I am thinking of proceeding, but I would really appreciate
comments from anybody who has done extensive i18n before.
Using this approach:
http://www.wicket-wiki.org.uk/wiki/index.php/Multiple_markups_per_page
Each page will (perhaps) have one variant for each locale. I say
"perhaps" because in most cases, there should be a version of the page
for each locale. However, this is not always the case. So, the page
should provide an alternate target for any page that is missing.
Well, no critique intended but I wouldn't (and didn't) choose the 'one
HTML page for each supported language' because it is hard to maintain.
When you introduce/change the content of one page, you'll have to change
it in such many pages as laguages you have. I prefer to keep all the
localization info in the Java code and have one HTML page to maintain
for all supported languages. I don't know why (except for demo) one
would choose another aproach, except the case that the page arrangement
differs so greatly from one language to another that you would need to
have a different HTML page for each language.
So what I did is I used all over the place where I needed localized
content class an I18nLabel (well, missname, but you get the point:-) see
code below) which extends Label and has a 2 args constructor (can be
further evolved for more complex cases, but in my case it was enough)
one is the component id and the second is the locale key for the
localized message:
add(new I18nLabel("helloLabel", "hello.message"));
package components;
import java.io.Serializable;
import wicket.markup.html.basic.Label;
import wicket.model.Model;
import wicket.model.StringResourceModel;
public final class I18nLabel extends Label {
private static final long serialVersionUID = 1L;
/**
* will display the content of a simple message like:
hello.message=Welcome !
*
* @param id
* @param key
*/
public I18nLabel(String id, String key) {
super(id);
setModel(new StringResourceModel(key, this, null));
}
/**
* will display the content of a message like: hello.message=Welcome
* ${displayName} !
* where the passed in modelObject has the corresponding
* getter method: getDisplayName(). See StringResourceModel class for
* variations on this.
*
* @param id
* @param key
* @param modelObject
*/
public I18nLabel(String id, String key, Serializable modelObject) {
super(id);
setModel(new StringResourceModel(key, this, new
Model(modelObject)));
}
}
I won't insult anybody by saying that you can copy/paste the code since
I am positive that 100% of the list can reproduce it w/o reading it :-D.
I could provide more sample code, if needed (but I think the above is
pretty clarifying), also I can provide an url to see it working, but I
don't want to polute the list with URLs that could be interpreted as
advertising so please ask for the link in particular, I will send it to you.
All this should be strictly type-checked (if possible at compile time)
to avoid as many errors as possible.
Pages that use components (such as forms) should be able to pass in the
locale as a parameter and the component should support l10n.
I don't see why you would want to pass a locale as a param since the
locale that is used to display messages from resource bundles is stored
in the session, so you just have to set the locale on the session and
your messages will be picked up automatically from the coresponding
localized file.
Thoughts? Advice?
If somebody from Wicket elders thinks that the approach I've took isn't
allright, or isn't the wicket way, please say so, I will correct my code
also, if needed. I don't want to proliferate bad practices unless it is
really needed :-D.
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
__________ NOD32 1.1100 (20050518) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user