Raku Land

Intl::Format::List

github:alabamenhu

IntlFormatList

A module for formatting lists in a localized manner

To format lists using this module, use the provided sub C:

format-list @list

There are three named options available:

Examples

If your language is set to English…

my @list = <apples oranges bananas>;
say format-list @list;              # 'apples, oranges, and bananas'
say format-list @list, :type<or>;   # 'apples, oranges, or bananas'
say format-list @list, :type<unit>; # 'apples, oranges, bananas'

But if your language is set to Spanish…

my $a = 'manzanas';
my $o = 'naranjas';
my $b = 'plátanos';
say format-list $a, $o, $b;            # 'manzanas, naranjas y plátanos'
say format-list $a, $o, $b, :type<or>; # 'manzanas, naranjas o plátanos'
say format-list $a, $o, $b, :type<unit; # 'manzanas, naranjas y plátanos'

As you can tell, the format-list sub follows the single-argument rule, allowing either a list proper or an inline list of items. All items passed in are stringified.

Version history

© 2020 Matthew Stephen Stuckwisch. Licensed under Artistic License 2.0