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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Query parameter that switches language, e.g.
    static final List<Locale>
    Languages the UI is translated into.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
     
    org.springframework.web.servlet.i18n.LocaleChangeInterceptor
    Lets any page switch language with a lang query parameter.
    org.springframework.web.servlet.LocaleResolver
    Resolves 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, wait

    Methods 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

      public static final List<Locale> SUPPORTED_LOCALES
      Languages the UI is translated into.
    • LANGUAGE_PARAMETER

      public static final String 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 a lang query parameter.
      Returns:
      The interceptor.
    • addInterceptors

      public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry)
      Specified by:
      addInterceptors in interface org.springframework.web.servlet.config.annotation.WebMvcConfigurer