From 627a899b2960fae88b52f5d2883be1511c109e33 Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Sun, 18 Sep 2016 19:39:40 +0200 Subject: [PATCH] Added Repository::$plurals --- README.md | 20 ++++++++++++++++++++ lib/Repository.php | 9 +++++++++ tests/RepositoryTest.php | 1 + 3 files changed, 30 insertions(+) diff --git a/README.md b/README.md index d63941b..0efa526 100644 --- a/README.md +++ b/README.md @@ -620,6 +620,26 @@ echo $repository->locales['fr']->format_list([ "Monday", "Tuesday", "Friday" ]); +## Plurals + +Languages have different pluralization rules for numbers that represent zero, one, tow, few, many or +other. ICanBoogie's CLDR makes it easy to find the plural rules for any numeric value: + +```php +plurals->rules_for('fr'); // [ 'one', 'other' ] +$repository->plurals->rules_for('ar'); // [ 'zero', 'one', 'two', 'few', 'many', 'other' ] + +$repository->plurals->rule_for(1.5, 'fr'); // 'one' +$repository->plurals->rule_for(2, 'fr'); // 'other' +$repository->plurals->rule_for(2, 'ar'); // 'twe' +``` + + + + + ---------- diff --git a/lib/Repository.php b/lib/Repository.php index a1b44cd..6b373d7 100644 --- a/lib/Repository.php +++ b/lib/Repository.php @@ -34,6 +34,7 @@ * @property-read CurrencyCollection $currencies * @property-read NumberFormatter $number_formatter * @property-read ListFormatter $list_formatter + * @property-read Plurals $plurals * * @see http://www.unicode.org/repos/cldr-aux/json/24/ */ @@ -102,6 +103,14 @@ protected function lazy_get_list_formatter() return new ListFormatter($this); } + /** + * @return Plurals + */ + protected function lazy_get_plurals() + { + return new Plurals($this->supplemental['plurals']); + } + /** * Initializes the {@link $provider} property. * diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index 48a2ed0..d236f6f 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -38,6 +38,7 @@ public function provide_test_properties_instanceof() [ 'territories', TerritoryCollection::class ], [ 'number_formatter', NumberFormatter::class ], [ 'list_formatter', ListFormatter::class ], + [ 'plurals', Plurals::class ], ]; }