3 releases (unstable)

new 1.0.0-beta1 Aug 5, 2022
0.6.0 May 10, 2022
0.0.1 Apr 29, 2021

#140 in Internationalization (i18n)

Download history 1/week @ 2022-04-21 7/week @ 2022-04-28 19/week @ 2022-05-05 59/week @ 2022-05-12 191/week @ 2022-05-19 101/week @ 2022-05-26 29/week @ 2022-06-02 10/week @ 2022-06-09 17/week @ 2022-06-16 14/week @ 2022-06-23 18/week @ 2022-06-30 15/week @ 2022-07-07 12/week @ 2022-07-14 17/week @ 2022-07-21 17/week @ 2022-07-28

68 downloads per month
Used in 5 crates (3 directly)

Unicode-DFS-2016

2MB
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_with_buffer_provider(
    &icu_testdata::get_provider(),
    &locale!("es").into(),
    ListStyle::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_buffer_provider(
    &icu_testdata::get_provider(),
    &locale!("th").into(),
    ListStyle::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_buffer_provider(
    &icu_testdata::get_provider(),
    &locale!("en").into(),
    ListStyle::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

~3MB
~40K SLoC