Internationalization in Hibernate validators

后端 未结 1 966
南方客
南方客 2021-01-05 16:28

Does Hibernate validators supports internationalization. I saw the jar and I could see the various ValidationMessages.properties file.

Can we create our own custom e

相关标签:
1条回答
  • 2021-01-05 16:55

    I18N is integral part of the Bean Validation specification.

    By default messages are retrieved from a resource bundle named "ValidationMessages". So just provide this bundle (e.g. ValidationMessages.properties) for the language(s) you need to override the default messages from Hibernate Validator (which are retrieved from the bundle "org.hibernate.validator.ValidationMessages").

    Besides the languages you mentioned Hibernate Validator 4.2 will provide Chinese (HV-359) and Spanish (HV-483) messages.

    If you don't want to work with file based resource bundles at all you also can provide your own MessageInterpolator or ResourceBundleLocator implementations.

    Using Hibernate Validator's PlatformResourceBundleLocator it's also possible to use bundles with other names than "ValidationMessages" like this:

    Validation
        .byProvider(HibernateValidator.class)
        .configure()
        .messageInterpolator(
            new ResourceBundleMessageInterpolator(
                new PlatformResourceBundleLocator("com.mycompany.Messages")))
        .buildValidatorFactory()
        .getValidator();`
    
    0 讨论(0)
提交回复
热议问题