PHP code example of polyglot / plural-detector-registry-cardinal-cldr
1. Go to this page and download the library: Download polyglot/plural-detector-registry-cardinal-cldr library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
polyglot / plural-detector-registry-cardinal-cldr example snippets
$registry = new \Polyglot\CldrCardinalPluralDetectorRegistry\CldrCardinalPluralDetectorRegistry();
$en = $registry->get('en_US'); // or $registry->get('en')
$en->getAllowedCategories(); // returns ["one", "other"]
$en->detect(1); // returns "one"
$en->detect(2); // returns "other"
$ar = $registry->get('ar');
$en->getAllowedCategories(); // returns ["zero", "one", "two", "few", "many", "other"]
$en->detect(0); // returns "zero"
$en->detect(1); // returns "one"
$en->detect(2); // returns "two"
$en->detect(rand(3, 10) + 100 * rand(0, 100)); // returns "few"
$en->detect(rand(11, 99) + 100 * rand(0, 100)); // returns "many"
$en->detect(rand(10, 99) / 10); // returns "other"
$registry->get('unknown'); // throws \Polyglot\Contract\PluralDetectorRegistry\Exception\LocaleNotSupported