Expand description
Locale negotiation middleware - the session-reading half of
larust_lang’s own current-locale story (see that crate’s doc comment
for the full design: translation files, t/t_with, the task-local
scope this wraps). Opt-in, like require_auth/csrf::verify - unlike
push_registry_scope, larust_lang::current_locale() already degrades
correctly with no scope established at all (falls back to
Config::app_locale), so there’s no “always on, unconditional” case to
make for this the way there was for @push/@stack.
Constants§
- SESSION_
KEY - The session key
LanguageController-style app code shouldsession.insert("locale", ...)into - matches whatever a real app’s own language-switcher route already sets, so wiring this middleware in doesn’t require renaming an existing session key.
Functions§
- negotiate
- Establishes a fresh
larust_langlocale scope for this request, then - if the session already has a stored"locale"value - overrides it for the rest of the request. Add after.with_sessions(...), the same ordering constraintcsrf::verify/require_authalready have: - negotiate_
from_ header negotiate’s session-free sibling, for routers with no cookie session at all - a bearer-token API (routes/api.rs’s own shape) has nowhere to persist a per-user locale choice, but a caller can still say what they want on each request via the standardAccept-Languageheader, so this reads that instead of a session key. Same task-local scope, same “degrade toConfig::app_localeif unrecognized” fallback asnegotiate- just a different source for the raw locale string.