Example #1
0
 /**
  * Makes a singular word plural.
  *
  * @param string $str word to pluralize
  * @param int $count
  * @return string
  */
 public static function plural($str, $count = NULL)
 {
     // Remove garbage
     $str = strtolower(trim($str));
     if (is_string($count)) {
         // Convert to integer when using a digit string
         $count = (int) $count;
     }
     // Do nothing with singular
     if ($count === 1) {
         return $str;
     }
     // Cache key name
     $key = 'plural_' . $str . $count;
     if (isset(self::$cache[$key])) {
         return self::$cache[$key];
     }
     if (self::uncountable($str)) {
         return self::$cache[$key] = $str;
     }
     if (empty(self::$irregular)) {
         // Cache irregular words
         self::$irregular = AetherDatabaseConfig::retrieve('inflector.irregular');
     }
     if (isset(self::$irregular[$str])) {
         $str = self::$irregular[$str];
     } elseif (preg_match('/[sxz]$/', $str) || preg_match('/[^aeioudgkprt]h$/', $str)) {
         $str .= 'es';
     } elseif (preg_match('/[^aeiou]y$/', $str)) {
         // Change "y" to "ies"
         $str = substr_replace($str, 'ies', -1);
     } else {
         $str .= 's';
     }
     // Set the cache and return
     return self::$cache[$key] = $str;
 }
Example #2
0
 /**
  * Makes a singular word plural.
  *
  *     echo Inflector::plural('fish'); // "fish", uncountable
  *     echo Inflector::plural('cat');  // "cats"
  *
  * You can also provide the count to make inflection more intelligent.
  * In this case, it will only return the plural value if the count is
  * not one.
  *
  *     echo Inflector::singular('cats', 3); // "cats"
  *
  * [!!] Special inflections are defined in `config/inflector.php`.
  *
  * @param   string  $str   word to pluralize
  * @param   integer $count count of thing
  *
  * @return  string
  * @uses    Inflector::uncountable
  */
 public static function plural($str, $count = null)
 {
     // $count should always be a float
     $count = $count === null ? 0.0 : (double) $count;
     // Do nothing with singular
     if ($count == 1) {
         return $str;
     }
     // Remove garbage
     $str = trim($str);
     // Cache key name
     $key = 'plural_' . $str . $count;
     // Check uppercase
     $is_uppercase = ctype_upper($str);
     if (isset(Inflector::$cache[$key])) {
         return Inflector::$cache[$key];
     }
     if (Inflector::uncountable($str)) {
         return Inflector::$cache[$key] = $str;
     }
     if (empty(Inflector::$irregular)) {
         // Cache irregular words
         Inflector::$irregular = Kohana::$config->load('inflector')->irregular;
     }
     if (isset(Inflector::$irregular[$str])) {
         $str = Inflector::$irregular[$str];
     } elseif (in_array($str, Inflector::$irregular)) {
         // Do nothing
     } elseif (preg_match('/[sxz]$/', $str) or preg_match('/[^aeioudgkprt]h$/', $str)) {
         $str .= 'es';
     } elseif (preg_match('/[^aeiou]y$/', $str)) {
         // Change "y" to "ies"
         $str = substr_replace($str, 'ies', -1);
     } else {
         $str .= 's';
     }
     // Convert to uppercase if necessary
     if ($is_uppercase) {
         $str = strtoupper($str);
     }
     // Set the cache and return
     return Inflector::$cache[$key] = $str;
 }
Example #3
0
 /**
  * Makes a singular word plural.
  *
  *     echo Inflector::plural('fish'); // "fish", uncountable
  *     echo Inflector::plural('cat');  // "cats"
  *
  * You can also provide the count to make inflection more intelligent.
  * In this case, it will only return the plural value if the count is
  * not one.
  *
  *     echo Inflector::singular('cats', 3); // "cats"
  *
  * [!!] Special inflections are defined in `config/inflector.php`.
  *
  * @param   string   word to pluralize
  * @param   integer  count of thing
  * @return  string
  * @uses    Inflector::uncountable
  */
 public static function plural($str, $count = NULL)
 {
     // $count should always be a float
     $count = $count === NULL ? 0.0 : (double) $count;
     // Do nothing with singular
     if ($count == 1) {
         return $str;
     }
     // Remove garbage
     $str = strtolower(trim($str));
     // Cache key name
     $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)) {
         // Cache irregular words
         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)) {
         // Change "y" to "ies"
         $str = substr_replace($str, 'ies', -1);
     } else {
         $str .= 's';
     }
     // Set the cache and return
     return Inflector::$cache[$key] = $str;
 }
