Skip to main content

Module i18n

Module i18n 

Source
Expand description

Locale messaging helpers. Automatic multi-language UI for human-facing suggestions.

§Language isolation (crates.io / agent contract)

  • All identifiers, comments, and technical message fields are English.
  • Portuguese appears only as catalog string literals for human suggestion UI text when locale resolves to pt-BR (not in identifiers or logs).
  • Agent-stable JSON error.message remains English regardless of locale.
  • Prefer [Mensagem] / [suggestion_key] over hardcoding UI strings at call sites.
  • Stdout JSON envelopes are not translated (machine contract).

§Boot order (rules multi-idioma)

  1. Windows console UTF-8 ([configure_console_utf8])
  2. TTY / plain / screen-reader hints (see crate::color)
  3. OS locale via sys-locale inside [resolve_locale]
  4. Parse → LanguageIdentifier (unic-langid)
  5. Negotiate against compiled packs (fluent-langneg)
  6. Publish in [OnceLock] via [set_effective_idioma]

§Precedence (5 layers)

--langBROWSER_AUTOMATION_CLI_LANG → XDG lang → system → default en

Structs§

ResolvedLocale
Result of the 5-layer resolution chain.

Enums§

Direcao
Text direction for terminal/UI rendering.
Idioma
Supported UI locale for human-facing suggestions.
LocaleSource
Where the effective UI locale came from (diagnostics / locale subcommand).
Mensagem
Every human-facing UI string key for this binary.
ScriptEscrita
Writing system tag used for documentation and future CJK/RTL packs.

Constants§

LANG_ENV
Product env override: BROWSER_AUTOMATION_CLI_LANG (rules: <CRATE_UPPER>_LANG).

Functions§

configure_console_utf8
Configure Windows console to UTF-8 (and VT) before any user-facing I/O.
detect_system_langid
Read OS locale once via sys-locale (never direct LANG reads in portable code).
effective_idioma
Current effective idioma (defaults to en if unset).
effective_lang
Current effective language legacy token (defaults to en if unset).
effective_resolved
Full resolved snapshot (for locale subcommand).
format_ftl
Format a message id from the embedded FTL; falls back to enum catalog on miss.
ftl_id
Stable FTL / catalog id for a Mensagem variant.
ftl_keys
Extract bare message ids from an FTL source (lines key = value, skip comments/blank).
ftl_source
Embedded FTL source for a compiled idioma.
locale_diagnostics
JSON-ready diagnostics for locale subcommand (machine keys English).
localize_error_suggestion
Apply kind-based localized suggestion when none is set, or re-map known EN strings.
negotiate
Negotiate requested identifiers against compiled packs; always returns a pack.
normalize_lang
Normalize lang token to legacy "en" or "pt".
parse_langid
Normalize raw OS / user locale strings into a LanguageIdentifier.
resolve
Full 5-layer resolution:
resolve_lang
Resolve language from CLI flag, then XDG config, then OS locale hints.
resolve_locale
Resolve language from CLI flag, then env, XDG, OS locale (see resolve).
set_effective_idioma
Store effective locale for the process (call once from run()).
set_effective_lang
Store effective language for the process (call once from run()).
suggestion_for
Localized suggestion for a known kind key.
suggestion_key
Catalog of stable suggestion keys (preferred over hard-coded English).
truncate_graphemes
Grapheme-aware truncation for terminal width (CJK-safe boundary).