MediaWiki master
Wikimedia\Leximorph\Provider\PluralRules Class Reference

PluralRules. More...

Public Member Functions

 compileRulesFor (string $code)
 Compiles the plural rules for the specified language code.
 
 getCompiledPluralRules ()
 Returns the compiled plural rules for the current language.
 
 getPluralRules ()
 Returns the raw plural rules for the current language from the XML files.
 
 getPluralRuleType (float $number)
 Finds the plural rule type corresponding to the given number.
 
 getPluralRuleTypes ()
 Returns the plural rule types for the current language from the XML files.
 

Public Attributes

 $evaluatedNumber = ( $number == (int)$number ) ? (int)$number : (string)$number
 
const array PLURAL_FILES
 The paths to the plural rules XML files.
 

Detailed Description

PluralRules.

Provides functionality to load, cache, and compile pluralization rules from XML files.

Since
1.45
Author
Doğu Abaris (abari.nosp@m.s@nu.nosp@m.ll.ne.nosp@m.t)
Note
https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later

Definition at line 25 of file PluralRules.php.

Member Function Documentation

◆ compileRulesFor()

Wikimedia\Leximorph\Provider\PluralRules::compileRulesFor ( string $code)

Compiles the plural rules for the specified language code.

It uses the cached data and returns a compiled version via the CLDR Evaluator. Returns an empty array if the rules are unavailable or if a compilation error occurs.

Parameters
string$codeThe language code.
Since
1.45
Returns
array<int, string> The compiled plural rules.

Definition at line 107 of file PluralRules.php.

◆ getCompiledPluralRules()

Wikimedia\Leximorph\Provider\PluralRules::getCompiledPluralRules ( )

Returns the compiled plural rules for the current language.

It uses the cached raw rules from the XML files and compiles them.

Since
1.45
Returns
array<int, string> The compiled plural rules.

Definition at line 82 of file PluralRules.php.

◆ getPluralRules()

Wikimedia\Leximorph\Provider\PluralRules::getPluralRules ( )

Returns the raw plural rules for the current language from the XML files.

The data is loaded from the cache if available; otherwise, the XML files are read.

Since
1.45
Returns
array<int, string>|null The plural rules, or null if they are not available.

Definition at line 209 of file PluralRules.php.

◆ getPluralRuleType()

Wikimedia\Leximorph\Provider\PluralRules::getPluralRuleType ( float $number)

Finds the plural rule type corresponding to the given number.

For example, if the language is set to Arabic, getPluralRuleType(5) should return 'few'.

Since
1.45
Returns
string The name of the plural rule type (e.g., one, two, few, many).

Definition at line 223 of file PluralRules.php.

◆ getPluralRuleTypes()

Wikimedia\Leximorph\Provider\PluralRules::getPluralRuleTypes ( )

Returns the plural rule types for the current language from the XML files.

The data is loaded from the cache if available; otherwise, the XML files are read.

Since
1.45
Returns
array<int, string> The plural rule types.

Definition at line 238 of file PluralRules.php.

Member Data Documentation

◆ $evaluatedNumber

Wikimedia\Leximorph\Provider\PluralRules::$evaluatedNumber = ( $number == (int)$number ) ? (int)$number : (string)$number

Definition at line 69 of file PluralRules.php.

◆ PLURAL_FILES

const array Wikimedia\Leximorph\Provider\PluralRules::PLURAL_FILES
Initial value:
= [
__DIR__ . '/../data/plurals.xml',
__DIR__ . '/../data/plurals-mediawiki.xml',
]

The paths to the plural rules XML files.

Definition at line 30 of file PluralRules.php.


The documentation for this class was generated from the following file: