PHP Class Neos\Flow\I18n\Cldr\Reader\PluralsReader

There are a few similar words used in plurals.xml file of CLDR used by this class. Following naming convention is used in the code (a name of corresponding tag from xml file is provided in brackets, if any): - ruleset: a set of plural rules for a locale [pluralRules] - rule: a rule for one of the forms: zero, one, two, few, many [pluralRule] - subrule: one of the conditions of rule. One rule can have many conditions joined with "and" or "or" logical operator.
See also: http://www.unicode.org/reports/tr35/#Language_Plural_Rules
Afficher le fichier Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Свойство Type Description
$cache Neos\Cache\Frontend\VariableFrontend
$cldrRepository Neos\Flow\I18n\Cldr\CldrRepository
$rulesets array One ruleset contains one or more rules (at most 5, one for every plural form - zero, one, two, few, many - a rule 'other' is implicit). There can also be NULL ruleset, used by languages which don't have plurals. A rule is an array with following elements: 'modulo' => $x | FALSE, 'condition' => array(0 => 'conditionName', 1 => $x, 2 => $y), 'logicalOperator' => 'and' | 'or' | FALSE Legend: - if 'modulo' key has an integer value, tested variable (call it $n) has to be replaced with the remainder of division of $n by $x. Otherwise unchanged $n is used for conditional test. - 'condition' is an indexed array where first element is a name of test condition (one of: is, isnot, in, notin, within, notwithin). Second element is a value to compare $n with. Third element is optional, and is used only for tests where range is needed (last 4 from the list above) - 'logicalOperator' represents a logical operation to be done with next subrule in chain. If current subrule is a last one (or only one), this element is set to FALSE.
$rulesetsIndices array An associative array holding information which ruleset is used by given locale. One or more locales can use the same ruleset.

Méthodes publiques

Méthode Description
getPluralForm ( mixed $quantity, Locale $locale ) : string Returns matching plural form based on $quantity and $locale provided.
getPluralForms ( Locale $locale ) : array Returns array of plural forms available for particular locale.
initializeObject ( ) : void Constructs the reader, loading parsed data from cache if available.
injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void Injects the Flow_I18n_Cldr_Reader_PluralsReader cache
injectCldrRepository ( CldrRepository $repository ) : void

Méthodes protégées

Méthode Description
generateRulesets ( ) : void Generates an internal representation of plural rules which can be found in plurals.xml CLDR file.
parseRule ( string $rule ) : array Parses a plural rule from CLDR.

Method Details

generateRulesets() protected méthode

The properties $rulesets and $rulesetsIndices should be empty before running this method.
See also: PluralsReader::$rulesets
protected generateRulesets ( ) : void
Résultat void

getPluralForm() public méthode

Plural form is one of following: zero, one, two, few, many, other. Last one (other) is returned when number provided doesn't match any of the rules, or there is no rules for given locale.
public getPluralForm ( mixed $quantity, Locale $locale ) : string
$quantity mixed A number to find plural form for (float or int)
$locale Neos\Flow\I18n\Locale
Résultat string One of plural form constants

getPluralForms() public méthode

Returns array of plural forms available for particular locale.
public getPluralForms ( Locale $locale ) : array
$locale Neos\Flow\I18n\Locale Locale to return plural forms for
Résultat array Plural forms' names (one, zero, two, few, many, other) available for language set in this model

initializeObject() public méthode

Constructs the reader, loading parsed data from cache if available.
public initializeObject ( ) : void
Résultat void

injectCache() public méthode

Injects the Flow_I18n_Cldr_Reader_PluralsReader cache
public injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void
$cache Neos\Cache\Frontend\VariableFrontend
Résultat void

injectCldrRepository() public méthode

public injectCldrRepository ( CldrRepository $repository ) : void
$repository Neos\Flow\I18n\Cldr\CldrRepository
Résultat void

parseRule() protected méthode

A plural rule in CLDR is a string with one or more test conditions, with 'and' or 'or' logical operators between them. Whole expression can look like this: n is 0 OR n is not 1 AND n mod 100 in 1..19 As CLDR documentation says, following test conditions can be used: - is x, is not x: $n is (not) equal $x - in x..y, not in x..y: $n is (not) one of integers from range <$x, $y> - within x..y, not within x..y: $n is (not) any number from range <$x, $y> Where $n can be a number (also float) as is, or a result of $n mod $x. Array returned follows simple internal format (see documentation for $rulesets property for details).
protected parseRule ( string $rule ) : array
$rule string
Résultat array Parsed rule

Property Details

$cache protected_oe property

protected VariableFrontend,Neos\Cache\Frontend $cache
Résultat Neos\Cache\Frontend\VariableFrontend

$cldrRepository protected_oe property

protected CldrRepository,Neos\Flow\I18n\Cldr $cldrRepository
Résultat Neos\Flow\I18n\Cldr\CldrRepository

$rulesets protected_oe property

One ruleset contains one or more rules (at most 5, one for every plural form - zero, one, two, few, many - a rule 'other' is implicit). There can also be NULL ruleset, used by languages which don't have plurals. A rule is an array with following elements: 'modulo' => $x | FALSE, 'condition' => array(0 => 'conditionName', 1 => $x, 2 => $y), 'logicalOperator' => 'and' | 'or' | FALSE Legend: - if 'modulo' key has an integer value, tested variable (call it $n) has to be replaced with the remainder of division of $n by $x. Otherwise unchanged $n is used for conditional test. - 'condition' is an indexed array where first element is a name of test condition (one of: is, isnot, in, notin, within, notwithin). Second element is a value to compare $n with. Third element is optional, and is used only for tests where range is needed (last 4 from the list above) - 'logicalOperator' represents a logical operation to be done with next subrule in chain. If current subrule is a last one (or only one), this element is set to FALSE.
protected array $rulesets
Résultat array

$rulesetsIndices protected_oe property

An associative array holding information which ruleset is used by given locale. One or more locales can use the same ruleset.
protected array $rulesetsIndices
Résultat array