Locale-Utils-PluralForms
view release on metacpan or search on metacpan
lib/Locale/Utils/PluralForms.pm view on Meta::CPAN
=head1 NAME
Locale::Utils::PluralForms - Utils to use plural forms
=head1 VERSION
0.003
=head1 SYNOPSIS
use Locale::Utils::PluralForms;
my $obj = Locale::Utils::PluralForms->new;
Data downloaded from web
$obj = Locale::Utils::PluralForms->new(
language => 'en_GB', # fallbacks from given en_GB to en
);
Data of given data structure
$obj = Locale::Utils::PluralForms->new(
all_plural_forms => {
'en' => {
english_name => 'English',
plural_forms => 'nplurals=2; plural=(n != 1)',
},
# next languages
},
);
Getter
my $language = $obj->language;
my $all_plural_forms = $obj->all_plural_forms;
my $plural_forms = $obj->plural_forms;
my $nplurals = $obj->nplurals;
my $plural_code = $obj->plural_code;
my $plural = $obj->plural_code->($number);
=head1 DESCRIPTION
=head2 Find plural forms for the language
This module helps to find the plural forms for all languages.
It downloads the plural forms for all languages from web.
Then it stores the extracted data
into a data structure named "all_plural_forms".
It is possible to fill that data structure
before method "language" is called first time
or to cache after first method call "language".
=head2 "plural" as subroutine
In the header of a PO- or MO-File
is an entry is called "Plural-Forms".
How many plural forms the language has, is described there in "nplurals".
The second Information in "Plural-Forms" describes as a formula,
how to choose the "plural".
This module compiles plural forms
to a code references in a secure way.
=head1 SUBROUTINES/METHODS
=head2 Find plural forms for the language
=head3 method language
Set the language to switch to the plural forms of that language.
"plural_forms" is set then and "nplurals" and "plural_code" will be calculated.
$obj->language('de_AT'); # A fallback finds plural forms of language de
# because de_AT is not different.
Read the language back.
$obj->language eq 'de_AT';
=head3 method all_plural_forms
Set the data structure.
$obj->all_plural_forms({
'de' => {
english_name => 'German',
plural_forms => 'nplurals=2; plural=(n != 1)',
},
# next languages
});
Read the data structure back.
my $hash_ref = $obj->all_plural_forms;
=head2 executable plural forms
=head3 method plural_forms
Set "plural_forms" if no "language" is set.
After that "nplurals" and "plural_code" will be calculated in a safe way.
$obj->plural_forms('nplurals=1; plural=0');
Or read it back.
my $plural_forms = $obj->plural_forms;
=head3 method nplurals
This method get back the calculated count of plurals.
If no "language" and no "plural_forms" is set,
the defaults for "nplurals" is:
my $count = $obj->nplurals # returns: 1
There is no public setter for "nplurals"
( run in 1.451 second using v1.01-cache-2.11-cpan-39bf76dae61 )