View Source ZoonkWeb.Plugs.Translate (Zoonk v0.2.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

Link to this function

get_browser_locale(conn)

View Source
@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.

@spec language_options() :: [{String.t(), atom()}]

Language options for displaying on a select component where the label is the key and the key is the value.

Link to this function

on_mount(atom, params, session, socket)

View Source

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.

Link to this function

set_session_locale(conn, opts)

View Source
@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.