Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wicket Internationalization : Multiple Properties file for Multiple Pages?

the wicket internationalization example available has the following file structure

HomePage.java
HomePage.html
HomePage.properties
WicketApplication.java
HomePage_nl.properties

Now when creating a project with multiple HTML pages, for example i have HomePage.html and Login.html, is there a way that i can save all key-value pair in single property for a particular language or i will have to have to create all these files

HomePage.properties
HomePage_nl.properties
Login.properties
Login_nl.properties
like image 943
anand mahuli Avatar asked Sep 21 '12 06:09

anand mahuli


1 Answers

Wicket will try to find message resources using the following rules:

  1. Wicket will try to find the message starting from the Page and drilling down to the specific Component through the component hierarchy of the Page. Notice this is a top-down search.

  2. When a message is not found in the component hierarchy, it will be looked for in the Application class.

The lookup for a resource in every class works in the following way :

  1. Localised searches appending the locale to the file name (Login_nl.properties, then Login.properties), just like Java's ResourceBundles do.

  2. Down-top through the class hierarchy. That means that if a resource is not found in a class, it will be searched in its superclasses all the way until it hits java.lang.Object.

So, in your specific case, if Login is a Panel inside HomePage, you can just define the resources in HomePage(_nl).properties. Also, if there are specific application-wide messages, remember that you can define them in WicketApplication(_nl).properties.

You might find the following Wicket wiki page : Everything about Wicket internationalization useful, it elaborates on this matter.

(...). This is facilitated by first looking up the message (following the algorithm above) for every parent in the component hierarchy (aka page hierarchy). Every component can override the messages of its child components, so the search starts at the page's properties and then trickles down to the component that uses it (yes, its top-down). In order to make overrides specific to a certain child component, you can prefix the message key with the component id of the child. See ComponentStringResourceLoader for more details.

If no message was found in the page hierarchy, another search starts which will look at your application class and its super classes. So Wicket first looks at MyApplication.properties (provided MyApplication is the name of your application) and then up the class hierarchy, passing org.apache.wicket.Application, up to java.lang.Object. This is how Wicket provides its many default i18n texts.

like image 90
Xavi López Avatar answered Nov 07 '22 11:11

Xavi López