GRI-2142: wire rust-i18n locale preference contract for panel i18n #276

Merged
vivy merged 2 commits from feature/GRI-2142-i18n-locale-contract into dev 2026-11-16 11:07:58 +00:00
Member

Closes #274.

Summary

  • rust-i18n wired into shared (bundles live here: crates/shared/locales/{en,nl}.yml) and server — each crate calls rust_i18n::i18n!(...) itself, since t! always expands to crate::_rust_i18n_t!.
  • crates/shared/build.rs enforces the three outcomes from plan/shared/internationalisation.md on every build: a key used in code with no English text fails the build; a key missing from a translation is a warning only; a stale key (in a translation, absent from English) fails the build. Reuses rust-i18n-support's own bundle loader; the "used in code" scan is hand-rolled rather than rust-i18n-extract, because that crate's Cargo.toml unconditionally pulls in serde_yaml → unsafe-libyaml (RUSTSEC-2024-0449, unmaintained, no safe upgrade), which cargo deny correctly refuses.
  • config.i18n.default_locale (env override SIGNAGE_I18N_DEFAULT_LOCALE), refused at load if it names no shipped bundle (GRI-1884: never a literal).
  • users.locale (migration 0011, nullable: NULL = "use the server default").
  • UserView.locale: the user's own preference, or the server default when they never set one. Returned by POST /setup, POST /session and GET /session; settable with PATCH /session/locale (400 unknown_locale for anything shared::locale::is_supported refuses).

Not wired: the client reading its own configured locale for its message screens (pending-registration, key-mismatch, etc.) — no client message is translated yet, so there is nothing yet for that side to call t!() on. Left for whichever issue converts the first of those screens, ahead of #38 (the panel's language switcher, which this contract unblocks).

Test plan

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo test --workspace --all-targets --locked (incl. new crates/server/tests/session_locale_integration.rs, against a real Postgres via SIGNAGE_TEST_DATABASE_URL) — 30/30 binaries green
  • cargo test --workspace --doc --locked
  • cargo deny check -D advisory-not-detected
  • Manually verified all three build.rs gate outcomes by temporarily introducing a stale nl.yml key and a t!() call with no en.yml text — both failed the build with the expected message; reverted.
Closes #274. ## Summary - `rust-i18n` wired into `shared` (bundles live here: `crates/shared/locales/{en,nl}.yml`) and `server` — each crate calls `rust_i18n::i18n!(...)` itself, since `t!` always expands to `crate::_rust_i18n_t!`. - `crates/shared/build.rs` enforces the three outcomes from `plan/shared/internationalisation.md` on every build: a key used in code with no English text fails the build; a key missing from a translation is a warning only; a stale key (in a translation, absent from English) fails the build. Reuses `rust-i18n-support`'s own bundle loader; the "used in code" scan is hand-rolled rather than `rust-i18n-extract`, because that crate's `Cargo.toml` unconditionally pulls in `serde_yaml` → `unsafe-libyaml` (RUSTSEC-2024-0449, unmaintained, no safe upgrade), which `cargo deny` correctly refuses. - `config.i18n.default_locale` (env override `SIGNAGE_I18N_DEFAULT_LOCALE`), refused at load if it names no shipped bundle (GRI-1884: never a literal). - `users.locale` (migration `0011`, nullable: `NULL` = "use the server default"). - `UserView.locale`: the user's own preference, or the server default when they never set one. Returned by `POST /setup`, `POST /session` and `GET /session`; settable with `PATCH /session/locale` (`400 unknown_locale` for anything `shared::locale::is_supported` refuses). Not wired: the client reading its own configured locale for its message screens (pending-registration, key-mismatch, etc.) — no client message is translated yet, so there is nothing yet for that side to call `t!()` on. Left for whichever issue converts the first of those screens, ahead of #38 (the panel's language switcher, which this contract unblocks). ## Test plan - [x] `cargo fmt --all --check` - [x] `cargo clippy --workspace --all-targets --locked -- -D warnings` - [x] `cargo test --workspace --all-targets --locked` (incl. new `crates/server/tests/session_locale_integration.rs`, against a real Postgres via `SIGNAGE_TEST_DATABASE_URL`) — 30/30 binaries green - [x] `cargo test --workspace --doc --locked` - [x] `cargo deny check -D advisory-not-detected` - [x] Manually verified all three `build.rs` gate outcomes by temporarily introducing a stale `nl.yml` key and a `t!()` call with no `en.yml` text — both failed the build with the expected message; reverted.
GRI-2142: wire rust-i18n and a locale preference contract
All checks were successful
CI / the pre-push hook (pull_request) Successful in 4s
CI / install.sh client upgrade (pull_request) Successful in 18s
CI / cargo fmt (pull_request) Successful in 6s
CI / cargo deny (pull_request) Successful in 19s
CI / cargo clippy (pull_request) Successful in 1m25s
CI / cargo deny advisories (pull_request) Successful in 31s
CI / repository boundary (pull_request) Successful in 4s
CI / frontend-web (pull_request) Successful in 1m26s
CI / cargo test (pull_request) Successful in 4m58s
CI / CI (pull_request) Successful in 1s
CI / Notify gate failed (pull_request) Has been skipped
4ed1a0012f
Bundles land in crates/shared/locales/{en,nl}.yml, loaded via rust_i18n::i18n!
in shared and server (t! always expands to crate::_rust_i18n_t!, so each
crate that translates needs its own invocation). crates/shared/build.rs
enforces the source-first, missing-translation-warns and stale-key rules on
every build, reusing rust-i18n's own bundle loader; the source scan for a
used-but-untranslated key is hand-rolled rather than rust-i18n-extract, whose
Cargo.toml drags in the unmaintained unsafe-libyaml via serde_yaml.

UserView gains a resolved locale field (the user's own preference, or
config.i18n.default_locale for one who never set it), returned by
/setup, /session and settable with PATCH /session/locale.
vivy approved these changes 2026-11-16 10:47:09 +00:00
vivy left a comment

Approved. Checked: migration 0011 is the next number on dev, nullable, with rollback; env override applied before the locale check; PATCH /session/locale validated; no literal (GRI-1884). Branch is behind dev; I update it and merge on green.

Approved. Checked: migration 0011 is the next number on dev, nullable, with rollback; env override applied before the locale check; PATCH /session/locale validated; no literal (GRI-1884). Branch is behind dev; I update it and merge on green.
Merge branch 'dev' into feature/GRI-2142-i18n-locale-contract
All checks were successful
CI / the pre-push hook (pull_request) Successful in 4s
CI / install.sh client upgrade (pull_request) Successful in 16s
CI / cargo fmt (pull_request) Successful in 6s
CI / cargo clippy (pull_request) Successful in 1m38s
CI / cargo deny (pull_request) Successful in 21s
CI / cargo deny advisories (pull_request) Successful in 21s
CI / repository boundary (pull_request) Successful in 4s
CI / frontend-web (pull_request) Successful in 1m3s
CI / cargo test (pull_request) Successful in 4m18s
CI / CI (pull_request) Successful in 3s
CI / Notify gate failed (pull_request) Has been skipped
19b8e09b4d
vivy merged commit d54ea3268f into dev 2026-11-16 11:07:58 +00:00
vivy deleted branch feature/GRI-2142-i18n-locale-contract 2026-11-16 11:07:59 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage!276
No description provided.