What is the recommended approach for Localization in Vaadin (ie. showing people a user interface in their own language)?



You can internationalize a Vaadin application with standard Java ResourceBundles. To make localization easier, you can get them from a property file or XML file.

Here’s a basic example
of working with resource bundles.

Using a more advanced internationalization package can make things easier in real projects. The
, and
Toolkit Productivity Tools
add-ons offer ready tools for internationalization.

One example application built with standard resource bundles that shows how to switch between languages:





- the application class

on-line demo
- click the language buttons to switch the language

[/list]The mentioned I18N4Vaadin tool makes switching easier so that you don’t have to rebuild the UI.

Great! Thank you.

Using resource bundles seems to break the Visual editor… button names are clearly something that should be externalized (did it with eclipse externalize refactor):

I get a pop-up that says:

Could not open design View:
Failed to find or parse visually editable class caused by
Invalid Expression statement in auto-generated layout method buildResultsTitleLayout on line 219

It seems that any use of the editor essentially forbids localization? :frowning:

The current version of the Eclipse code generation and parsing parts of the Visual Editor only support (string etc.) literals as parameters to setter calls, not other method calls.
The visual editor is open source so you could even extend this yourself (patches welcome), although this would probably require extending the type system in a couple of places as well as the UI - a non-trivial task.

Another approach is to iterate over the components at the end of the constructor and reset the String values with calls to a localization helper class.

Yeah, I suppose that one could re-do everything in the constructor, but that still leaves a lot of magic strings in the code and makes it impossible to use checkstyle to flag places where people didn’t do the right thing. I’m aware that all of this stuff is open source, and if I had some time I might see if I could fix it, but at the moment I don’t have that kind of time. Until then, it would be nice if this would be put on the to-do or wish list for the editor since localization is a pretty common thing to do.

(tools like checkstyle, or ide warnings are useless once the generate more than about 5-10 unfixable warnings… nobody pays attention to any of the warnings after that)