类 AcceptHeaderLocaleResolver

java.lang.Object
cn.taketoday.web.i18n.AcceptHeaderLocaleResolver
所有已实现的接口:
LocaleResolver

public class AcceptHeaderLocaleResolver extends Object implements 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
另请参阅:
  • 字段详细资料

    • supportedLocales

      private final List<Locale> supportedLocales
    • defaultLocale

      @Nullable private Locale defaultLocale
  • 构造器详细资料

    • AcceptHeaderLocaleResolver

      public AcceptHeaderLocaleResolver()
  • 方法详细资料

    • setSupportedLocales

      public void setSupportedLocales(List<Locale> locales)
      Configure the list of supported locales to compare and match against requested 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 defaultLocale is used, if configured, or otherwise falling back on ServletRequest.getLocale().

      参数:
      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.

      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

      @Nullable public Locale getDefaultLocale()
      The configured default locale, if any.

      This method may be overridden in subclasses.

    • resolveLocale

      public Locale resolveLocale(RequestContext request)
      从接口复制的说明: LocaleResolver
      Resolve 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

      @Nullable private Locale findSupportedLocale(RequestContext request, List<Locale> supportedLocales)
    • setLocale

      public void setLocale(RequestContext request, @Nullable Locale locale)
      从接口复制的说明: LocaleResolver
      Set the current locale to the given one.
      指定者:
      setLocale 在接口中 LocaleResolver
      参数:
      request - the request to be used for locale modification
      locale - the new locale, or null to clear the locale