Cldr v1.7.0 Cldr.Plug.SetLocale View Source

Sets the Cldr and/or Gettext locales derived from the accept-language header, a query parameter, a url parameter, a body parameter or the session.

Options

  • :apps - list of apps for which to set locale. Valid apps are :cldr and :gettext. The default is :cldr.

  • :from - where in the request to look for the locale. The default is [:session, :accept_language]. The valid options are:

    • :accept_language will parse the accept-language header and finds the best matched configured locale
    • :path will look for a locale by examining conn.path_params
    • :query will look for a locale by examining conn.query_params
    • :body will look for a locale by examining conn.body_params
    • :cookie will look for a locale in the request cookie(s)
    • :session will look for a locale in the session
  • :default - the default locale to set if no locale is found by other configured methods. It can be a string like “en” or a Cldr.LanguageTag.t/0 struct. The default is Cldr.default_locale()

  • :gettext - the name of the Gettext module upon which the locale should be set

  • :session_key - defines the key used to look for the locale in the session. The default is “locale”.

If a locale is found then conn.private[:cldr_locale] is also set. It can be retrieved with Cldr.Plug.SetLocale.get_cldr_locale/1.

Example

plug Cldr.Plug.SetLocale,
  apps:    [:cldr, :gettext],
  from:    [:query, :path, :body, :cookie, :accept_language],
  param:   "locale",
  default: Cldr.default_locale,
  gettext: GetTextModule,
  session_key: "cldr_locale"

Link to this section Summary

Link to this section Functions

Return the locale set by Cldr.Plug.SetLocale