I have a web application that exposes RESTful services with Spring Boot. I added validation on my models with the Hibernate implementation. Example :
public class PersonForm {
@NotNull
@Size(min=2, max=30)
private String name;
@NotNull
@Min(18)
private Integer age;
...
}
The problem is that the messages are rendered in english. Question : how can I force the application to render the messages in french ?
Regards.
You need to add a spring bean in the context to set the default localization
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver slr = new SessionLocaleResolver();
slr.setDefaultLocale(Locale.FRENCH);
return slr;
}
In webflux,there is no SessionLocaleResolver, I simply add this:
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
SpringApplication.run(Application.class);
}
you can also set -Duser.language=en。
both works for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With