Skip to main content

Locale

Enum Locale 

Source
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§

§

En

English human messages.

§

PtBr

Brazilian Portuguese human messages.

Implementations§

Source§

impl Locale

Source

pub fn as_bcp47(self) -> &'static str

Stable BCP 47 tag for diagnostics (en or pt-BR).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn progress_fetching(self, target: &str) -> String

Progress line after the 2s threshold.

Source

pub fn error_prefix(self) -> &'static str

Prefix for human stderr errors.

Source

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.

Source

pub fn doctor_ok(self, ok: bool) -> String

Doctor summary line.

Source

pub fn from_argv_for_bootstrap<I, T>(args: I) -> Self
where I: IntoIterator<Item = T>, T: AsRef<OsStr>,

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.

Source

pub fn bootstrap_provider_conflict(self) -> &'static str

Bootstrap failure: a rustls CryptoProvider was already installed.

Source

pub fn bootstrap_runtime_failure(self, detail: &str) -> String

Bootstrap failure: the async runtime could not be built.

Trait Implementations§

Source§

impl Clone for Locale

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Locale

Source§

impl Debug for Locale

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Locale

Source§

impl Hash for Locale

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Locale

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Locale

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more