View Source ZoonkWeb.Plugs.Translate (Zoonk v0.1.0-alpha)
Reusable functions for setting up multiple languages and translations.
Link to this section Summary
Functions
Get the browser's locale.
Language options for displaying on a select
component where the label is the key and the key is the value.
Get user's defined locale and set it to Gettext
. When the user hasn't defined a locale it,
we use the one defined at the current session.
Plug for adding a locale to the current session.
List all keys for supported languages.
Link to this section Functions
@spec get_browser_locale(Plug.Conn.t()) :: String.t()
Get the browser's locale.
This is a naive implementation that only takes the first locale from the accept-language
header.
If it's not supported by this application, it will return the @default_locale
.
Language options for displaying on a select
component where the label is the key and the key is the value.
@spec on_mount( atom(), Phoenix.LiveView.unsigned_params(), map(), Phoenix.LiveView.Socket.t() ) :: {:cont, Phoenix.LiveView.Socket.t()}
Get user's defined locale and set it to Gettext
. When the user hasn't defined a locale it,
we use the one defined at the current session.
@spec set_session_locale(Plug.Conn.t(), Keyword.t()) :: Plug.Conn.t()
Plug for adding a locale to the current session.
current_user
: Use the locale set by the user in their settings.unauthenticated
: Use the browser's locale.
@spec supported_locales() :: [atom()]
List all keys for supported languages.