Skip to content

Instantly share code, notes, and snippets.

Created July 11, 2022 21:41
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Intl data via LiveView connect params
defmodule MyAppWeb.Intl do
@moduledoc """
Loads internationalization info from socket.
import Phoenix.LiveView
def on_mount(:default, _params, _session, socket) do
cparams = get_connect_params(socket)
|> assign(:locale, cparams["_intl_locale"])
|> assign(:timezone, cparams["_intl_timezone"])
|> assign(:timezone_offset, cparams["_intl_timezone_offset"])}
let liveSocket = new LiveSocket("/live", Socket, {
hooks: Hooks,
params: {
_csrf_token: csrfToken,
_intl_locale: Intl.NumberFormat().resolvedOptions().locale,
_intl_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
_intl_timezone_offset: -(new Date().getTimezoneOffset() / 60),
scope "/", MyAppWeb do
pipe_through :browser
live_session :default, on_mount: [MyAppWeb.Intl] do
live "/", PageLive.Index, :index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment