Last active
November 13, 2018 07:06
-
-
Save Ikhiloya/8ea8ed6d86e446b8f68d959fa106bf69 to your computer and use it in GitHub Desktop.
Spring Boot Internalization Configuration Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Configuration class for Internationalization | |
| */ | |
| @Configuration | |
| public class LocaleConfiguration implements WebMvcConfigurer { | |
| /** | |
| * * @return default Locale set by the user | |
| */ | |
| @Bean(name = "localeResolver") | |
| public LocaleResolver localeResolver() { | |
| SessionLocaleResolver slr = new SessionLocaleResolver(); | |
| slr.setDefaultLocale(Locale.US); | |
| return slr; | |
| } | |
| /** | |
| * an interceptor bean that will switch to a new locale based on the value of the language parameter appended to a request: | |
| * | |
| * @param registry | |
| * @language should be the name of the request param i.e localhost:8010/api/get-greeting?language=fr | |
| * <p> | |
| * Note: All requests to the backend needing Internationalization should have the "language" request param | |
| */ | |
| @Override | |
| public void addInterceptors(InterceptorRegistry registry) { | |
| LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); | |
| localeChangeInterceptor.setParamName("language"); | |
| registry.addInterceptor(localeChangeInterceptor); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment