Last active
July 4, 2017 13:26
-
-
Save briankip/625e5434af728487594183eff6009811 to your computer and use it in GitHub Desktop.
from Illuminate\Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Doctrine\Common\Inflector\Inflector; | |
class Pluralizer | |
{ | |
/** | |
* Uncountable word forms. | |
* | |
* @var array | |
*/ | |
public static $uncountable = [ | |
'audio', | |
'bison', | |
'chassis', | |
'compensation', | |
'coreopsis', | |
'data', | |
'deer', | |
'education', | |
'emoji', | |
'equipment', | |
'evidence', | |
'feedback', | |
'fish', | |
'furniture', | |
'gold', | |
'information', | |
'jedi', | |
'knowledge', | |
'love', | |
'metadata', | |
'money', | |
'moose', | |
'nutrition', | |
'offspring', | |
'plankton', | |
'pokemon', | |
'police', | |
'rain', | |
'rice', | |
'series', | |
'sheep', | |
'species', | |
'swine', | |
'traffic', | |
'wheat', | |
]; | |
/** | |
* Get the plural form of an English word. | |
* | |
* @param string $value | |
* @param int $count | |
* @return string | |
*/ | |
public static function plural($value, $count = 2) | |
{ | |
if ((int) $count === 1 || static::uncountable($value)) { | |
return $value; | |
} | |
$plural = Inflector::pluralize($value); | |
return static::matchCase($plural, $value); | |
} | |
/** | |
* Get the singular form of an English word. | |
* | |
* @param string $value | |
* @return string | |
*/ | |
public static function singular($value) | |
{ | |
$singular = Inflector::singularize($value); | |
return static::matchCase($singular, $value); | |
} | |
/** | |
* Determine if the given value is uncountable. | |
* | |
* @param string $value | |
* @return bool | |
*/ | |
protected static function uncountable($value) | |
{ | |
return in_array(strtolower($value), static::$uncountable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment