pub struct LocaleContext { /* private fields */ }Expand description
Runtime locale context with scoped overrides.
Implementations§
Source§impl LocaleContext
impl LocaleContext
Sourcepub fn new(locale: impl Into<Locale>) -> Self
pub fn new(locale: impl Into<Locale>) -> Self
Create a new locale context with the provided locale.
Sourcepub fn current_locale(&self) -> Locale
pub fn current_locale(&self) -> Locale
Get the active locale, honoring any scoped override.
Sourcepub fn base_locale(&self) -> Locale
pub fn base_locale(&self) -> Locale
Get the base locale without considering overrides.
Sourcepub fn set_locale(&self, locale: impl Into<Locale>)
pub fn set_locale(&self, locale: impl Into<Locale>)
Set the base locale.
Sourcepub fn direction(&self) -> TextDirection
pub fn direction(&self) -> TextDirection
Get the active text direction (from current locale unless overridden).
Sourcepub fn set_direction(&self, direction: Option<TextDirection>)
pub fn set_direction(&self, direction: Option<TextDirection>)
Set an explicit text direction override (or None to infer from locale).
Sourcepub fn subscribe(&self, callback: impl Fn(&Locale) + 'static) -> Subscription
pub fn subscribe(&self, callback: impl Fn(&Locale) + 'static) -> Subscription
Subscribe to base locale and direction changes.
Sourcepub fn push_override(&self, locale: impl Into<Locale>) -> LocaleOverride
pub fn push_override(&self, locale: impl Into<Locale>) -> LocaleOverride
Push a scoped locale override. Dropping the guard restores the prior locale.
Sourcepub fn number_formatter(&self) -> Result<NumberFormatter, FormattingError>
pub fn number_formatter(&self) -> Result<NumberFormatter, FormattingError>
Create a NumberFormatter configured for the active locale.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.
Sourcepub fn number_formatter_with_config(
&self,
config: NumberFormat,
) -> Result<NumberFormatter, FormattingError>
pub fn number_formatter_with_config( &self, config: NumberFormat, ) -> Result<NumberFormatter, FormattingError>
Create a NumberFormatter with custom configuration for the active locale.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.
Sourcepub fn datetime_formatter(&self) -> Result<DateTimeFormatter, FormattingError>
pub fn datetime_formatter(&self) -> Result<DateTimeFormatter, FormattingError>
Create a DateTimeFormatter for the active locale.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.
Sourcepub fn format_int<I: Into<i128>>(
&self,
val: I,
) -> Result<String, FormattingError>
pub fn format_int<I: Into<i128>>( &self, val: I, ) -> Result<String, FormattingError>
Format an integer value using the active locale’s conventions.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.
Sourcepub fn format_number(&self, val: f64) -> Result<String, FormattingError>
pub fn format_number(&self, val: f64) -> Result<String, FormattingError>
Format a float value using default decimal formatting for the active locale.
§Errors
Returns FormattingError if the locale is unsupported or if the float is non-finite.
Sourcepub fn format_date(
&self,
date: &Date,
style: DateFormatStyle,
) -> Result<String, FormattingError>
pub fn format_date( &self, date: &Date, style: DateFormatStyle, ) -> Result<String, FormattingError>
Format a date using the active locale’s conventions.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.
Sourcepub fn format_datetime(
&self,
dt: &DateTime,
date_style: DateFormatStyle,
time_style: TimeFormatStyle,
) -> Result<String, FormattingError>
pub fn format_datetime( &self, dt: &DateTime, date_style: DateFormatStyle, time_style: TimeFormatStyle, ) -> Result<String, FormattingError>
Format a combined date and time using the active locale’s conventions.
§Errors
Returns FormattingError::UnsupportedLocale if the active locale is not supported.