Is it possible to force the language of a Wicket message in HTML?
I have a few wicket pages and generic components that are used both when the user's locale is known and when it is not known. When the locale is not known, I am required to show messages in two official languages (english and german in this example). For now I have made language specific pages for the two languages and a default page for the "unknown" case:
MyComponent.html
MyComponent_en.hmtl
MyComponent_de.html
The "unknown" page (MyComponent.html) contains message-elements for both languages. At the moment, one of the laguages is the default one and for the common components I have had to duplicate the messages in other languages by appending the language code to the message key:
MyComponent.html:
<span lang="en"><wicket:message key="myMessageKey"/></span>
<span lang="de"><wicket:message key="myMessageKey.de"/></span>
wicket_package.properties:
myMessageKey=My hovercraft is full of eels
myMessageKey.de=Mein Luftkissenfahrzeug ist voller Aale
wicket_package_de.properties:
myMessageKey=Mein Luftkissenfahrzeug ist voller Aale
Clearly this duplication of localizations is insanity. Is there a way where I could force the language of the wicket:message in the HTML and save myself from duplicating the localizations? What I am looking for is something like <wicket:message key="myMessageKey" lang="de"/> or anything similar.
One option seems to be making my own WicketMessageResolver
but I'd rather not do that work if I can avoid it.
There is no such functionality in current Wicket (9.8.0).
I'd also be hesitant to implement something like WicketMessageResolver
!
But it would be quite simple to implement with non-auto component (auto-components are all created from markup - <wicket:xyz>
), i.e. with a custom Panel
that has two Label
s which models use Localizer.get()
to get the localized values.