pub struct I18nFormatter { /* private fields */ }Expand description
基于 ICU4X 编译数据的 locale 感知格式化器。
通过 BCP-47 locale 标签(如 "en-US"、"zh-CN")构造。
所有格式化器在构造时 eagerly 创建,后续格式化调用低分配。
Implementations§
Source§impl I18nFormatter
impl I18nFormatter
Sourcepub fn new(locale: &str) -> Result<Self, I18nError>
pub fn new(locale: &str) -> Result<Self, I18nError>
Create a new formatter for the given BCP-47 locale tag.
§Errors
Returns I18nError::InvalidLocale if the tag cannot be parsed,
or I18nError::FormatError if ICU4X lacks compiled data for it.
Sourcepub fn format_number(&self, value: f64) -> Result<String, I18nError>
pub fn format_number(&self, value: f64) -> Result<String, I18nError>
Format a floating-point number with locale-sensitive grouping and decimal separators.
§Errors
Returns I18nError::InvalidNumber for non-finite values or
if the value cannot be parsed into a fixed decimal.
Sourcepub fn format_date(
&self,
year: i32,
month: u8,
day: u8,
) -> Result<String, I18nError>
pub fn format_date( &self, year: i32, month: u8, day: u8, ) -> Result<String, I18nError>
Format an ISO calendar date (year / month / day) using a medium length locale-specific pattern.
§Errors
Returns I18nError::DateError if any component is out of range,
or I18nError::FormatError if the formatter cannot be constructed.
Sourcepub fn plural_category(&self, count: u64) -> Result<PluralCategory, I18nError>
pub fn plural_category(&self, count: u64) -> Result<PluralCategory, I18nError>
Return the plural category for count in the formatter’s locale.
§Errors
This method does not currently fail, but returns Result for API
consistency with the other formatting methods.
Trait Implementations§
Auto Trait Implementations§
impl !Send for I18nFormatter
impl !Sync for I18nFormatter
impl Freeze for I18nFormatter
impl RefUnwindSafe for I18nFormatter
impl Unpin for I18nFormatter
impl UnsafeUnpin for I18nFormatter
impl UnwindSafe for I18nFormatter
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more