Expand description
Public language-switcher data for templates.
The admin has a locale picker, but visitors had no built-in way to
switch language. This exposes a language_switcher() Tera function
returning the active locales — each with the URL to view the
current page in that locale, built per the configured
crate::locale_mode::LocaleMode:
<nav aria-label="Language">
{% for loc in language_switcher() %}
<a href="{{ loc.url }}"{% if loc.is_current %} aria-current="page"{% endif %}>
{{ loc.name }}</a>
{% endfor %}
</nav>Like crate::page_url, the per-request data is stashed in a
thread-local installed by the public render handler (it owns the
pool + the resolved locale + the mount prefix) and cleared by the
returned guard when tera.render finishes.
Structs§
- Pending
Guard - RAII guard clearing
PENDING_SWITCHERon drop — the router holds it across the render future so a stashed hand-off never leaks onto a pooled worker thread if the render short-circuits before consuming it. - Switcher
Entry - One entry in the switcher: a locale + the URL to the current page in it, and whether it’s the locale the request resolved to.
- Switcher
Guard - RAII guard — clears the thread-local on drop. Returned by
install.
Functions§
- build
- Build switcher entries for
url_pathacross the given activelocales. The URL shape followsmode: - install
- Install the switcher entries for the duration of the returned guard.
- register_
hreflang_ function - Register the
rcms_hreflang_tags(origin=…)Tera function. - register_
tera_ function - Register the
language_switcher()Tera function. - stash_
pending - Stash entries for the upcoming render on this thread and return a
guard that clears them on drop. Called by the public render handler
immediately before it polls the render future (no
.awaitin between), so the future’s first synchronous slice — the top ofcrate::render’srender_inner, which callstake_pending— runs on this same thread and sees them. - take_
pending - Take (and clear) any entries
stash_pending’d for this render. Called at the very top ofrender_inner, before its first.await, so the returnedVecbecomes a plain local that travels with the future across tokio thread-hops and can beinstalled in render’s await-free block right beforetera.render.