# `Localize.Plug.PutSession`
[🔗](https://github.com/kipcole9/localize_web/blob/main/lib/localize/plug/put_session.ex#L1)

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
