spring-framework / org.springframework.web.servlet.i18n

Package org.springframework.web.servlet.i18n

Types

AbstractLocaleContextResolver

abstract class AbstractLocaleContextResolver : AbstractLocaleResolver, LocaleContextResolver

Abstract base class for LocaleContextResolver implementations. Provides support for a default locale and a default time zone.

Also provides pre-implemented versions of #resolveLocale and #setLocale, delegating to #resolveLocaleContext and #setLocaleContext.

AbstractLocaleResolver

abstract class AbstractLocaleResolver : LocaleResolver

Abstract base class for LocaleResolver implementations. Provides support for a default locale.

AcceptHeaderLocaleResolver

open class AcceptHeaderLocaleResolver : LocaleResolver

LocaleResolver implementation that simply uses the primary locale specified in the "accept-language" header of the HTTP request (that is, the locale sent by the client browser, normally that of the client's OS).

Note: Does not support setLocale, since the accept header can only be changed through changing the client's locale settings.

CookieLocaleResolver

open class CookieLocaleResolver : CookieGenerator, LocaleContextResolver

LocaleResolver implementation that uses a cookie sent back to the user in case of a custom setting, with a fallback to the specified default locale or the request's accept-header locale.

This is particularly useful for stateless applications without user sessions. The cookie may optionally contain an associated time zone value as well; alternatively, you may specify a default time zone.

Custom controllers can override the user's locale and time zone by calling #setLocale(Context) on the resolver, e.g. responding to a locale change request. As a more convenient alternative, consider using org.springframework.web.servlet.support.RequestContext#changeLocale.

FixedLocaleResolver

open class FixedLocaleResolver : AbstractLocaleContextResolver

org.springframework.web.servlet.LocaleResolver implementation that always returns a fixed default locale and optionally time zone. Default is the current JVM's default locale.

Note: Does not support setLocale(Context), as the fixed locale and time zone cannot be changed.

LocaleChangeInterceptor

open class LocaleChangeInterceptor : HandlerInterceptorAdapter

Interceptor that allows for changing the current locale on every request, via a configurable request parameter (default parameter name: "locale").

SessionLocaleResolver

open class SessionLocaleResolver : AbstractLocaleContextResolver

org.springframework.web.servlet.LocaleResolver implementation that uses a locale attribute in the user's session in case of a custom setting, with a fallback to the specified default locale or the request's accept-header locale.

This is most appropriate if the application needs user sessions anyway, i.e. when the HttpSession does not have to be created just for storing the user's locale. The session may optionally contain an associated time zone attribute as well; alternatively, you may specify a default time zone.

Custom controllers can override the user's locale and time zone by calling #setLocale(Context) on the resolver, e.g. responding to a locale change request. As a more convenient alternative, consider using org.springframework.web.servlet.support.RequestContext#changeLocale.

In contrast to CookieLocaleResolver, this strategy stores locally chosen locale settings in the Servlet container's HttpSession. As a consequence, those settings are just temporary for each session and therefore lost when each session terminates.

Note that there is no direct relationship with external session management mechanisms such as the "Spring Session" project. This LocaleResolver will simply evaluate and modify corresponding HttpSession attributes against the current HttpServletRequest.