diff --git a/README.md b/README.md index 0fe3522..0aec02e 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,21 @@ defmodule MyApp.Router do pipe_through :browser get "/", PageController, :index ... + # If you are using Phoenix LiveView, use the following: + live "/livepage", PageLive, session: [:locale] end end ``` +### Phoenix LiveView +You need to set the locale in the mount/2 function of your page +```elixir +def mount(session, socket) do + Gettext.put_locale(session.locale) + ... +end +``` + ### Options - gettext: mandatory - default_locale: mandatory, used as last step in fallback chain diff --git a/lib/set_locale.ex b/lib/set_locale.ex index d55b376..0db62e0 100644 --- a/lib/set_locale.ex +++ b/lib/set_locale.ex @@ -39,6 +39,7 @@ defmodule SetLocale do do: Gettext.put_locale(config.gettext, config.default_locale), else: Gettext.put_locale(config.gettext, requested_locale) assign(conn, :locale, requested_locale) + put_session(conn, :locale, requested_locale) else path = rewrite_path(conn, requested_locale, config)