When implementing a translation provider following the description here: https://vaadin.com/docs/v14/flow/advanced/tutorial-i18n-localization.html, one has to take care that the translation provider is available in the classpath of the flow server bundle. When running the UI in an OSGi environment, this can e.g. be reached by placing it in a fragment bundle which attaches to com.vaadin.flow.server as host.
In general, translation works. However, when calling getTranslation(“some_key”) from a thread - which e.g. opens a pop-up window with an error message after some timeout - I receive following exception - not knowing whether that is a general issue or related to the specifics of OSGi:
java.lang.NullPointerException
at com.vaadin.flow.component.Component.getI18NProvider(Component.java:600)
at com.vaadin.flow.component.Component.getLocale(Component.java:617)
at com.vaadin.flow.component.Component.getTranslation(Component.java:574)
...
Here the code which leads to this issue (it is called from a class derived from VerticalLayout) :
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
showDialog(getTranslation("timeoutErrorText"));
}
};
final Timer timer = new Timer("TimeoutTimer");
timer.schedule(timerTask, TIMEOUT);
Line 600 of the Component class in the flow-server contains the following:
VaadinService.getCurrent().getInstantiator().getI18NProvider();
Does anybody have an idea how to solve this?
Thanks,
Jochen