LocaleContextResolver 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
Does not support setLocaleContext, since the accept header
can only be changed through changing the client's locale settings.
HttpHeaders#getAcceptLanguageAsLocales()
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Locale | |
| public List | |
| public LocaleContext | resolveLocaleContext(ServerWebExchange
current server exchange exchange)Implements org. |
| private Locale | |
| public void | setDefaultLocale(Locale
the default locale to use defaultLocale)Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header (not set by default). |
| public void | setLocaleContext(ServerWebExchange
current server exchange exchange, LocaleContext the new locale context, or locale)null to clear the localeImplements org. |
| public void | setSupportedLocales(List<Locale>
the supported locales locales)Configure the list of supported locales to compare and match against
|
| defaultLocale | back to summary |
|---|---|
| private Locale defaultLocale
| |
| supportedLocales | back to summary |
|---|---|
| private final List<Locale> supportedLocales | |
| AcceptHeaderLocaleContextResolver | back to summary |
|---|---|
| public AcceptHeaderLocaleContextResolver() | |
| getDefaultLocale | back to summary |
|---|---|
| public Locale getDefaultLocale() The configured default locale, if any. This method may be overridden in subclasses.
| |
| getSupportedLocales | back to summary |
|---|---|
| public List Return the configured list of supported locales. | |
| resolveLocaleContext | back to summary |
|---|---|
| public LocaleContext resolveLocaleContext(ServerWebExchange exchange) Implements org. Doc from org. Resolve the current locale context via the given exchange. The returned context may be a
Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.
| |
| resolveSupportedLocale | back to summary |
|---|---|
private Locale resolveSupportedLocale(List<Locale> requestLocales)
| |
| setDefaultLocale | back to summary |
|---|---|
| public void setDefaultLocale(Locale defaultLocale) Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header (not set by default).
| |
| setLocaleContext | back to summary |
|---|---|
| public void setLocaleContext(ServerWebExchange exchange, LocaleContext locale) Implements org. Doc from org. Set the current locale context to the given one, potentially including a locale with associated time zone information.
| |
| setSupportedLocales | back to summary |
|---|---|
| public void setSupportedLocales(List<Locale> locales) Configure the list of supported locales to compare and match against
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 If there is no match, then the | |