diff --git a/lib/teslamate_web/controllers/car_controller.ex b/lib/teslamate_web/controllers/car_controller.ex index 47241b34..224bfbb6 100644 --- a/lib/teslamate_web/controllers/car_controller.ex +++ b/lib/teslamate_web/controllers/car_controller.ex @@ -15,7 +15,10 @@ defmodule TeslaMateWeb.CarController do def index(conn, _) do live_render(conn, TeslaMateWeb.CarLive.Index, - session: %{"settings" => conn.assigns[:settings], "locale" => get_session(conn, :locale)} + session: %{ + "settings" => conn.assigns[:settings], + "cldr_locale" => get_session(conn, :cldr_locale) + } ) end diff --git a/lib/teslamate_web/live/car_live/index.ex b/lib/teslamate_web/live/car_live/index.ex index 83587121..d74adaeb 100644 --- a/lib/teslamate_web/live/car_live/index.ex +++ b/lib/teslamate_web/live/car_live/index.ex @@ -7,7 +7,7 @@ defmodule TeslaMateWeb.CarLive.Index do alias TeslaMate.Settings.GlobalSettings @impl true - def mount(_params, %{"settings" => settings, "locale" => locale}, socket) do + def mount(_params, %{"settings" => settings, "cldr_locale" => locale}, socket) do socket = socket |> assign(locale: locale, page_title: gettext("Home")) diff --git a/lib/teslamate_web/live/car_live/index.html.leex b/lib/teslamate_web/live/car_live/index.html.leex index 4711082b..09285677 100644 --- a/lib/teslamate_web/live/car_live/index.html.leex +++ b/lib/teslamate_web/live/car_live/index.html.leex @@ -1,4 +1,4 @@ <%= for summary <- @summaries do %> <%= live_render @socket, TeslaMateWeb.CarLive.Summary, id: "car_#{summary.car.id}", - session: %{ "summary" => summary, "settings" => @settings, "locale" => @locale } %> + session: %{ "summary" => summary, "settings" => @settings, "cldr_locale" => @locale } %> <% end %> diff --git a/lib/teslamate_web/live/car_live/summary.ex b/lib/teslamate_web/live/car_live/summary.ex index 6a881f6f..02a86cd8 100644 --- a/lib/teslamate_web/live/car_live/summary.ex +++ b/lib/teslamate_web/live/car_live/summary.ex @@ -10,7 +10,7 @@ defmodule TeslaMateWeb.CarLive.Summary do @impl true def mount(_params, %{"summary" => %Summary{car: car} = summary} = session, socket) do if connected?(socket) do - Gettext.put_locale(session["locale"]) + Gettext.put_locale(session["cldr_locale"]) send(self(), :update_duration) send(self(), {:status, Vehicle.busy?(car.id)}) diff --git a/lib/teslamate_web/live/charge_live/cost.ex b/lib/teslamate_web/live/charge_live/cost.ex index 7e8706b8..c95ccf97 100644 --- a/lib/teslamate_web/live/charge_live/cost.ex +++ b/lib/teslamate_web/live/charge_live/cost.ex @@ -10,7 +10,7 @@ defmodule TeslaMateWeb.ChargeLive.Cost do import TeslaMateWeb.Gettext @impl true - def mount(%{"id" => id}, %{"locale" => locale}, socket) do + def mount(%{"id" => id}, %{"cldr_locale" => locale}, socket) do if connected?(socket), do: Gettext.put_locale(locale) charging_process = Log.get_charging_process!(id) diff --git a/lib/teslamate_web/live/geofence_live/form.ex b/lib/teslamate_web/live/geofence_live/form.ex index dd2162b8..f8af8b34 100644 --- a/lib/teslamate_web/live/geofence_live/form.ex +++ b/lib/teslamate_web/live/geofence_live/form.ex @@ -12,7 +12,7 @@ defmodule TeslaMateWeb.GeoFenceLive.Form do @impl true def mount(%{"id" => id}, session, socket) do - %{"settings" => settings, "locale" => locale} = session + %{"settings" => settings, "cldr_locale" => locale} = session if connected?(socket) do Gettext.put_locale(locale) @@ -24,7 +24,7 @@ defmodule TeslaMateWeb.GeoFenceLive.Form do end def mount(%{"lat" => lat, "lng" => lng}, session, socket) do - %{"settings" => settings, "locale" => locale} = session + %{"settings" => settings, "cldr_locale" => locale} = session if connected?(socket) do Gettext.put_locale(locale) @@ -42,7 +42,7 @@ defmodule TeslaMateWeb.GeoFenceLive.Form do end def mount(_params, session, socket) do - %{"settings" => settings, "locale" => locale} = session + %{"settings" => settings, "cldr_locale" => locale} = session if connected?(socket) do Gettext.put_locale(locale) diff --git a/lib/teslamate_web/live/geofence_live/index.ex b/lib/teslamate_web/live/geofence_live/index.ex index 41e4bf9f..106f6a13 100644 --- a/lib/teslamate_web/live/geofence_live/index.ex +++ b/lib/teslamate_web/live/geofence_live/index.ex @@ -7,7 +7,7 @@ defmodule TeslaMateWeb.GeoFenceLive.Index do alias TeslaMate.Convert @impl true - def mount(_params, %{"settings" => settings, "locale" => locale}, socket) do + def mount(_params, %{"settings" => settings, "cldr_locale" => locale}, socket) do if connected?(socket), do: Gettext.put_locale(locale) unit_of_length = diff --git a/lib/teslamate_web/live/import_live/index.ex b/lib/teslamate_web/live/import_live/index.ex index 8d101653..b38e7742 100644 --- a/lib/teslamate_web/live/import_live/index.ex +++ b/lib/teslamate_web/live/import_live/index.ex @@ -14,7 +14,7 @@ defmodule TeslaMateWeb.ImportLive.Index do alias TeslaMate.Import @impl true - def mount(_params, %{"settings" => _, "locale" => locale}, socket) do + def mount(_params, %{"settings" => _, "cldr_locale" => locale}, socket) do tz = if connected?(socket) do Gettext.put_locale(locale) diff --git a/lib/teslamate_web/live/settings_live/index.ex b/lib/teslamate_web/live/settings_live/index.ex index e3e01520..1808b1a6 100644 --- a/lib/teslamate_web/live/settings_live/index.ex +++ b/lib/teslamate_web/live/settings_live/index.ex @@ -7,7 +7,7 @@ defmodule TeslaMateWeb.SettingsLive.Index do alias TeslaMate.{Settings, Updater, Api} @impl true - def mount(_params, %{"settings" => settings, "locale" => locale}, socket) do + def mount(_params, %{"settings" => settings, "cldr_locale" => locale}, socket) do if connected?(socket), do: Gettext.put_locale(locale) assigns = %{ diff --git a/lib/teslamate_web/live/signin_live/index.ex b/lib/teslamate_web/live/signin_live/index.ex index 00296f24..8a4281ee 100644 --- a/lib/teslamate_web/live/signin_live/index.ex +++ b/lib/teslamate_web/live/signin_live/index.ex @@ -5,7 +5,7 @@ defmodule TeslaMateWeb.SignInLive.Index do alias TeslaMate.{Auth, Api} @impl true - def mount(_params, %{"locale" => locale}, socket) do + def mount(_params, %{"cldr_locale" => locale}, socket) do if connected?(socket), do: Gettext.put_locale(locale) assigns = %{ diff --git a/lib/teslamate_web/plugs/set_locale.ex b/lib/teslamate_web/plugs/set_locale.ex index ea50bcfa..7101d17d 100644 --- a/lib/teslamate_web/plugs/set_locale.ex +++ b/lib/teslamate_web/plugs/set_locale.ex @@ -10,16 +10,8 @@ defmodule TeslaMateWeb.Plugs.SetLocale do plug Cldr.Plug.SetLocale, apps: [:cldr, :gettext], from: [:query, :session, :accept_language], - session_key: "locale", gettext: TeslaMateWeb.Gettext, cldr: TeslaMateWeb.Cldr - plug :put_locale - - defp put_locale(conn, _opts) do - %Cldr.LanguageTag{gettext_locale_name: locale} = - Cldr.Plug.SetLocale.get_cldr_locale(conn) || TeslaMateWeb.Cldr.default_locale() - - put_session(conn, "locale", locale) - end + plug Cldr.Plug.SetSession end diff --git a/lib/teslamate_web/templates/layout/root.html.leex b/lib/teslamate_web/templates/layout/root.html.leex index 4a2981e3..3cae0db3 100644 --- a/lib/teslamate_web/templates/layout/root.html.leex +++ b/lib/teslamate_web/templates/layout/root.html.leex @@ -1,5 +1,5 @@ - + diff --git a/mix.lock b/mix.lock index cd6be3e3..084933fb 100644 --- a/mix.lock +++ b/mix.lock @@ -11,7 +11,7 @@ "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "ecto": {:hex, :ecto, "3.6.1", "7bb317e3fd0179ad725069fd0fe8a28ebe48fec6282e964ea502e4deccb0bd0f", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cbb3294a990447b19f0725488a749f8cf806374e0d9d0dffc45d61e7aeaf6553"}, "ecto_sql": {:hex, :ecto_sql, "3.6.1", "8774dc3fc0ff7b6be510858b99883640f990c0736b8ab54588f9a0c91807f909", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.6.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "66f35c3f2d5978b6bffebd1e6351ab8c9d6b68650d62abd1ab8d149de40e0779"}, - "ex_cldr": {:hex, :ex_cldr, "2.20.0", "571a4b490c333809be59cc984a21be2deaab1db9e2418e323d5935aec8b1394a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.15", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "06147e4a27be62e6fe92db14cf5048c645927bfc530aa1cc6af8c92d65e32427"}, + "ex_cldr": {:hex, :ex_cldr, "2.21.0", "27144a6649df3a315de85da5b9ad2db1b9e2a754d0c6ea498653b859b6340e04", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.15", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.13", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "4b3d8df8ada72f0d82e867fea7c88de9904c19dc69e5797684757ad64e907df7"}, "excoveralls": {:hex, :excoveralls, "0.14.0", "4b562d2acd87def01a3d1621e40037fdbf99f495ed3a8570dfcf1ab24e15f76d", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "94f17478b0cca020bcd85ce7eafea82d2856f7ed022be777734a2f864d36091a"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "finch": {:hex, :finch, "0.7.0", "2352962c81fd54952788d66e5eed436a7b734745e0c1cdd5b28a28184fe3e5cd", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.5", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4e046b6a4f010898a036244d680ae212331aab2f0a1005bcded3e3e3364f0025"},