Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

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
page.label=hello

MyPage_fr.properties
page.label=salut

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
html
html

  <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
html
html

<input type="submit" value="Search"/>

You can't use the <wicket:message/> component, you should use the following:

Code Block
html
html

<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" );

...