Skip to main content

Module language_switcher

Module language_switcher 

Source
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§

PendingGuard
RAII guard clearing PENDING_SWITCHER on 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.
SwitcherEntry
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.
SwitcherGuard
RAII guard — clears the thread-local on drop. Returned by install.

Functions§

build
Build switcher entries for url_path across the given active locales. The URL shape follows mode:
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 .await in between), so the future’s first synchronous slice — the top of crate::render’s render_inner, which calls take_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 of render_inner, before its first .await, so the returned Vec becomes a plain local that travels with the future across tokio thread-hops and can be installed in render’s await-free block right before tera.render.