Skip to content

Commit bff9954

Browse files
committed
build(deps): replace ex_cldr with localize and localize_web
Migrate off ex_cldr before support ends in 2027 and drop compile-time locale downloads.
1 parent 5e76490 commit bff9954

19 files changed

Lines changed: 130 additions & 109 deletions

File tree

.github/actions/setup-elixir-and-cache-deps/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ runs:
4949
with:
5050
path: |
5151
_build
52-
priv/cldr/locales
5352
key: ${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-build-${{ inputs.mix-env }}-${{ hashFiles('**/mix.lock') }}
5453
restore-keys: |
5554
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-mix-build-${{ inputs.mix-env }}-

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- ci: purge orphaned GHCR attestation referrers (#5622 - @swiffer)
1717
- test: stop the app in test_helper instead of relying on --no-start (#5615 - @swiffer)
1818
- build(deps): update flake.lock (#5613)
19+
- build(deps): replace `ex_cldr` / `ex_cldr_plugs` with `localize` and `localize_web` (ex_cldr support ends 2027-12-31). Drops compile-time locale download and the Nix `cldr` pin.
1920

2021
#### Dashboards
2122

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ COPY VERSION VERSION
4343
RUN mix compile
4444

4545
COPY config/runtime.exs config/runtime.exs
46-
RUN SKIP_LOCALE_DOWNLOAD=true mix release --path /opt/built
46+
RUN mix release --path /opt/built
4747

4848
########################################################################
4949

config/config.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,35 @@ config :phoenix,
3030

3131
config :gettext, :default_locale, "en"
3232

33+
# Static list so compile-time Localize calls see the same set as runtime.
34+
# Use CLDR IDs (hyphens, :"zh-Hans") — expanding Gettext names like
35+
# "zh_Hans" collapses to :zh via likely subtags and loses zh-Hant.
36+
config :localize,
37+
otp_app: :teslamate,
38+
default_locale: :en,
39+
allow_runtime_locale_download: false,
40+
supported_locales: [
41+
:ca,
42+
:da,
43+
:de,
44+
:en,
45+
:es,
46+
:fi,
47+
:fr,
48+
:hu,
49+
:it,
50+
:ja,
51+
:ko,
52+
:nb,
53+
:nl,
54+
:sv,
55+
:th,
56+
:tr,
57+
:uk,
58+
:"zh-Hans",
59+
:"zh-Hant"
60+
]
61+
3362
config :elixir, :time_zone_database, Tzdata.TimeZoneDatabase
3463

3564
import_config "#{config_env()}.exs"

lib/teslamate_web/cldr.ex

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/teslamate_web/controllers/car_controller.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ defmodule TeslaMateWeb.CarController do
1616
def index(conn, _) do
1717
live_render(conn, TeslaMateWeb.CarLive.Index,
1818
session: %{
19-
"settings" => conn.assigns[:settings],
20-
"locale" => get_session(conn, :locale)
19+
"settings" => conn.assigns[:settings]
2120
}
2221
)
2322
end

lib/teslamate_web/live/init_assigns.ex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ defmodule TeslaMateWeb.InitAssigns do
55

66
import Phoenix.Component
77

8-
def on_mount(:locale, _params, %{"gettext_locale" => locale}, socket) do
9-
Gettext.put_locale(locale)
10-
{:cont, assign(socket, :locale, locale)}
8+
def on_mount(:locale, _params, session, socket) do
9+
case Localize.Plug.put_locale_from_session(session, gettext: TeslaMateWeb.Gettext) do
10+
{:ok, _locale} ->
11+
:ok
12+
13+
{:error, _reason} ->
14+
Gettext.put_locale(TeslaMateWeb.Gettext, "en")
15+
end
16+
17+
{:cont, assign(socket, :locale, Gettext.get_locale(TeslaMateWeb.Gettext))}
1118
end
1219
end

lib/teslamate_web/live/settings_live/index.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ defmodule TeslaMateWeb.SettingsLive.Index do
134134
|> Enum.map(fn {key, val} -> {val, key} end)
135135
|> Enum.into(%{})
136136

137-
@supported_ui_languages TeslaMateWeb.Cldr.known_locale_names()
138-
|> Enum.reject(&(&1 in [:zh]))
139-
|> Enum.map(&String.replace(to_string(&1), "-", "_"))
137+
@supported_ui_languages TeslaMateWeb.Gettext
138+
|> Gettext.known_locales()
140139
|> Enum.map(&{Map.get(@language_tags, &1, &1), &1})
141140
|> Enum.sort_by(&elem(&1, 0))
142141

lib/teslamate_web/plugs/put_session.ex

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/teslamate_web/router.ex

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ defmodule TeslaMateWeb.Router do
88
plug :fetch_session
99
plug :fetch_live_flash
1010

11-
plug Cldr.Plug.AcceptLanguage,
12-
cldr_backend: TeslaMateWeb.Cldr,
13-
no_match_log_level: :debug
14-
15-
plug Cldr.Plug.PutLocale,
16-
apps: [:cldr, :gettext],
11+
# Query first so the settings UI language switcher (?locale=) beats session.
12+
plug Localize.Plug.PutLocale,
1713
from: [:query, :session, :accept_language],
14+
param: "locale",
1815
gettext: TeslaMateWeb.Gettext,
19-
cldr: TeslaMateWeb.Cldr
16+
default: :en
2017

21-
plug TeslaMateWeb.Plugs.PutSession
18+
plug Localize.Plug.PutSession, as: :string
2219

2320
plug :put_root_layout, {TeslaMateWeb.LayoutView, :root}
2421
plug :protect_from_forgery

0 commit comments

Comments
 (0)