类 AcceptHeaderLocaleContextResolver
- java.lang.Object
- org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver
- 所有已实现的接口:
LocaleContextResolver
public class AcceptHeaderLocaleContextResolver extends Object implements LocaleContextResolver
LocaleContextResolver
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
setLocaleContext(org.springframework.web.server.ServerWebExchange, org.springframework.context.i18n.LocaleContext)
, since the accept header can only be changed through changing the client's locale settings.- 从以下版本开始:
- 5.0
- 作者:
- Sebastien Deleuze, Juergen Hoeller
- 另请参阅:
HttpHeaders.getAcceptLanguageAsLocales()
构造器概要
构造器 构造器 说明 AcceptHeaderLocaleContextResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 Locale
getDefaultLocale()
The configured default locale, if any.List<Locale>
getSupportedLocales()
Return the configured list of supported locales.LocaleContext
resolveLocaleContext(ServerWebExchange exchange)
Resolve the current locale context via the given exchange.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).void
setLocaleContext(ServerWebExchange exchange, LocaleContext locale)
Set the current locale context to the given one, potentially including a locale with associated time zone information.void
setSupportedLocales(List<Locale> locales)
Configure supported locales to check against the requested locales determined viaHttpHeaders.getAcceptLanguageAsLocales()
.
构造器详细资料
AcceptHeaderLocaleContextResolver
public AcceptHeaderLocaleContextResolver()
方法详细资料
setSupportedLocales
public void setSupportedLocales(List<Locale> locales)
Configure supported locales to check against the requested locales determined viaHttpHeaders.getAcceptLanguageAsLocales()
.- 参数:
locales
- the supported locales
getSupportedLocales
public List<Locale> getSupportedLocales()
Return the configured list of supported locales.
setDefaultLocale
public void setDefaultLocale(@Nullable 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).- 参数:
defaultLocale
- the default locale to use
getDefaultLocale
@Nullable public Locale getDefaultLocale()
The configured default locale, if any.This method may be overridden in subclasses.
resolveLocaleContext
public LocaleContext resolveLocaleContext(ServerWebExchange exchange)
从接口复制的说明:LocaleContextResolver
Resolve the current locale context via the given exchange.The returned context may be a
TimeZoneAwareLocaleContext
, containing a locale with associated time zone information. Simply apply aninstanceof
check and downcast accordingly.Custom resolver implementations may also return extra settings in the returned context, which again can be accessed through downcasting.
- 指定者:
resolveLocaleContext
在接口中LocaleContextResolver
- 参数:
exchange
- current server exchange- 返回:
- the current locale context (never
null
)
setLocaleContext
public void setLocaleContext(ServerWebExchange exchange, @Nullable LocaleContext locale)
从接口复制的说明:LocaleContextResolver
Set the current locale context to the given one, potentially including a locale with associated time zone information.- 指定者:
setLocaleContext
在接口中LocaleContextResolver
- 参数:
exchange
- current server exchangelocale
- the new locale context, ornull
to clear the locale- 另请参阅:
SimpleLocaleContext
,SimpleTimeZoneAwareLocaleContext