pub enum Locale {
En,
PtBr,
}Expand description
Resolved UI locale for stderr prose.
Not #[non_exhaustive]: only en and pt-BR ship in the MVP binary and
exhaustive matches in this crate are intentional.
Variants§
Implementations§
Source§impl Locale
impl Locale
Sourcepub fn resolve(explicit: Option<&str>) -> AppResult<Self>
pub fn resolve(explicit: Option<&str>) -> AppResult<Self>
Resolve locale with fail-closed explicit tags and soft system fallback.
Precedence: explicit (CLI/config) → system locale → en.
Explicit tags that are not en / pt-BR (and en-* variants)
return InvalidInput (exit 65). Unknown system locales soft-fallback to English.
No product knob comes from the environment. The host locale does
reach step 2 through sys_locale (LC_ALL / LC_MESSAGES / LANG on
Unix); it steers stderr prose only, never a setting, and never stdout.
§Errors
Returns crate::error::ErrorKind::InvalidInput when an explicit tag is unsupported.
Sourcepub fn parse_supported(tag: &str) -> AppResult<Self>
pub fn parse_supported(tag: &str) -> AppResult<Self>
Parse an explicit lang tag. Fail-closed.
Accepted after normalization:
en,en-US,en_GB,en.UTF-8, …pt-BR,pt_BR,pt-br,pt_BR.UTF-8(region must be BR)
Rejected: bare pt, pt-PT, fr, empty, unknown tags.
§Errors
Returns crate::error::ErrorKind::InvalidInput when tag is empty or unsupported.
Sourcepub fn from_system() -> Self
pub fn from_system() -> Self
Soft-detect from OS locale (unknown tags → English).
Called after tracing init in the binary path. Logs when the OS returns
no locale so detection failure is visible under -v.
Sourcepub fn soft_from_tag(tag: &str) -> Self
pub fn soft_from_tag(tag: &str) -> Self
Soft map a system/BCP47-ish tag (never errors).
Any primary language pt (including pt, pt-PT, pt_BR.UTF-8) maps
to Locale::PtBr for the MVP bilingual bundle.
Sourcepub fn progress_fetching(self, target: &str) -> String
pub fn progress_fetching(self, target: &str) -> String
Progress line after the 2s threshold.
Sourcepub fn error_prefix(self) -> &'static str
pub fn error_prefix(self) -> &'static str
Prefix for human stderr errors.
Sourcepub fn format_error(self, err: &AppError) -> String
pub fn format_error(self, err: &AppError) -> String
Prefix and render an AppError for human stderr.
The message comes from the typed catalogue via AppError::localized,
so pt-BR coverage is enforced by the compiler. This replaced a
starts_with matcher over English prose whose fallback returned English
unchanged: a new message was untranslatable and indistinguishable from
a translated one.
Sourcepub fn from_argv_for_bootstrap<I, T>(args: I) -> Self
pub fn from_argv_for_bootstrap<I, T>(args: I) -> Self
Locale for messages emitted before argv is parsed.
The binary entrypoint reports two failures that happen during bootstrap:
a duplicate rustls CryptoProvider and a runtime that will not build.
Both precede clap, so neither Locale::resolve nor the XDG config is
available — reading config.toml there would put disk I/O ahead of TLS
setup and invert the bootstrap order fixed by ADR 0007.
So this scans argv directly for --lang <tag> / --lang=<tag>: no disk,
no environment variable, one linear pass. It uses
Locale::soft_from_tag rather than Locale::parse_supported on
purpose — a malformed tag must not turn a bootstrap failure into a second,
unrelated error. Absent or unknown tags fall back to English, matching
what the normal path would print before the system locale is consulted.
This is the only sanctioned pre-argv message path in the product.
Sourcepub fn bootstrap_provider_conflict(self) -> &'static str
pub fn bootstrap_provider_conflict(self) -> &'static str
Bootstrap failure: a rustls CryptoProvider was already installed.
Sourcepub fn bootstrap_runtime_failure(self, detail: &str) -> String
pub fn bootstrap_runtime_failure(self, detail: &str) -> String
Bootstrap failure: the async runtime could not be built.
Trait Implementations§
impl Copy for Locale
impl Eq for Locale
impl StructuralPartialEq for Locale
Auto Trait Implementations§
impl Freeze for Locale
impl RefUnwindSafe for Locale
impl Send for Locale
impl Sync for Locale
impl Unpin for Locale
impl UnsafeUnpin for Locale
impl UnwindSafe for Locale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.