I am working on a server application without a user frontend. To ensure that all parts of the application will generate only English message I would like to ensure that the application will use only a specific locale.
After reading the docs and some googling I came to the conclusion that I have to do the following:
Setting the locale programmatically in the main
method via Locale.setDefault(Locale.ENGLISH)
;
Provide a bean instance of FixedLocaleResolver
as locale resolver for the application.
Is this correct or this there a better way to achive my goal?
Internationalization or I18N is a process that makes your application adaptable to different languages and regions without engineering changes on the source code. You can display messages, currencies, date, time etc.
Interface LocaleResolver The default implementation is AcceptHeaderLocaleResolver , simply using the request's locale provided by the respective HTTP header.
you can put
spring.mvc.locale=en_EN
spring.mvc.localeResolver=fixed
in your application.properties or application.yml(of course in yaml format).
Spring will automatically read those properties.
I am not aware of any other better way.
Since SpringBoot 2.4.0 use:
spring.web.locale=en_EN
spring.mvc.localeResolver=fixed
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