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

Clone this repo:
  1. 108d569 Add evaluations and test cases for c and e operands by Nemoralis · 4 weeks ago master v3.0.2
  2. 8c225fd build: Updating mediawiki/mediawiki-codesniffer to 51.0.0 by libraryupgrader · 2 months ago v3.0.1
  3. 4153ea9 Add c and e operands by NMW03 · 2 months ago
  4. 050e337 Declare strict types on all php files by Umherirrender · 3 months ago
  5. adefc06 build: Updating mediawiki/mediawiki-phan-config to 0.20.0 by libraryupgrader · 4 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.