Expand description
Formatting lists in a locale-sensitive way.
This module is published as its own crate (icu_list
)
and as part of the icu
crate. See the latter for more details on the ICU4X project.
§Examples
§Formatting and lists in Spanish
let list_formatter = ListFormatter::try_new_and_with_length(
&locale!("es").into(),
ListLength::Wide,
)
.expect("locale should be present");
assert_writeable_eq!(
list_formatter.format(["España", "Suiza"].iter()),
"España y Suiza",
);
// The Spanish 'y' sometimes becomes an 'e':
assert_writeable_eq!(
list_formatter.format(["España", "Suiza", "Italia"].iter()),
"España, Suiza e Italia",
);
§Formatting or lists in Thai
let list_formatter = ListFormatter::try_new_or_with_length(
&locale!("th").into(),
ListLength::Short,
)
.expect("locale should be present");
// We can use any Writeables as inputs
assert_writeable_eq!(list_formatter.format(1..=3), "1, 2 หรือ 3",);
§Formatting unit lists in English
let list_formatter = ListFormatter::try_new_unit_with_length(
&locale!("en").into(),
ListLength::Wide,
)
.expect("locale should be present");
assert_writeable_eq!(
list_formatter.format(["1ft", "2in"].iter()),
"1ft, 2in",
);
Note: this last example is not fully internationalized. See icu4x/2192 for full unit handling.
Re-exports§
pub use ListError as Error;
Modules§
- error 🔒
- The
Part
s used byListFormatter
. - patterns 🔒
- 🚧 [Unstable] Data provider struct definitions for this ICU4X component.
Structs§
- The
Writeable
implementation that is returned byListFormatter::format
. See thewriteable
crate for how to consume this. - A formatter that renders sequences of items in an i18n-friendly way. See the crate-level documentation for more details.
Enums§
- A list of error outcomes for various operations in this module.
- Represents the style of a list. See the CLDR spec for an explanation of the different styles.