Vaadin 7 Portlet I18N Helpers...

Okay, so I’ve been working on V7 portlets in Liferay and needed to support I18N.

Unfortunately the only feedback I got on how to do this was to reaffirm how I had started out, manually resolving resource bundle keys and passing those values to the Vaadin components. And this really didn’t help when it came to changing the locale on the fly (something that Liferay supports).

So I thought there must be a better way to isolate the I18N effort out of my code (I mean, my code shouldn’t have to deal w/ all of the resource bundle keys, etc), and since it didn’t exist I built one…

The attached zip file has my source for an I18N layer over top of the standard Vaadin widgets. Rather than using, say, com.vaadin.ui.Button, instead you use a com.vaadin.i18n.ui.I18NButton (sorry Vaadin for using your package path).

And rather than passing in the button caption, i.e. “Click Me”, instead you pass a resource bundle key, i.e. “”. The I18NButton takes care of the resource bundle lookup and uses the resolved string for you. And I18NButton retains the resource bundle key used for the caption, so when the locale is changed on the fly the caption (etc.) are updated automatically.

For this to work, your portlet class (defined in portlet.xml) must extend com.vaadin.i18n.VaadinI18NPortlet instead of com.vaadin.server.VaadinPortlet.

I’ve implemented most of the UI classes from com.vaadin.ui, but the code has a lot of documentation so it shouldn’t be too much of a problem implementing whatever is missing.

Note that for the most part the code is pretty clean and has been tested against Vaadin 7.0.4 successfully.

The ugly pieces of code are in com.vaadin.i18n.ui.I18NMenuBar, I18NTabSheet, and I18NAccordion. I don’t believe the Vaadin architects believed that a developer would want to extend these classes to allow for creating different MenuItem or Tab implementations, so I had to copy methods verbatim from the super classes and sometimes use reflection to get to the private members/methods of the super classes (yuck). I do have a bug open on the issue,

Anyway, give it a look and let me know what you think. Feel free to swipe, modify, use, or whatever… (45.5 KB)