12 releases (7 stable)

2.0.0-beta2 Feb 26, 2025
2.0.0-beta1 Nov 23, 2024
1.5.0 May 28, 2024
1.4.0 Nov 16, 2023
0.0.1 Apr 29, 2021

#7 in Internationalization (i18n)

Download history 27344/week @ 2024-11-17 25586/week @ 2024-11-24 27815/week @ 2024-12-01 29465/week @ 2024-12-08 28563/week @ 2024-12-15 21141/week @ 2024-12-22 22682/week @ 2024-12-29 27942/week @ 2025-01-05 26741/week @ 2025-01-12 25541/week @ 2025-01-19 21702/week @ 2025-01-26 23950/week @ 2025-02-02 23950/week @ 2025-02-09 22444/week @ 2025-02-16 21484/week @ 2025-02-23 20558/week @ 2025-03-02

90,654 downloads per month
Used in 41 crates (9 directly)

Unicode-3.0

1MB
15K SLoC

icu_list crates.io

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(
    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",
);

Formatting or lists in Thai

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",);

Formatting unit lists in English

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.

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~2–3.5MB
~55K SLoC