Refresh Components for Multi-language

Hey

I’m developping a java web tool using Vaadin. This tool shoud support two languages, english and german.
i created a customcomponent in a own class called “LanguageSelection”. in this component i have two buttons, one for german and one for english. this customcomponent i add to all windows in my application. After clicking a button i set the Lang of the application to the locale ENGLISH or GERMAN.
All the translations i make with the i18n addon from app-foundation.

now, for example, i have a label in a window. This Label takes caption from the translation.xml file.
Label(Lang.getMessage(“LABEL_MESSAGE”).

how is it possible to refresh the caption in this label by clicking on a language button in the customcomponent?

sorry about my bad english :wink:

regards

andreas

Hi,

With some pain. As it is not possible to bind component captions to a data source, there is no ideal solution for that. (You can bind Label values.)

  1. You could
    traverse
    the component tree to change language in the captions and labels, but that could be a bit complicated. You have to associate a resource identifier with every component so that you can load the same resource with the new locale; you could use a HashMap to do that or store the identifier in the data property of the component with [tt]
    setData()
    [/tt] (but then you can’t use it for anything else).
  2. It may be easier to simply rebuild the view, especially if you have the language selection right in the login screen.
    [list]

  3. LoginScreen.java

  4. GasDiaryApplication.java
    - the application class

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

    [/list]

Dear Marko!

It’s a very good example, I could create my application multilingual about this, but how can I change the system messages too? Can you give me other sample or idea?

Tnaks!
Tamás

Its a bit old already, but you change your system messages like this:

VaadinServletService.getCurrent().setSystemMessagesProvider(new SystemMessagesProvider() {

@Override
public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
CustomizedSystemMessages messages = new CustomizedSystemMessages();
messages.setCommunicationErrorCaption(“caption”);
messages.setCommunicationErrorMessage(“message”);
return messages;
}
});

Hi,
Sorry to revice this old thread. The example (GasDiary) looks promising, but is not using Vaadin 7.x.x as it seems.

How would be the way of refreshing components after a language switch in Vaadin 7?

Thanks,
Sven