Crates.io | icu_list |
lib.rs | icu_list |
version | 2.0.0-beta1 |
source | src |
created_at | 2021-04-29 20:10:14.192332 |
updated_at | 2024-11-23 02:16:01.219009 |
description | ECMA-402 ListFormatter |
homepage | https://icu4x.unicode.org |
repository | https://github.com/unicode-org/icu4x |
max_upload_size | |
id | 391251 |
size | 74,694 |
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.
let list_formatter = ListFormatter::try_new_and(
locale!("es").into(),
ListFormatterOptions::default().with_length(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",
);
let list_formatter = ListFormatter::try_new_or(
locale!("th").into(),
ListFormatterOptions::default().with_length(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",);
let list_formatter = ListFormatter::try_new_unit(
locale!("en").into(),
ListFormatterOptions::default().with_length(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.
For more information on development, authorship, contributing etc. please visit ICU4X home page
.