[Vaadin 7] I18N with Spring and Strings in *.properties

Hi,
I’m trying to set up internationalization for my Vaadin 7 webapp on Spring (
SpringVaadinIntegration
add-on).

Currently what I got is:

In spring context:

<bean id="messageSource" class="org.springframework.context.support.
          ReloadableResourceBundleMessageSource" autowire="byName">
  <property name="defaultEncoding" value="UTF-8" />
  <property name="basenames">
    <list>
      <value>classpath:translations/messages</value>
    </list>
  </property>
</bean>

And in my UI:

Button flagENbutton = new Button("English", new ClickListener() { @Override public void buttonClick(ClickEvent event) { VaadinSession.getCurrent().setLocale(new Locale("en")); }}; And of course some .properties files in resources/translations dir. I would really like to keep them that way (prefer it over XML etc)

It works almost like I want - setting the Locale for VaadinSession actually is working by changing the properties file from which the strings are taken, but it works only when I reload (refresh) manually the page.

As I did my research over this forum and whole Interwebs, I got some possible solutions, but I’m having problem in realization:

  1. I found similar topic, but old and referencing to Vaadin6 (
    https://vaadin.com/forum#!/thread/178978
    ), where there is posted GasDiary example of what I want to achieve - its changing Locale and refreshing the V6 “screen”. Is there a simple way to do the same in Vaadin 7? Or how to easy reload all components of the UI, on clicking on language selection button in UI?
  2. I looked at the
    I18N4Vaadin
    addon, but as I found, there is also need of manual reload of components, so the problem is the same as in no.1.
  3. I looked also on the
    AppFoundation i18n module
    which looks nice but: it uses XML (I prefer .properties) and I don’t know how about reloading the page to change the strings on currently loaded components.

I would really appreciate any suggestions about my concerns. How this should be done in Vaadin7? Is there a better way than reloading whole page? If so, how? If not, how to properly reload all the components in one method, without going manually through all of the components?

Hi,
I’m still waiting for some help.

To be honest, I don’t need very fancy solution - for example programatically way of rebuilding the whole UI in Spring-based Vaadin 7 app would be sufficient for me, but unfortunately, all the methods I found online are for Vaadin 6.

I would be grateful for any help from outstanding Vaadin community :slight_smile:

Hi. You can use this bean from Spring

@Bean public MessageSource messageSource(){ final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("i18n/messages"); return messageSource; } And call it everywhere

@Autowired MessageSource messageSource See the attached picture for the file organisation(IntelliJ). There are many tutorials about how to use messageSource. So, I will just explain how to link spring with vaadin
in Vaadin code:

messageSource.getMessage("message.from.file",null, VaadinSession.getCurrent().getLocale())); Hope it helps, at least to figure out how to do it

27118.jpg