Skip to content

Commit

Permalink
Added Repository::$plurals
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 18, 2016
1 parent 0c0bdd9 commit 627a899
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php

$repository->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'
```





----------


Expand Down
9 changes: 9 additions & 0 deletions lib/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function provide_test_properties_instanceof()
[ 'territories', TerritoryCollection::class ],
[ 'number_formatter', NumberFormatter::class ],
[ 'list_formatter', ListFormatter::class ],
[ 'plurals', Plurals::class ],

];
}
Expand Down

0 comments on commit 627a899

Please sign in to comment.