feat(ui): wire the i18n foundation into the web UI (#187)#191
Open
angela-helios wants to merge 4 commits into
Open
feat(ui): wire the i18n foundation into the web UI (#187)#191angela-helios wants to merge 4 commits into
angela-helios wants to merge 4 commits into
Conversation
# Conflicts: # Cargo.lock
Plug the locale structure from feat/i18n-foundation into the helios-ui crate from #186 — the runtime wiring #187 deliberately deferred: - crates/ui/src/i18n.rs: negotiate_locale middleware producing one RequestLocale per request (?lang= override -> hfs_lang cookie -> Accept-Language via RFC 4647 Lookup -> en), an explicit ?lang= choice persisted in the cookie, Vary: Accept-Language, Cookie on responses, and the I18n Fluent lookup helper templates resolve keys through. - Catalogs embedded at compile time via fluent-templates static_loader (no runtime file/CDN dependency, same stance as the vendored assets), falling back negotiated locale -> en, key echo for unknown keys. - Templates now hold catalog keys, not prose; <html lang> reflects the negotiated locale; no-JS language switcher with aria-current. - New keys (home-lede, status-version, status-last-checked, action-refresh-status) seeded across en/es/de; en stays the source of truth and a test parses all three .ftl files to enforce key-set parity. - tests/i18n_http.rs drives the mounted router end to end: header negotiation, override cookie, persistence, localized htmx fragments. - docs/multi-language.md: crate name updated to helios-ui post-#188 review; point at the now-existing wiring.
65c1375 to
d0bb1ce
Compare
# Conflicts: # Cargo.lock
4 tasks
…at/i18n-ui-wiring # Conflicts: # Cargo.lock # crates/ui/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires the i18n foundation from #187 into the UI crate from #186, so the two foundations meet: one negotiated locale per request, threaded from the browser to the templates.
Stacked PR — depends on #188. Base branch is
feat/htmx-ui-foundation; merge #188 first, then this. (The first commit mergesmainto pick up thelocales/catalogs from #187, so the diff shrinks further once the base catches up with main.)What this adds
crates/ui/src/i18n.rs— the runtime wiring Foundation: multi-language support (i18n) for the HFS UI (en/es/de) #187 deliberately deferred to this crate:negotiate_localemiddleware: oneRequestLocaleper request, precedence?lang=override →hfs_langcookie →Accept-Language(RFC 4647 §3.4 Lookup with subtag truncation, quality-ordered) →en. An explicit?lang=is persisted in the cookie (SameSite=Lax, 1 year).I18ntemplate helper:t(key)/t_arg(key, name, value)against the Fluent catalogs, embedded at compile time viafluent-templates(static_loader!) — no runtime file/CDN dependency, same stance as the vendored assets. Fallback chain per the ratified policy: negotiated locale →en; unknown keys render the key, never a blank or a crash.base.html,index.html, andpartials/status.htmlnow resolve everything throughi18n.t(...);<html lang>reflects the negotiated locale; a no-JS language switcher (plain?lang=links) marks the active locale witharia-current.en/es/de,enfirst as source of truth):home-lede,status-version,status-last-checked,action-refresh-status..ftlfiles and fails if any locale drifts fromen. Plustests/i18n_http.rs: end-to-end through the mounted router (Accept-Language selects the language,?lang=sets the cookie, the cookie sticks, htmx fragments are localized too).docs/multi-language.md§2/§10 updated to the crate's post-review name (helios-ui) and to point at the now-existing wiring.Verified against the running server
Built
hfs --features uiand drove/uiwith a real client: German viaAccept-Language: de-DE, de;q=0.9, Spanish via?lang=es(Set-Cookie observed, subsequent cookie-only request stays Spanish), English default, localized htmx fragment onHX-Request.Heads-up for reviewers
maincurrently contains a parallel UI scaffold atcrates/web(helios-web, commit 5f1bbd9) that overlaps with this crate (crates/ui, renamed fromhelios-webin #188 per review). After the merge that this branch carries, both crates coexist in the workspace. This PR wires i18n intocrates/uionly; reconciling the two scaffolds is a #186 decision that should happen in #188 before or when this lands.Closes the runtime-wiring follow-up of #187 (the catalogs, conventions, and discussion doc are already on
main).