5 releases (2 stable)

1.1.0 Jan 26, 2023
1.0.0 Sep 27, 2022
1.0.0-beta1 Aug 5, 2022
0.6.0 May 10, 2022
0.0.1 Apr 29, 2021

#7 in #cldr

Download history 5581/week @ 2022-11-27 7402/week @ 2022-12-04 6449/week @ 2022-12-11 5709/week @ 2022-12-18 5919/week @ 2022-12-25 6180/week @ 2023-01-01 7191/week @ 2023-01-08 7138/week @ 2023-01-15 7092/week @ 2023-01-22 8114/week @ 2023-01-29 7580/week @ 2023-02-05 8982/week @ 2023-02-12 7910/week @ 2023-02-19 8738/week @ 2023-02-26 9787/week @ 2023-03-05 9474/week @ 2023-03-12

37,151 downloads per month
Used in 12 crates (5 directly)

Unicode-DFS-2016

270KB
4.5K 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_unstable(
    &icu_testdata::unstable(),
    &locale!("es").into(),
    ListLength::Wide,
)
.expect("Data should load successfully");

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_unstable(
    &icu_testdata::unstable(),
    &locale!("th").into(),
    ListLength::Short,
)
.expect("Data should load successfully");

// 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_unstable(
    &icu_testdata::unstable(),
    &locale!("en").into(),
    ListLength::Wide,
)
.expect("Data should load successfully");

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
~63K SLoC