Class AcceptHeaderLocaleResolver
java.lang.Object
org.springframework.web.servlet.i18n.AbstractLocaleResolver
org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
- All Implemented Interfaces:
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(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse, java.util.Locale)
since the Accept-Language
header can only be changed by changing the client's locale settings.
- Since:
- 27.02.2003
- Author:
- Juergen Hoeller, Rossen Stoyanchev
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet the configured list of supported locales.resolveLocale
(HttpServletRequest request) Resolve the current locale via the given request.void
setLocale
(HttpServletRequest request, HttpServletResponse response, Locale locale) Set the current locale to the given one.void
setSupportedLocales
(List<Locale> locales) Configure supported locales to check against the requested locales determined viaServletRequest.getLocales()
.Methods inherited from class org.springframework.web.servlet.i18n.AbstractLocaleResolver
getDefaultLocale, setDefaultLocale
-
Constructor Details
-
AcceptHeaderLocaleResolver
public AcceptHeaderLocaleResolver()
-
-
Method Details
-
setSupportedLocales
Configure supported locales to check against the requested locales determined viaServletRequest.getLocales()
. If this is not configured thenServletRequest.getLocale()
is used instead.- Parameters:
locales
- the supported locales- Since:
- 4.3
-
getSupportedLocales
Get the configured list of supported locales.- Since:
- 4.3
-
resolveLocale
Description copied from interface:LocaleResolver
Resolve the current locale via the given request.Can return a default locale as fallback in any case.
- Parameters:
request
- the request to resolve the locale for- Returns:
- the current locale (never
null
)
-
setLocale
public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) Description copied from interface:LocaleResolver
Set the current locale to the given one.- Parameters:
request
- the request to be used for locale modificationresponse
- the response to be used for locale modificationlocale
- the new locale, ornull
to clear the locale
-