Changeset 276

Show
Ignore:
Timestamp:
01/22/07 04:53:53 (5 years ago)
Author:
john
Message:

modified Inflector::pluralize to take a second param

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/inflector.php

    r201 r276  
    4646     * 
    4747     *  Convert a lower-case singular word to plural form. 
     48     *  If $count > 0 then prefixes $word with the $count 
     49     * 
    4850     *  @param  string $word  Word to be pluralized 
     51     *  @param  int $count How many of these $words are there 
    4952     *  @return string  Plural of $word 
    5053     */ 
    51     function pluralize($word) { 
    52         if(!in_array($word, Inflections::$uncountables)) {  
    53             $original = $word;    
    54             foreach(Inflections::$plurals as $plural_rule) { 
    55                 $word = preg_replace($plural_rule['rule'], $plural_rule['replacement'], $word); 
    56                 if($original != $word) break; 
     54    function pluralize($word, $count = 0) { 
     55        if($count == 0 || $count > 1) {           
     56            if(!in_array($word, Inflections::$uncountables)) {  
     57                $original = $word;    
     58                foreach(Inflections::$plurals as $plural_rule) { 
     59                    $word = preg_replace($plural_rule['rule'], $plural_rule['replacement'], $word); 
     60                    if($original != $word) break; 
     61                } 
    5762            } 
    5863        } 
    59         return $word; 
     64        return ($count >= 1 ? "{$count} {$word}" : $word); 
    6065    } 
    6166