Example #4
0
 /**
  * Clears all inflection rules.
  *
  * @param string|boolean $lang The language name to reset or `true` to reset all even defaults.
  */
 public static function reset($lang = null)
 {
     if (is_string($lang)) {
         unset(static::$_singular[$lang]);
         unset(static::$_plural[$lang]);
         return;
     }
     static::$_singular = [];
     static::$_plural = [];
     if ($lang === true) {
         return;
     }
     /**
      * Initilalize the class with english inflector rules.
      */
     Inflector::singular('/([^s])s$/i', '\\1', 'default');
     Inflector::plural('/([^s])$/i', '\\1s', 'default');
     Inflector::singular('/(x|z|s|ss|ch|sh)es$/i', '\\1', 'default');
     Inflector::plural('/(x|z|ss|ch|sh)$/i', '\\1es', 'default');
     Inflector::singular('/ies$/i', 'y', 'default');
     Inflector::plural('/([^aeiouy]|qu)y$/i', '\\1ies', 'default');
     Inflector::plural('/(meta|data)$/i', '\\1', 'default');
     Inflector::irregular('child', 'children', 'default');
     Inflector::irregular('equipment', 'equipment', 'default');
     Inflector::irregular('information', 'information', 'default');
     Inflector::irregular('man', 'men', 'default');
     Inflector::irregular('news', 'news', 'default');
     Inflector::irregular('person', 'people', 'default');
     Inflector::irregular('woman', 'women', 'default');
     /**
      * Warning, using an "exhastive" list of rules will slow
      * down all singularizations/pluralizations generations.
      * So it may be preferable to only add the ones you are actually needed.
      *
      * Anyhow bellow a list english exceptions which are not covered by the above rules.
      */
     // Inflector::irregular('advice', 'advice', 'default');
     // Inflector::irregular('aircraft', 'aircraft', 'default');
     // Inflector::irregular('alias', 'aliases', 'default');
     // Inflector::irregular('alga', 'algae', 'default');
     // Inflector::irregular('alumna', 'alumnae', 'default');
     // Inflector::irregular('alumnus', 'alumni', 'default');
     // Inflector::irregular('analysis', 'analyses', 'default');
     // Inflector::irregular('antenna', 'antennae', 'default');
     // Inflector::irregular('automaton', 'automata', 'default');
     // Inflector::irregular('axis', 'axes', 'default');
     // Inflector::irregular('bacillus', 'bacilli', 'default');
     // Inflector::irregular('bacterium', 'bacteria', 'default');
     // Inflector::irregular('barracks', 'barracks', 'default');
     // Inflector::irregular('basis', 'bases', 'default');
     // Inflector::irregular('bellows', 'bellows', 'default');
     // Inflector::irregular('buffalo', 'buffaloes', 'default');
     // Inflector::irregular('bus', 'buses', 'default');
     // Inflector::irregular('bison', 'bison', 'default');
     // Inflector::irregular('cactus', 'cacti', 'default');
     // Inflector::irregular('cafe', 'cafes', 'default');
     // Inflector::irregular('calf', 'calves', 'default');
     // Inflector::irregular('cargo', 'cargoes', 'default');
     // Inflector::irregular('cattle', 'cattle', 'default');
     // Inflector::irregular('child', 'children', 'default');
     // Inflector::irregular('congratulations', 'congratulations', 'default');
     // Inflector::irregular('corn', 'corn', 'default');
     // Inflector::irregular('crisis', 'crises', 'default');
     // Inflector::irregular('criteria', 'criterion', 'default');
     // Inflector::irregular('curriculum', 'curricula', 'default');
     // Inflector::irregular('datum', 'data', 'default');
     // Inflector::irregular('deer', 'deer', 'default');
     // Inflector::irregular('die', 'dice', 'default');
     // Inflector::irregular('dregs', 'dregs', 'default');
     // Inflector::irregular('duck', 'duck', 'default');
     // Inflector::irregular('echo', 'echos', 'default');
     // Inflector::irregular('elf', 'elves', 'default');
     // Inflector::irregular('ellipsis', 'ellipses', 'default');
     // Inflector::irregular('embargo', 'embargoes', 'default');
     // Inflector::irregular('equipment', 'equipment', 'default');
     // Inflector::irregular('erratum', 'errata', 'default');
     // Inflector::irregular('evidence', 'evidence', 'default');
     // Inflector::irregular('eyeglasses', 'eyeglasses', 'default');
     // Inflector::irregular('fish', 'fish', 'default');
     // Inflector::irregular('focus', 'foci', 'default');
     // Inflector::irregular('foot', 'feet', 'default');
     // Inflector::irregular('fungus', 'fungi', 'default');
     // Inflector::irregular('gallows', 'gallows', 'default');
     // Inflector::irregular('genus', 'genera', 'default');
     // Inflector::irregular('goose', 'geese', 'default');
     // Inflector::irregular('gold', 'gold', 'default');
     // Inflector::irregular('grotto', 'grottoes', 'default');
     // Inflector::irregular('gymnasium', 'gymnasia', 'default');
     // Inflector::irregular('half', 'halves', 'default');
     // Inflector::irregular('headquarters', 'headquarters', 'default');
     // Inflector::irregular('hoof', 'hooves', 'default');
     // Inflector::irregular('hypothesis', 'hypotheses', 'default');
     // Inflector::irregular('information', 'information', 'default');
     // Inflector::irregular('graffito', 'graffiti', 'default');
     // Inflector::irregular('half', 'halves', 'default');
     // Inflector::irregular('hero', 'heroes', 'default');
     // Inflector::irregular('jewelry', 'jewelry', 'default');
     // Inflector::irregular('kin', 'kin', 'default');
     // Inflector::irregular('knife', 'knives', 'default');
     // Inflector::irregular('larva', 'larvae', 'default');
     // Inflector::irregular('leaf', 'leaves', 'default');
     // Inflector::irregular('legislation', 'legislation', 'default');
     // Inflector::irregular('life', 'lives', 'default');
     // Inflector::irregular('loaf', 'loaves', 'default');
     // Inflector::irregular('locus', 'loci', 'default');
     // Inflector::irregular('louse', 'lice', 'default');
     // Inflector::irregular('luck', 'luck', 'default');
     // Inflector::irregular('luggage', 'luggage', 'default');
     // Inflector::irregular('man', 'men', 'default');
     // Inflector::irregular('mathematics', 'mathematics', 'default');
     // Inflector::irregular('matrix', 'matrices', 'default');
     // Inflector::irregular('means', 'means', 'default');
     // Inflector::irregular('measles', 'measles', 'default');
     // Inflector::irregular('medium', 'media', 'default');
     // Inflector::irregular('memorandum', 'memoranda', 'default');
     // Inflector::irregular('money', 'monies', 'default');
     // Inflector::irregular('moose', 'moose', 'default');
     // Inflector::irregular('mosquito', 'mosquitoes', 'default');
     // Inflector::irregular('motto', 'mottoes', 'default');
     // Inflector::irregular('mouse', 'mice', 'default');
     // Inflector::irregular('mumps', 'mumps', 'default');
     // Inflector::irregular('music', 'music', 'default');
     // Inflector::irregular('mythos', 'mythoi', 'default');
     // Inflector::irregular('nebula', 'nebulae', 'default');
     // Inflector::irregular('neurosis', 'neuroses', 'default');
     // Inflector::irregular('news', 'news', 'default');
     // Inflector::irregular('nucleus', 'nuclei', 'default');
     // Inflector::irregular('numen', 'numina', 'default');
     // Inflector::irregular('oasis', 'oases', 'default');
     // Inflector::irregular('oats', 'oats', 'default');
     // Inflector::irregular('octopus', 'octopuses', 'default');
     // Inflector::irregular('offspring', 'offspring', 'default');
     // Inflector::irregular('ovum', 'ova', 'default');
     // Inflector::irregular('ox', 'oxen', 'default');
     // Inflector::irregular('pajamas', 'pajamas', 'default');
     // Inflector::irregular('pants', 'pants', 'default');
     // Inflector::irregular('paralysis', 'paralyses', 'default');
     // Inflector::irregular('parenthesis', 'parentheses', 'default');
     // Inflector::irregular('person', 'people', 'default');
     // Inflector::irregular('phenomenon', 'phenomena', 'default');
     // Inflector::irregular('pike', 'pike', 'default');
     // Inflector::irregular('plankton', 'plankton', 'default');
     // Inflector::irregular('pliers', 'pliers', 'default');
     // Inflector::irregular('polyhedron', 'polyhedra', 'default');
     // Inflector::irregular('potato', 'potatoes', 'default');
     // Inflector::irregular('quiz', 'quizzes', 'default');
     // Inflector::irregular('radius', 'radii', 'default');
     // Inflector::irregular('roof', 'roofs', 'default');
     // Inflector::irregular('salmon', 'salmon', 'default');
     // Inflector::irregular('scarf', 'scarves', 'default');
     // Inflector::irregular('scissors', 'scissors', 'default');
     // Inflector::irregular('self', 'selves', 'default');
     // Inflector::irregular('series', 'series', 'default');
     // Inflector::irregular('shears', 'shears', 'default');
     // Inflector::irregular('sheep', 'sheep', 'default');
     // Inflector::irregular('shelf', 'shelves', 'default');
     // Inflector::irregular('shorts', 'shorts', 'default');
     // Inflector::irregular('silver', 'silver', 'default');
     // Inflector::irregular('species', 'species', 'default');
     // Inflector::irregular('squid', 'squid', 'default');
     // Inflector::irregular('stimulus', 'stimuli', 'default');
     // Inflector::irregular('stratum', 'strata', 'default');
     // Inflector::irregular('swine', 'swine', 'default');
     // Inflector::irregular('syllabus', 'syllabi', 'default');
     // Inflector::irregular('synopsis', 'synopses', 'default');
     // Inflector::irregular('synthesis', 'syntheses', 'default');
     // Inflector::irregular('tax', 'taxes', 'default');
     // Inflector::irregular('terminus', 'termini', 'default');
     // Inflector::irregular('thesis', 'theses', 'default');
     // Inflector::irregular('thief', 'thieves', 'default');
     // Inflector::irregular('tomato', 'tomatoes', 'default');
     // Inflector::irregular('tongs', 'tongs', 'default');
     // Inflector::irregular('tooth', 'teeth', 'default');
     // Inflector::irregular('torpedo', 'torpedoes', 'default');
     // Inflector::irregular('torus', 'tori', 'default');
     // Inflector::irregular('trousers', 'trousers', 'default');
     // Inflector::irregular('trout', 'trout', 'default');
     // Inflector::irregular('tweezers', 'tweezers', 'default');
     // Inflector::irregular('vertebra', 'vertebrae', 'default');
     // Inflector::irregular('vertex', 'vertices', 'default');
     // Inflector::irregular('vespers', 'vespers', 'default');
     // Inflector::irregular('veto', 'vetoes', 'default');
     // Inflector::irregular('volcano', 'volcanoes', 'default');
     // Inflector::irregular('vortex', 'vortices', 'default');
     // Inflector::irregular('vita', 'vitae', 'default');
     // Inflector::irregular('virus', 'viri', 'default');
     // Inflector::irregular('wheat', 'wheat', 'default');
     // Inflector::irregular('wife', 'wives', 'default');
     // Inflector::irregular('wolf', 'wolves', 'default');
     // Inflector::irregular('woman', 'women', 'default');
     // Inflector::irregular('zero', 'zeros', 'default');
 }
