Class AcceptHeaderLocaleResolver
- All Implemented Interfaces:
- LocaleResolver
LocaleResolver implementation that looks for a match between locales
 in the Accept-Language header and a list of configured supported
 locales.
 See setSupportedLocales(List) for further details on how
 supported and requested locales are matched.
 
Note: This implementation 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionGet the configured list of supported locales.resolveLocale(HttpServletRequest request) Resolve the current locale via the given request.voidsetLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) Set the current locale to the given one.voidsetSupportedLocales(List<Locale> locales) Configure the list of supported locales to compare and match againstrequested locales.Methods inherited from class org.springframework.web.servlet.i18n.AbstractLocaleResolvergetDefaultLocale, setDefaultLocale
- 
Constructor Details- 
AcceptHeaderLocaleResolverpublic AcceptHeaderLocaleResolver()
 
- 
- 
Method Details- 
setSupportedLocalesConfigure the list of supported locales to compare and match againstrequested locales.In order for a supported locale to be considered a match, it must match on both country and language. If you want to support a language-only match as a fallback, you must configure the language explicitly as a supported locale. For example, if the supported locales are ["de-DE","en-US"], then a request for"en-GB"will not match, and neither will a request for"en". If you want to support additional locales for a given language such as"en", then you must add it to the list of supported locales.If there is no match, then the defaultLocaleis used, if configured, or otherwise falling back onServletRequest.getLocale().- Parameters:
- locales- the supported locales
- Since:
- 4.3
 
- 
getSupportedLocalesGet the configured list of supported locales.- Since:
- 4.3
 
- 
resolveLocaleDescription copied from interface:LocaleResolverResolve 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)
 
- 
setLocalepublic void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale) Description copied from interface:LocaleResolverSet the current locale to the given one.- Parameters:
- request- the request to be used for locale modification
- response- the response to be used for locale modification
- locale- the new locale, or- nullto clear the locale
 
 
-