Expand description
Process-wide translation and formatting hooks - the surfaces a script host reaches an app’s locale through.
Both capabilities live in lumen-i18n (Fluent bundles, locale fallback,
ICU4X formatters), which core does not depend on: core carries no
backend crates. What core owns is the seam. The runtime installs a
translator with set_translator once it has loaded the app’s
catalogues, and a formatter with set_formatter once it knows the
locale; every script host calls translate from its t() / tr()
builtin and [format] from its format_* builtins, without linking
Fluent or ICU or reaching into the world.
[format] takes two opaque strings, a spec and a value, and hands back
what the other side made of them. Core never learns that currency:EUR
names a currency, which is what lets a core-owned system apply a format
without core naming the capability.
This mirrors crate::nav: one process-global bus, many producers and
consumers, no per-language plumbing. An app that never installs a
translator still resolves every key - translate returns the key
itself, which is exactly what an untranslated string should render as -
and an app with no formatter leaves every value as it stands.
An app’s locale is not fixed for the life of the process: AppI18n
carries the switch, and active_locale answers which locale is
running for a script that has no world to read the resource from.
One of each is live at a time, so a host process running two Lumen apps
shares the second app’s catalogue and locale with the first. Markup
avoids this by reading AppI18n off the world instead, which is the
same set of handles scoped to one app.
Both shapes are opaque the whole way through, so a host links only what it installs. A page whose text was already written for its locale while the site was built installs nothing here, and carries neither a catalogue nor a formatter.
Structs§
- AppI18n
- One app’s own translator, formatter and locale switch, held in its world.
- Locale
Change - What changed when an app switched locale: the locale it is now in, and the writing direction that locale reads in.
Functions§
- active_
locale - The locale the app is running in, or an empty string when nothing has published one.
- clear_
formatter - Remove the installed formatter. [
format] answersNonefor everything afterwards. - clear_
translator - Remove the installed translator.
translatefalls back to returning keys verbatim. - format
- Format
valueperspec, orNonewhen no formatter is installed, the spec is not one it knows, or the value is not what the spec expects. A caller showsvalueunchanged then. - set_
active_ locale - Publish the locale the app is running in. The runtime calls this once the locale is resolved, and again every time it changes.
- set_
formatter - Install the process-wide formatter, replacing any previous one.
- set_
translator - Install the process-wide translator, replacing any previous one.
- translate
- Resolve
key, falling back to the key itself. This is what a script’st("key")returns. - try_
translate - Resolve
keyagainst the installed translator, orNonewhen no translator is installed or the catalogue lacks the key.
Type Aliases§
- Formatter
- Formats one value the way one spec asks for. Both arguments are
opaque to core: the spec is whatever a
formatattribute or aformat_*builtin wrote, and what it means is the formatter’s business. ReturnsNonewhen the spec is not one it knows or the value is not what that spec expects, so callers can leave the text alone. - Locale
Setter - Switches one app to another locale, answering with what changed, or
Nonewhen the tag is not a locale at all and nothing moved. - Translator
- Resolves a translation key against the active catalogue. Returns
Nonewhen the catalogue has no entry for the key, so callers can apply their own fallback.