Example #5
0
Inflector::singular('/(cris|ax|test)es$/i', '\\1is');
Inflector::singular('/([octop|vir])i$/i', '\\1us');
Inflector::singular('/(alias|status)es$/i', '\\1');
Inflector::singular('/^(ox)en/i', '\\1');
Inflector::singular('/(vert|ind)ices$/i', '\\1ex');
Inflector::singular('/(matr)ices$/i', '\\1ix');
Inflector::singular('/(quiz)zes$/i', '\\1');
Inflector::plural('/$/', 's');
Inflector::plural('/s$/i', 's');
Inflector::plural('/(ax|test)is$/i', '\\1es');
Inflector::plural('/(octop|vir)us$/i', '\\1i');
Inflector::plural('/(alias|status)$/i', '\\1es');
Inflector::plural('/(bu)s$/i', '\\1ses');
Inflector::plural('/(buffal|tomat)o$/i', '\\1oes');
Inflector::plural('/([ti])um$/i', '\\1a');
Inflector::plural('/sis$/i', 'ses');
Inflector::plural('/(?:([^f])fe|([lr])f)$/i', '\\1\\2ves');
Inflector::plural('/(hive)$/i', '\\1s');
Inflector::plural('/([^aeiouy]|qu)y$/i', '\\1ies');
Inflector::plural('/([^aeiouy]|qu)ies$/i', '\\1y');
Inflector::plural('/(x|ch|ss|sh)$/i', '\\1es');
Inflector::plural('/(matr|vert|ind)ix|ex$/i', '\\1ices');
Inflector::plural('/([m|l])ouse$/i', '\\1ice');
Inflector::plural('/^(ox)$/i', '\\1en');
Inflector::plural('/(quiz)$/i', '\\1zes');
Inflector::irregular('person', 'people');
Inflector::irregular('man', 'men');
Inflector::irregular('child', 'children');
Inflector::irregular('sex', 'sexes');
Inflector::irregular('move', 'moves');
Inflector::uncountable(array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'deer', 'elk', 'cattle'));
Inflector::singular('/(n)ews$/i', '\\1ews');
Inflector::singular('/([ti])a$/i', '\\1um');
Inflector::singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i', '\\1\\2sis');
Inflector::singular('/(^analy)ses$/i', '\\1sis');
Inflector::singular('/([^f])ves$/i', '\\1fe');
Inflector::singular('/(hive)s$/i', '\\1');
Inflector::singular('/(tive)s$/i', '\\1');
Inflector::singular('/([lr])ves$/i', '\\1f');
Inflector::singular('/([^aeiouy]|qu)ies$/i', '\\1y');
Inflector::singular('/(s)eries$/i', '\\1eries');
Inflector::singular('/(m)ovies$/i', '\\1ovie');
Inflector::singular('/(x|ch|ss|sh)es$/i', '\\1');
Inflector::singular('/([m|l])ice$/i', '\\1ouse');
Inflector::singular('/(bus)es$/i', '\\1');
Inflector::singular('/(o)es$/i', '\\1');
Inflector::singular('/(shoe)s$/i', '\\1');
Inflector::singular('/(cris|ax|test)es$/i', '\\1is');
Inflector::singular('/(octop|vir)i$/i', '\\1us');
Inflector::singular('/(alias|status)es$/i', '\\1');
Inflector::singular('/^(ox)en/i', '\\1');
Inflector::singular('/(vert|ind)ices$/i', '\\1ex');
Inflector::singular('/(matr)ices$/i', '\\1ix');
Inflector::singular('/(quiz)zes$/i', '\\1');
Inflector::singular('/(database)s$/i', '\\1');
Inflector::irregular('person', 'people');
Inflector::irregular('man', 'men');
Inflector::irregular('child', 'children');
Inflector::irregular('sex', 'sexes');
Inflector::irregular('move', 'moves');
Inflector::irregular('cow', 'cattle');
Inflector::uncountable(array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans'));