PHP library for parsing plural rules specified in the CLDR project. https://www.mediawiki.org/wiki/CLDRPluralRuleParser

Clone this repo:

Branches

  1. 15f1464 build: Updating mediawiki/mediawiki-codesniffer to 43.0.0 by libraryupgrader · 6 weeks ago master
  2. 468678a build: Updating mediawiki/mediawiki-phan-config to 0.14.0 by libraryupgrader · 3 months ago
  3. f138323 build: Upgrade phpunit to 9.6.16 by James D. Forrester · 3 months ago
  4. e787bed build: Switch phan to special library mode by James D. Forrester · 1 year ago
  5. 3a54e39 build: Updating mediawiki/mediawiki-codesniffer to 41.0.0 by libraryupgrader · 1 year, 2 months ago

CLDRPluralRuleParser

CLDRPluralRuleParser is a PHP library for parsing plural rules specified in the CLDR project.

This library does not contain the rules from the CLDR project, you have to get them yourself.

Here is how you use it:

use CLDRPluralRuleParser\Evaluator;

// Example for English
$rules = ['i = 1 and v = 0'];
$forms = ['syntax error', 'syntax errors'];

for ( $i = 0; $i < 3; $i++ ) {
	$index = Evaluator::evaluate( $i, $rules );
	echo "This code has $i {$forms[$index]}\n";
}

// This code has 0 syntax errors
// This code has 1 syntax error
// This code has 2 syntax errors

License

The project is licensed under the GPL license 2 or later.