Intl::Number::Plural

A module to determine the grammatical count of a number

IntlNumberPlural

A number to determine the plural count category of a number for use in localization contexts

Warning: The name may change in the near-ish future (mid 2021) to be cohesive with other modules. If it changes, I will continue to provide under the current name for at least one year.

To use:

use Intl::Number::Plural

                 # English  Arabic  Russian
plural-count 0;  # other    zero    many
plural-count 1;  # one      one     one
plural-count 2;  # other    two     few
plural-count 3;  # other    few     few
plural-count 6;  # other    few     many

There are six strings that can be returned by the function: zero, one, two, few, many, and other. Other is the default and is used for all values in languages that do not have grammatical number. Note that (as evidenced by the above table), the labels don't always correspond to what one might intuitively think. Consequently, this is a module generally oriented towards makes of localization frameworks, and less so towards end-users.

The plural-count sub currently takes one or two positional arguments:

  • number (required)The number whose count is to be determined.

  • from, toThe count is calculated for a range (from .. to).

There are two optional named parameters

  • :languageThe language to be used in determining the count. Defaults to user-language.

  • :typeAcceptable values are cardinal and ordinal, defaults to cardinal. Some languages behave differently for these two types of numbers. Ignored for range calculations which always use cardinal

Dependencies

  • Intl::CLDRHouses the data for calculating the counts

  • Intl::UserLanguageDetermines the default language when not provided

Todo

  • Use Intl::CLDR enums once available.

  • Add tests for major languages

Version History

  • v0.5.4

    • Fixed a small bug (mod ā†’ % for CLDR's mod)

  • v0.5.3

    • Updated CLDR reference (was .plurals in beta, now is .grammar.plurals)

  • v0.5.2

    • Added support for ranged

  • v0.5.1

    • Initial release as separate module

  • v0.1 ā€“ v0.5

    • Included as a part of Intl::CLDR

License and Copyright

Ā© 2020-2021 Matthew Stephen Stuckwisch. Licensed under the Artistic License 2.0.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.