Added in automatic inflection on english strings. Non-english strings may be added to the "irregular" array.
This commit is contained in:
@@ -2,6 +2,13 @@
|
||||
|
||||
class Str {
|
||||
|
||||
/**
|
||||
* The pluralizer instance.
|
||||
*
|
||||
* @var Pluralizer
|
||||
*/
|
||||
public static $pluralizer;
|
||||
|
||||
/**
|
||||
* Get the default string encoding for the application.
|
||||
*
|
||||
@@ -154,25 +161,17 @@ class Str {
|
||||
/**
|
||||
* Get the singular form of the given word.
|
||||
*
|
||||
* The word should be defined in the "strings" configuration file.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function singular($value)
|
||||
{
|
||||
$inflection = Config::get('strings.inflection');
|
||||
|
||||
$singular = array_get(array_flip($inflection), strtolower($value), $value);
|
||||
|
||||
return (ctype_upper($value[0])) ? static::title($singular) : $singular;
|
||||
return static::pluralizer()->singular($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plural form of the given word.
|
||||
*
|
||||
* The word should be defined in the "strings" configuration file.
|
||||
*
|
||||
* <code>
|
||||
* // Returns the plural form of "child"
|
||||
* $plural = Str::plural('child', 10);
|
||||
@@ -187,11 +186,19 @@ class Str {
|
||||
*/
|
||||
public static function plural($value, $count = 2)
|
||||
{
|
||||
if ((int) $count == 1) return $value;
|
||||
return static::pluralizer()->plural($value, $count);
|
||||
}
|
||||
|
||||
$plural = array_get(Config::get('strings.inflection'), strtolower($value), $value);
|
||||
/**
|
||||
* Get the pluralizer instance.
|
||||
*
|
||||
* @return Pluralizer
|
||||
*/
|
||||
protected static function pluralizer()
|
||||
{
|
||||
$config = Config::get('strings');
|
||||
|
||||
return (ctype_upper($value[0])) ? static::title($plural) : $plural;
|
||||
return static::$pluralizer ?: static::$pluralizer = new Pluralizer($config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user