GRI-2142: wire rust-i18n locale preference contract for panel i18n #276
No reviewers
Labels
No labels
Area/Backend
Area/Database
Area/Docs
Area/Frontend
Area/Infra
Area/Security
Area/Tests
Area/Tooling
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Lang/Python
Lang/Rust
Lang/Shell
Lang/SQL
Lang/TypeScript
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Routing
Auto
Routing
Hold
Routing
Human
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Grimoirix/grimoire-of-digital-signage!276
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/GRI-2142-i18n-locale-contract"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #274.
Summary
rust-i18nwired intoshared(bundles live here:crates/shared/locales/{en,nl}.yml) andserver— each crate callsrust_i18n::i18n!(...)itself, sincet!always expands tocrate::_rust_i18n_t!.crates/shared/build.rsenforces the three outcomes fromplan/shared/internationalisation.mdon 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. Reusesrust-i18n-support's own bundle loader; the "used in code" scan is hand-rolled rather thanrust-i18n-extract, because that crate'sCargo.tomlunconditionally pulls inserde_yaml→unsafe-libyaml(RUSTSEC-2024-0449, unmaintained, no safe upgrade), whichcargo denycorrectly refuses.config.i18n.default_locale(env overrideSIGNAGE_I18N_DEFAULT_LOCALE), refused at load if it names no shipped bundle (GRI-1884: never a literal).users.locale(migration0011, nullable:NULL= "use the server default").UserView.locale: the user's own preference, or the server default when they never set one. Returned byPOST /setup,POST /sessionandGET /session; settable withPATCH /session/locale(400 unknown_localefor anythingshared::locale::is_supportedrefuses).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 --checkcargo clippy --workspace --all-targets --locked -- -D warningscargo test --workspace --all-targets --locked(incl. newcrates/server/tests/session_locale_integration.rs, against a real Postgres viaSIGNAGE_TEST_DATABASE_URL) — 30/30 binaries greencargo test --workspace --doc --lockedcargo deny check -D advisory-not-detectedbuild.rsgate outcomes by temporarily introducing a stalenl.ymlkey and at!()call with noen.ymltext — both failed the build with the expected message; reverted.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.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.