Which language to render, per request (SPEC §14). The host gives a Tempura
dictionary keyed by locale, a default locale, the locales the site speaks — :locales,
and without it the default alone (since 0.12.0) — and optionally a function returning
the request's own preference list (a choice kept in the session, a cookie, a URL
prefix). The languages are the host's decision and nobody else's: a plugin's
dictionary never adds one, and a host dictionary in a locale :locales does not name is
refused rather than served half the time. The base puts
two things on the request: :wb/tr, Tempura's translate function bound to
the preferences, and :wb/locale, the first preference the dictionary
actually supports, so <html lang> never names a language the page is not
rendered in.
Read from the request every time, never cached per session: the htmx fragment that arrives a second later carries the same headers and must land in the same language.
Which language to render, per request (SPEC §14). The host gives a Tempura dictionary keyed by locale, a default locale, the locales the site speaks — `:locales`, and without it the default alone (since 0.12.0) — and optionally a function returning the request's own preference list (a choice kept in the session, a cookie, a URL prefix). The languages are the host's decision and nobody else's: a plugin's dictionary never adds one, and a host dictionary in a locale `:locales` does not name is refused rather than served half the time. The base puts two things on the request: `:wb/tr`, Tempura's translate function bound to the preferences, and `:wb/locale`, the first preference the dictionary actually supports, so `<html lang>` never names a language the page is not rendered in. Read from the request every time, never cached per session: the htmx fragment that arrives a second later carries the same headers and must land in the same language.
(locales-of {:keys [locales default-locale]})The locales a site speaks: its :locales, or its :default-locale alone.
The locales a site speaks: its `:locales`, or its `:default-locale` alone.
(parse-accept-language header)The header's language tags ordered by descending quality, written order
among equals; entries with q=0 or an unparseable q are dropped. A
malformed header is a client's business, never an exception: it yields no
preference.
The header's language tags ordered by descending quality, written order among equals; entries with `q=0` or an unparseable q are dropped. A malformed header is a client's business, never an exception: it yields no preference.
(translator config prefs)The translate function :wb/tr is, outside any request: for mail a job sends, in
the language the host keeps for its recipient. config is the :i18n config as the
handler takes it — (:i18n (wb/expand config)), so the plugins' words are there — and
prefs the locales to try, best first; the site's default is tried last, as for a
request. Which language a person gets is the host's to know. Build it once per
language and keep it: each call reads the dictionary afresh and warns of a missing
word again.
The translate function `:wb/tr` is, outside any request: for mail a job sends, in the language the host keeps for its recipient. `config` is the `:i18n` config as the handler takes it — `(:i18n (wb/expand config))`, so the plugins' words are there — and `prefs` the locales to try, best first; the site's default is tried last, as for a request. Which language a person gets is the host's to know. Build it once per language and keep it: each call reads the dictionary afresh and warns of a missing word again.
(wrap handler config)Middleware adding :wb/tr and :wb/locale to every request.
Middleware adding `:wb/tr` and `:wb/locale` to every request.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |