Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/set_locale.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down