Skip to main content

Module locale

Module locale 

Source
Expand description

Cross-platform language detection and resolution (Rules Rust i18n).

§Precedence (highest → lowest) — four product layers

  1. CLI --lang flag (validated BCP47; must negotiate to a supported locale)
  2. Persisted preference (<config_dir>/lang, XDG; 0o600 when written) via locale set
  3. OS locale via sys_locale::get_locale() (never raw LANG / LC_* in portável)
  4. 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§

LocaleResolution
Full resolution result (language + winning layer + raw inputs for diagnostics).

Enums§

LocaleSource
Which precedence layer won resolution (diagnostics / locale subcommand).

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_parser for --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 for locale / tests.
set_language
Sets the global language (once at process startup).
write_persisted_lang
Writes the persisted language preference (BCP47 of a supported language).