Expand description
icu_list
provides the ListFormatter
which renders sequences of Writeable
s as lists in a locale-sensitive way.
Examples
Format a list of strings in Spanish
use icu_list::{ListFormatter, ListStyle};
use icu_locid::locale;
use writeable::Writeable;
let list_formatter = ListFormatter::try_new_and(
locale!("es"),
&icu_testdata::get_provider(),
ListStyle::Wide,
)
.expect("Data should load successfully");
assert_eq!(
list_formatter.format(["España", "Suiza"].iter())
.write_to_string(),
"España y Suiza"
);
// The Spanish 'y' sometimes becomes an 'e':
assert_eq!(
list_formatter.format(["España", "Suiza", "Italia"].iter())
.write_to_string(),
"España, Suiza e Italia"
);
// We can use any Writeables as inputs:
assert_eq!(
list_formatter.format(1..=10).write_to_string(),
"1, 2, 3, 4, 5, 6, 7, 8, 9 y 10"
);
Modules
The Part
s used by ListFormatter
.
Data provider struct definitions for this ICU4X component.
Structs
The Writeable
implementation that is returned by ListFormatter::format
. See
the writeable
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.