Commit 96c6f54d authored by Ghislain Loas's avatar Ghislain Loas

dev #56034 endle english plural

parent 57fb2c7f
...@@ -29,20 +29,18 @@ THE SOFTWARE. ...@@ -29,20 +29,18 @@ THE SOFTWARE.
* Used to generate on-the-fly method names and attributes for Storm_Model_Abstract mainly * Used to generate on-the-fly method names and attributes for Storm_Model_Abstract mainly
*/ */
class Storm_Inflector { class Storm_Inflector {
protected static $_singular = [ protected static $_singular = ['/eux$/i' => 'eu',
'/eux$/i' => 'eu', '/aux$/i' => 'al',
'/aux$/i' => 'al', '/ies$/i' => 'y',
'/s$/i' => '' '/s$/i' => ''];
];
protected static $_plural = ['/eu$/i'=> 'eux',
protected static $_plural = [ '/al$/i'=> 'aux',
'/eu$/i'=> 'eux', '/s$/i'=> 's',
'/al$/i'=> 'aux', '/$/'=> 's',
'/s$/i'=> 's', '/y$/i' => 'ies'];
'/$/'=> 's'
]; protected static
protected static
$_uncountable = ['avis'], $_uncountable = ['avis'],
$_underscorize_cache = [], $_underscorize_cache = [],
$_camelize_cache = []; $_camelize_cache = [];
...@@ -51,14 +49,14 @@ class Storm_Inflector { ...@@ -51,14 +49,14 @@ class Storm_Inflector {
/** /**
* Returns given_word as CamelCased * Returns given_word as CamelCased
* *
* @param string $word * @param string $word
* @return string * @return string
*/ */
public static function camelize($word) { public static function camelize($word) {
if (isset(self::$_camelize_cache[$word])) if (isset(self::$_camelize_cache[$word]))
return self::$_camelize_cache[$word]; return self::$_camelize_cache[$word];
return self::$_camelize_cache[$word] = str_replace(' ', return self::$_camelize_cache[$word] = str_replace(' ',
'', '',
ucwords(preg_replace('/[^A-Z^a-z^0-9]+/',' ',strtolower($word)))); ucwords(preg_replace('/[^A-Z^a-z^0-9]+/',' ',strtolower($word))));
} }
...@@ -66,14 +64,14 @@ class Storm_Inflector { ...@@ -66,14 +64,14 @@ class Storm_Inflector {
/** /**
* Returns GivenWord as variable_name_with_underscores * Returns GivenWord as variable_name_with_underscores
* *
* @param string $word * @param string $word
* @return string * @return string
*/ */
public static function underscorize($word) { public static function underscorize($word) {
if (isset(self::$_underscorize_cache[$word])) if (isset(self::$_underscorize_cache[$word]))
return self::$_underscorize_cache[$word]; return self::$_underscorize_cache[$word];
return self::$_underscorize_cache[$word] = strtolower( return self::$_underscorize_cache[$word] = strtolower(
preg_replace(['/([A-Z])([A-Z])/', '/([^A-Z_])([A-Z])/'], preg_replace(['/([A-Z])([A-Z])/', '/([^A-Z_])([A-Z])/'],
'$1_$2', '$1_$2',
$word) $word)
); );
...@@ -88,12 +86,12 @@ class Storm_Inflector { ...@@ -88,12 +86,12 @@ class Storm_Inflector {
if (self::_isUncountable($word)) if (self::_isUncountable($word))
return $word; return $word;
foreach (self::$_singular as $rule => $replacement) { foreach (self::$_singular as $rule => $replacement) {
if ($word != ($singular = preg_replace($rule, $replacement, $word))) if ($word != ($singular = preg_replace($rule, $replacement, $word)))
return $singular; return $singular;
} }
return $word; return $word;
} }
...@@ -105,7 +103,7 @@ class Storm_Inflector { ...@@ -105,7 +103,7 @@ class Storm_Inflector {
public static function pluralize($word) { public static function pluralize($word) {
if (self::_isUncountable($word)) if (self::_isUncountable($word))
return $word; return $word;
foreach (self::$_plural as $rule => $replacement) { foreach (self::$_plural as $rule => $replacement) {
if ($word !== ($plural = preg_replace($rule, $replacement, $word))) if ($word !== ($plural = preg_replace($rule, $replacement, $word)))
return $plural; return $plural;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment