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

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.

Author
Juergen Hoeller

Author
Rossen Stoyanchev

Since
27.02.2003

See Also
javax.servlet.http.HttpServletRequest#getLocale()

Constructors

<init>

AcceptHeaderLocaleResolver()

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.

Functions

getDefaultLocale

open fun getDefaultLocale(): Locale

The configured default locale, if any.

getSupportedLocales

open fun getSupportedLocales(): MutableList<Locale>

Return the configured list of supported locales.

resolveLocale

open fun resolveLocale(request: HttpServletRequest): Locale

setDefaultLocale

open fun setDefaultLocale(defaultLocale: Locale): Unit

Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.

By default this is not set in which case when there is "Accept-Language" header, the default locale for the server is used as defined in HttpServletRequest#getLocale().

setLocale

open fun setLocale(request: HttpServletRequest, response: HttpServletResponse, locale: Locale): Unit

setSupportedLocales

open fun setSupportedLocales(locales: MutableList<Locale>): Unit

Configure supported locales to check against the requested locales determined via HttpServletRequest#getLocales(). If this is not configured then HttpServletRequest#getLocale() is used instead.