Skip to content

Commit

Permalink
perf($Starter): simplify internationalization (i18n)
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
johnnymillergh committed Feb 19, 2021
1 parent 1c8b38b commit b42bc7b
Showing 1 changed file with 2 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.jmsoftware.maf.springcloudstarter.configuration;

import org.springframework.context.annotation.Bean;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

/**
* <h1>WebMvcConfiguration</h1>
Expand All @@ -16,15 +14,12 @@
* @date 1/23/20 9:02 AM
**/
@Configuration
@RequiredArgsConstructor
public class WebMvcConfiguration implements WebMvcConfigurer {
/**
* Max age: 3600 seconds (1 hour)
*/
private static final long MAX_AGE_SECS = 3600;
/**
* Default name of the locale specification parameter: "lang".
*/
private static final String DEFAULT_PARAM_NAME = "lang";

/**
* Configure cross origin requests processing.
Expand All @@ -38,25 +33,4 @@ public void addCorsMappings(CorsRegistry registry) {
.allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
.maxAge(MAX_AGE_SECS);
}

/**
* An interceptor bean that will switch to a new locale based on the value of the lang parameter appended to a
* request.
*
* @return the locale change interceptor
* @see
* <a href='https://www.baeldung.com/spring-boot-internationalization#localechangeinterceptor'>LocaleChangeInterceptor</a>
*/
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName(DEFAULT_PARAM_NAME);
return localeChangeInterceptor;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
// In order to take effect, this bean needs to be added to the application's interceptor registry.
registry.addInterceptor(localeChangeInterceptor());
}
}

0 comments on commit b42bc7b

Please sign in to comment.