Expand description
Cross-platform language detection and resolution (Rules Rust i18n).
§Precedence (highest → lowest) — four product layers
- CLI
--langflag (validated BCP47; must negotiate to a supported locale) - Persisted preference (
<config_dir>/lang, XDG; 0o600 when written) vialocale set - OS locale via
sys_locale::get_locale()(never rawLANG/LC_*in portável) - Fallback:
Language::English(en)
SSH_CLI_LANG is a historical constant name only — not read as a product
config store (G-AUD-12). Use --lang or locale set.
§Pipeline
Raw string → strip encoding/modifier → _→- → LanguageIdentifier
(unic-langid) → negotiate against available locales (fluent-langneg) →
map to Language → publish once in OnceLock.
Detection failure is never silent: tracing::warn! records the miss
(observability / stderr diagnostics; no remote telemetry).
Structs§
- Locale
Resolution - Full resolution result (language + winning layer + raw inputs for diagnostics).
Enums§
- Locale
Source - Which precedence layer won resolution (diagnostics /
localesubcommand).
Constants§
- LANG_
PREFERENCE_ FILE - File name for the persisted language preference (sibling of
config.toml).
Functions§
- clear_
persisted_ lang - Removes the persisted language preference if present.
- current_
language - Returns the current global language.
- lang_
preference_ path - Path to the persisted language preference file.
- negotiate_
code - Negotiates a raw code against the available product locales.
- negotiate_
langid - Negotiates a structured identifier against available locales.
- normalize_
raw_ locale - Normalizes a raw locale string for BCP47 parse.
- parse_
lang_ cli_ arg - Clap
value_parserfor--lang: accepts BCP47 tags that negotiate to a supported product locale (en,en-US,pt-BR,pt, …). - parse_
language_ identifier - Parses a raw OS/CLI locale into a
LanguageIdentifier. - read_
persisted_ lang - Reads the persisted language preference (trimmed, non-empty).
- resolve_
config_ dir - Directory that holds
config.toml/lang(respects override and XDG). - resolve_
language - Resolves language using the CLI / XDG / OS / default precedence hierarchy.
- resolve_
language_ detailed - Like
resolve_language, but returns diagnostics forlocale/ tests. - set_
language - Sets the global language (once at process startup).
- write_
persisted_ lang - Writes the persisted language preference (BCP47 of a supported language).