How to integrate hibernate's internationalization with Vaadin binder?

How to translate hibernate’s validation messages which are on dto’s or entities fields in binder’s validation ? For example @NotNull(message="This field cannot be null)

How to integrate hibernate’s internationalization with Vaadin binder?

https://jakarta.ee/specifications/bean-validation/3.0/jakarta-bean-validation-spec-3.0.html#validationapi-message-defaultmessageinterpolation-resolutionalgorithm

You can use keys and the messages go to ValidationMessages.properties resp. according to the language like ValidationMessage_de.properties

But if I have to use custom resource bundle? From paths: resources/i18n/messages.properities
resources/i18n/messages_pl.properties
I have implemented I18NProvider like it is in the official Vaadin documentation.
https://vaadin.com/docs/latest/advanced/i18n-localization
I would like to use the same implementation which uses resource bundle. Can you help with that @adaptable-uakari ?

then you have to write your own MessageInterpolator

I was also trying like this

    @Primary
    public static LocalValidatorFactoryBean defaultValidator() {

        var bean = new LocalValidatorFactoryBean();
        bean.setMessageInterpolator(new ResourceBundleMessageInterpolator(new PlatformResourceBundleLocator(I18nResolver.getBundleBasename())));
        return bean;
    }

Remove static!

Then this should work

Still does not work

unknown.png

bundle name is still ValidationMessages

With using custom MessageSoruce it also not working. Methods getMessage() also are not invoked.

    @Primary
    public LocalValidatorFactoryBean defaultValidator() {

        var bean = new LocalValidatorFactoryBean();
        bean.setValidationMessageSource(new CustomMessageSource());

        return bean;
    }

    private static class CustomMessageSource implements MessageSource {

        @Override
        public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {

            return I18nResolver.getTranslation(code, locale, args);
        }

        @Override
        public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {

            return I18nResolver.getTranslation(code, locale, args);
        }

        @Override
        public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {

            return null;
        }
    }

Does the class with this code have the annotation @Configuration?

of course

and defaultValidator ist called?

yes
unknown.png
unknown.png

No I mean the method defaultValidator where you set the CustomMessageSource

yes

Maybe it is something with Vaadin binder?
Which validator is used by binder?
javax.validation.Validator or org.springframework.validation.Validator ?