NAME

Locale::Unicode::RBNF::PluralRules - CLDR plural rules evaluator

SYNOPSIS

use Locale::Unicode::RBNF::PluralRules;
my $st;
my $rules = Locale::Unicode::RBNF::PluralRules->new( $cldr->plural_rules( 'fr', 'cardinal' ), \$st );
die( $st ) if( $st );
say $rules->select( 2 );
# other

VERSION

v0.1.0

DESCRIPTION

Internal module. It evaluates the CLDR cardinal and ordinal plural rules used by the $(cardinal,...)$ and $(ordinal,...)$ constructs of rule-based number formats.

CONSTRUCTOR

new

my $rules = Locale::Unicode::RBNF::PluralRules->new( [ [ one => 'i = 0,1 @integer 0, 1' ], [ other => '' ] ], \$st );

Takes an array reference of array references [ keyword, condition ], in the CLDR order, as returned by "plural_rules" in Locale::Unicode::RBNF::CLDR, and a scalar reference that receives an error status, and returns a new object.

The samples, introduced by @, are ignored, and so is the other rule, since other is what remains when no other rule matches. The operands n, i, v, w, f, t, c and e, the % or mod modulus, and the relations =, !=, is, is not, in, not in, within and not within are supported.

The object is always returned. If a condition cannot be parsed, the status is set to a U_PARSE_ERROR message, and the caller must check it.

METHODS

keywords

my $keywords = $rules->keywords;
# [ 'one', 'many', 'other' ]

Returns an array reference of the plural keywords, in the order of the rules, followed by other.

select

my $keyword = $rules->select( 1 );
my $keyword = $rules->select( '1.50' );

Returns the plural keyword of the first rule whose condition matches the number, or other if none does.

The number can be given as a decimal string, so that visible trailing zeros, such as in 1.50, are taken into account by the operands v, w, f and t. An exponent, such as in 1.2e3 or 1.2c3, is taken into account by the operands c and e.

SEE ALSO

Locale::Unicode::RBNF, Locale::Unicode::RBNF::PluralFormat

AUTHOR

Jacques Deguest <jack@deguest.jp>

COPYRIGHT & LICENSE

Copyright(c) 2026 DEGUEST Pte. Ltd.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.