FlowingCode / ErrorWindowAddon

Error Window Vaadin Add-on
Apache License 2.0
9 stars 2 forks source link

Adding Custom I18n setting #43

Closed mcentrih closed 1 year ago

mcentrih commented 1 year ago

It would be very good if you would allow to set custom I18n text for whole dialog globaly. So that we would not need to set text in every error case each.

image

javier-godoy commented 1 year ago

Hello. If you don't need to support multiple languages, you can set up a custom i18n instance globally by replacing the default ErrorWindowFactory. In order to do so, set up a VaadinServiceInitListener as follows:

@Component
public class ErrorWindowServiceInitListener
        implements VaadinServiceInitListener {

  @Override
  public void serviceInit(ServiceInitEvent event) {
    ErrorWindowI18n i18n = new ErrorWindowI18n();
    i18n.setCaption(...);
    i18n.setCaption(...);

    ErrorManager.setErrorWindowFactory(Throwable.class, details -> new ErrorWindow(details, i18n).open());        
  }
}

Please let us know if that helped.

javier-godoy commented 1 year ago

While my comment above allows customizing the texts globally, it does not allow to resolve them based on the locale of the current UI, which is a desirable feature.