...
Code Block |
---|
add( new Label( "page.label", new PropertyModel( this, "propertyName" ) ); |
which accesses a property from the page class. No problem.
So, what do we do if we want to i18nise this label?
...
Code Block |
---|
if( getSession().getLocale h1. Locale.ENGLISH ) add( new Label( "page.label", new PropertyModel( this, "enPropertyName" ) ); else if( getSession().getLocale Locale.FRENCH ) add( new Label( "page.label", new PropertyModel( this, "frPropertyName" ) ); ... |
which is a very bad idea!
Rather, use the support provided by Wicket. By setting up properties files for your pages, wicket will take care of the details for you. So, you would set up files like so:
Panel |
---|
MyPage_en.properties MyPage_fr.properties etc. |
i18n of Entire Pages
MyPage.properties is used for the default language for the website, MyPage_xx.properties is used for other languages, replacing xx by the language code.
You can then activate the properties files by Java code such as this:
Code Block |
---|
add( new Label( "page.label", new ResourceModel( "page.label" ) );
|
However, Wicket provides a much quicker and simpler solution with a dedicated tag for the html, that means there is no Java code to write at all:
Code Block | ||||
---|---|---|---|---|
| ||||
<wicket:message key="page.label">Default label</wicket:message>
|
If you want to use Wicket's i18n in other HTML elements, for example:
Code Block | ||||
---|---|---|---|---|
| ||||
<input type="submit" value="Search"/>
|
You can't use the <wicket:message/> component, you should use the following:
Code Block | ||||
---|---|---|---|---|
| ||||
<input type="submit" wicket:message="value:page.search"/>
|
i18n of Entire Pages
To i18nise an entire page, it's the same simple approach as for a label. We simply write entire pages with the To i18nise an entire page, it's the same simple approach as for a label. We simply write entire pages with the locale name appended to the page name:
...
And perhaps something like Page_ja.html:
Panel |
---|
<a wicket:id="links.acme">Ã?£?ââ?¬Å?Ã?£?Ã?¡Ã?£ââ?¬Å¡Ã¢â?¬Â°</a>Ã?£?Ã?«Ã?£?ââ?¬?Ã?¨Ã?¦Ã?§Ã?£??Ã?£?Ã? Ã?£?ââ?¬Â¢Ã?£?ââ?¬Å¾.acme">ã?â€Å"ã?¡ã‚‰</a>ã?«ã?â€?覧ã??ã? ã?•ã?„. |
and in our Page.java:
Code Block |
---|
add( new i18nLink( "links.acme" ); |
...