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

dev #56034 endle english plural

parent 57fb2c7f
......@@ -29,20 +29,18 @@ THE SOFTWARE.
* Used to generate on-the-fly method names and attributes for Storm_Model_Abstract mainly
*/
class Storm_Inflector {
protected static $_singular = [
'/eux$/i' => 'eu',
'/aux$/i' => 'al',
'/s$/i' => ''
];
protected static $_plural = [
'/eu$/i'=> 'eux',
'/al$/i'=> 'aux',
'/s$/i'=> 's',
'/$/'=> 's'
];
protected static
protected static $_singular = ['/eux$/i' => 'eu',
'/aux$/i' => 'al',
'/ies$/i' => 'y',
'/s$/i' => ''];
protected static $_plural = ['/eu$/i'=> 'eux',
'/al$/i'=> 'aux',
'/s$/i'=> 's',
'/$/'=> 's',
'/y$/i' => 'ies'];
protected static
$_uncountable = ['avis'],
$_underscorize_cache = [],
$_camelize_cache = [];
......@@ -51,14 +49,14 @@ class Storm_Inflector {
/**
* Returns given_word as CamelCased
*
* @param string $word
* @param string $word
* @return string
*/
public static function camelize($word) {
if (isset(self::$_camelize_cache[$word]))
return self::$_camelize_cache[$word];
return self::$_camelize_cache[$word] = str_replace(' ',
'',
'',
ucwords(preg_replace('/[^A-Z^a-z^0-9]+/',' ',strtolower($word))));
}
......@@ -66,14 +64,14 @@ class Storm_Inflector {
/**
* Returns GivenWord as variable_name_with_underscores
*
* @param string $word
* @param string $word
* @return string
*/
public static function underscorize($word) {
if (isset(self::$_underscorize_cache[$word]))
return self::$_underscorize_cache[$word];
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',
$word)
);
......@@ -88,12 +86,12 @@ class Storm_Inflector {
if (self::_isUncountable($word))
return $word;
foreach (self::$_singular as $rule => $replacement) {
if ($word != ($singular = preg_replace($rule, $replacement, $word)))
return $singular;
}
return $word;
}
......@@ -105,7 +103,7 @@ class Storm_Inflector {
public static function pluralize($word) {
if (self::_isUncountable($word))
return $word;
foreach (self::$_plural as $rule => $replacement) {
if ($word !== ($plural = preg_replace($rule, $replacement, $word)))
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