Skip to main content

I18nFormatter

Struct I18nFormatter 

Source
pub struct I18nFormatter { /* private fields */ }
Expand description

基于 ICU4X 编译数据的 locale 感知格式化器。

通过 BCP-47 locale 标签(如 "en-US""zh-CN")构造。 所有格式化器在构造时 eagerly 创建,后续格式化调用低分配。

Implementations§

Source§

impl I18nFormatter

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn compare(&self, a: &str, b: &str) -> Result<Ordering, I18nError>

Compare two strings using locale-sensitive collation rules.

§Errors

This method does not currently fail, but returns Result for API consistency with the other formatting methods.

Trait Implementations§

Source§

impl Debug for I18nFormatter

Source§

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

Formats the value using the given formatter. Read more

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.