9 releases (stable)

1.4.0 Nov 16, 2023
1.3.0 Sep 23, 2023
1.2.0 Apr 14, 2023
1.1.0 Jan 26, 2023
0.0.1 Apr 29, 2021

#357 in Internationalization (i18n)

Download history 11766/week @ 2024-01-10 12253/week @ 2024-01-17 13071/week @ 2024-01-24 18197/week @ 2024-01-31 20326/week @ 2024-02-07 20007/week @ 2024-02-14 18926/week @ 2024-02-21 17443/week @ 2024-02-28 20235/week @ 2024-03-06 20319/week @ 2024-03-13 18751/week @ 2024-03-20 17760/week @ 2024-03-27 17707/week @ 2024-04-03 17452/week @ 2024-04-10 18294/week @ 2024-04-17 14596/week @ 2024-04-24

70,767 downloads per month
Used in 23 crates (6 directly)

Custom license

365KB
6K 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_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.

More Information

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

Dependencies

~5MB
~73K SLoC