public class AcceptHeaderLocaleResolver extends Object implements 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(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.util.Locale)
since the Accept-Language
header can only be changed by changing the client's locale settings.
ServletRequest.getLocale()
Constructor and Description |
---|
AcceptHeaderLocaleResolver() |
Modifier and Type | Method and Description |
---|---|
Locale |
getDefaultLocale()
The configured default locale, if any.
|
List<Locale> |
getSupportedLocales()
Get the configured list of supported locales.
|
Locale |
resolveLocale(HttpServletRequest request)
Resolve the current locale via the given request.
|
void |
setDefaultLocale(Locale defaultLocale)
Configure a fixed default locale to fall back on if the request does not
have an "Accept-Language" header.
|
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 via
ServletRequest.getLocales() . |
public void setSupportedLocales(List<Locale> locales)
ServletRequest.getLocales()
. If this is not
configured then ServletRequest.getLocale()
is used instead.locales
- the supported localespublic List<Locale> getSupportedLocales()
public void setDefaultLocale(@Nullable Locale defaultLocale)
By default this is not set in which case when there is no "Accept-Language"
header, the default locale for the server is used as defined in
ServletRequest.getLocale()
.
defaultLocale
- the default locale to use@Nullable public Locale getDefaultLocale()
This method may be overridden in subclasses.
public Locale resolveLocale(HttpServletRequest request)
LocaleResolver
Can return a default locale as fallback in any case.
resolveLocale
in interface LocaleResolver
request
- the request to resolve the locale fornull
)public void setLocale(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable Locale locale)
LocaleResolver
setLocale
in interface LocaleResolver
request
- the request to be used for locale modificationresponse
- the response to be used for locale modificationlocale
- the new locale, or null
to clear the locale