1) return $str; $key = 'singular_'.$str.$count; if (isset(inflector::$cache[$key])) return inflector::$cache[$key]; if (inflector::uncountable($str)) return inflector::$cache[$key] = $str; if (empty(inflector::$irregular)) { inflector::$irregular = Kohana::config('inflector.irregular'); } if ($irregular = array_search($str, inflector::$irregular)) { $str = $irregular; } elseif (preg_match('/[sxz]es$/', $str) OR preg_match('/[^aeioudgkprt]hes$/', $str)) { $str = substr($str, 0, -2); } elseif (preg_match('/[^aeiou]ies$/', $str)) { $str = substr($str, 0, -3).'y'; } elseif (substr($str, -1) === 's' AND substr($str, -2) !== 'ss') { $str = substr($str, 0, -1); } return inflector::$cache[$key] = $str; } public static function plural($str, $count = NULL) { $str = strtolower(trim($str)); if (is_string($count)) { $count = (int) $count; } if ($count === 1) return $str; $key = 'plural_'.$str.$count; if (isset(inflector::$cache[$key])) return inflector::$cache[$key]; if (inflector::uncountable($str)) return inflector::$cache[$key] = $str; if (empty(inflector::$irregular)) { inflector::$irregular = Kohana::config('inflector.irregular'); } if (isset(inflector::$irregular[$str])) { $str = inflector::$irregular[$str]; } elseif (preg_match('/[sxz]$/', $str) OR preg_match('/[^aeioudgkprt]h$/', $str)) { $str .= 'es'; } elseif (preg_match('/[^aeiou]y$/', $str)) { $str = substr_replace($str, 'ies', -1); } else { $str .= 's'; } return inflector::$cache[$key] = $str; } public static function camelize($str) { $str = 'x'.strtolower(trim($str)); $str = ucwords(preg_replace('/[\s_]+/', ' ', $str)); return substr(str_replace(' ', '', $str), 1); } public static function underscore($str) { return preg_replace('/\s+/', '_', trim($str)); } public static function humanize($str) { return preg_replace('/[_-]+/', ' ', trim($str)); } }