Do you like all ICU4J, Vaadin and Spring?
Here is the Add-on that will allow you to connect these three elements right together!
This Add-on provides you with Spring MessageSource compatible wrapper of ICU4J messages provider that uses current VaadinSession to obtain the Locale.
- Define the Bean in your Application configuration
@Bean(name = "uiMessages")
public VaadinICUMessageSource getUIMessages() {
VaadinICUMessageSource uiMessages = new VaadinICUMessageSource();
uiMessages.setBasename("classpath:uiMessages");
uiMessages.setCacheSeconds(3600);
uiMessages.setFallbackToSystemLocale(false);
return uiMessages;
}
- Use your Bean in your UI code
@SpringUI
public class MainUI extends UI {
@Autowired
private VaadinICUMessageSource uiMessages;
private int counter = 0;
@Override
protected void init(VaadinRequest request) {
setContent(new Button(uiMessages.get("label"), e -> {
Notification.show(uiMessages.get("notification", counter));
counter++;
}));
}
}
- See the
cz.lzaruba.icu4j.spring.vaadin.VaadinICUMessageSource
source or JavaDoc for more details on available methods. - See the project of the original ICU4J + Spring combination
- See the ICU4J syntax options
- Try the Demo Application
This project is based on the code from https://github.com/meticoeus/spring-icu/. Credit to the original code is marked in the header of each file.
This Add-on is licensed under the terms of the Apache License, Version 2.0.