类 AcceptHeaderLocaleResolver
- 所有已实现的接口:
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(cn.taketoday.web.RequestContext, java.util.Locale) since the
Accept-Language header can only be changed by changing the client's
locale settings.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
-
字段概要
字段从接口继承的字段 cn.taketoday.web.LocaleResolver
BEAN_NAME -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private LocalefindSupportedLocale(RequestContext request, List<Locale> supportedLocales) The configured default locale, if any.Return the configured list of supported locales.resolveLocale(RequestContext request) Resolve the current locale via the given request.voidsetDefaultLocale(Locale defaultLocale) Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.voidsetLocale(RequestContext request, 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.
-
字段详细资料
-
supportedLocales
-
defaultLocale
-
-
构造器详细资料
-
AcceptHeaderLocaleResolver
public AcceptHeaderLocaleResolver()
-
-
方法详细资料
-
setSupportedLocales
Configure 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().- 参数:
locales- the supported locales
-
getSupportedLocales
Return the configured list of supported locales. -
setDefaultLocale
Configure a fixed default locale to fall back on if the request does not have an "Accept-Language" header.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
RequestContext.getLocale().- 参数:
defaultLocale- the default locale to use
-
getDefaultLocale
The configured default locale, if any.This method may be overridden in subclasses.
-
resolveLocale
从接口复制的说明:LocaleResolverResolve the current locale via the given request. Can return a default locale as fallback in any case.- 指定者:
resolveLocale在接口中LocaleResolver- 参数:
request- the request to resolve the locale for- 返回:
- the current locale (never
null)
-
findSupportedLocale
-
setLocale
从接口复制的说明:LocaleResolverSet the current locale to the given one.- 指定者:
setLocale在接口中LocaleResolver- 参数:
request- the request to be used for locale modificationlocale- the new locale, ornullto clear the locale
-