Localize.Plug.PutSession (Localize Web v0.2.0)

Copy Markdown View Source

Plug that persists the locale discovered by Localize.Plug.PutLocale into the session.

The session key is fixed to "localize_locale" so that downstream functions like LiveView on_mount callbacks can retrieve the locale without needing additional configuration.

Options

  • :as determines the format in which the locale is saved in the session. The valid settings are:
    • :string in which the current locale is converted to a string before storing in the session. It will then be parsed back into a %Localize.LanguageTag{} upon reading it from the session. This option minimises space used in the session at the expense of CPU time to serialize and parse.

    • :language_tag in which the current locale is stored in the session in its native %Localize.LanguageTag{} format. This minimizes CPU time at the expense of larger session storage.

The default is as: :string.

Examples

plug Localize.Plug.PutLocale,
  apps: [:localize, :gettext],
  from: [:path, :query],
  gettext: MyApp.Gettext
plug Localize.Plug.PutSession, as: :string