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
Wicket will try to find message resources using the following rules:
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.
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 :
Localised searches appending the locale to the file name (Login_nl.properties
, then Login.properties
), just like Java's ResourceBundle
s do.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With