Class I18nConfig
java.lang.Object
springboot.bg.harisauto.common.config.i18n.I18nConfig
- All Implemented Interfaces:
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration
public class I18nConfig
extends Object
implements org.springframework.web.servlet.config.annotation.WebMvcConfigurer
I18nConfig.java - Language selection for the web UI.
The chosen language is kept in a cookie rather than the session, so it survives a logout and a new session - a visitor who picked German should not be shown English again on their next visit.
- Author:
- Kristian Popov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringQuery parameter that switches language, e.g.Languages the UI is translated into. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) org.springframework.web.servlet.i18n.LocaleChangeInterceptorLets any page switch language with alangquery parameter.org.springframework.web.servlet.LocaleResolverResolves the locale from a cookie, defaulting to English.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer
addArgumentResolvers, addCorsMappings, addErrorResponseInterceptors, addFormatters, addResourceHandlers, addReturnValueHandlers, addViewControllers, configureAsyncSupport, configureContentNegotiation, configureDefaultServletHandling, configureHandlerExceptionResolvers, configureMessageConverters, configurePathMatch, configureViewResolvers, extendHandlerExceptionResolvers, extendMessageConverters, getMessageCodesResolver, getValidator
-
Field Details
-
SUPPORTED_LOCALES
Languages the UI is translated into. -
LANGUAGE_PARAMETER
Query parameter that switches language, e.g./home?lang=de.- See Also:
-
-
Constructor Details
-
I18nConfig
public I18nConfig()
-
-
Method Details
-
localeResolver
@Bean public org.springframework.web.servlet.LocaleResolver localeResolver()Resolves the locale from a cookie, defaulting to English.- Returns:
- The locale resolver.
-
localeChangeInterceptor
@Bean public org.springframework.web.servlet.i18n.LocaleChangeInterceptor localeChangeInterceptor()Lets any page switch language with alangquery parameter.- Returns:
- The interceptor.
-
addInterceptors
public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) - Specified by:
addInterceptorsin interfaceorg.springframework.web.servlet.config.annotation.WebMvcConfigurer
-