Here is the implementation of PHP, in fact, in CSharp or Java, the implementation of the same approach.
/** * Wirror:pluralize A String * @param $string/function pluralize ($string) {$plural = Array ('/(Quiz) $/i ', "$1zes"), Array ('/^ (ox) $/i ', "$1en"), Array ('/([m|l]) ouse$/i ', "$1ice"), Array ('/(Matr|vert|ind) ix|ex$/i ', "$1ices" ), Array ('/(X|CH|SS|SH) $/i ', ' $1es '), Array ('/([^aeiouy]|qu) y$/i ', ' $1ies '), Array ('/([^aeiouy]|qu) ies$/i ', ' $1y '), Array ('/(hive) $/i ', "$1s"), Array ('/(?:( [^f]) fe| ([LR] f) $/i ', "$1$2ves"), Array ('/sis$/i ', "ses"), Array ('/[[Ti]] um$/i ', "$1a"), Array ('/(Buffal|tomat) o$/i ', "$1oes "), Array (' bu) s$/i '," $1ses "), Array ('/(alias|status) $/i ', ' $1es '), Array (' Octop|vir ' us$/i ', ' $1i '), Array ('/( ax|test) is$/i ', "$1es"), Array ('/s$/i ', "s"), Array ('/$/', "s")); $singular = Array (Array ("/s$/", ""), Array ("/(n) ews$/", "$1ews"), Array ("[Ti]) a$/", "$1um"), Array ("/((a) naly| ( b) a| (d) iagno| (p) arenthe| (p) rogno| (s) ynop| (t) He) ses$/"," $1$2sis "), Array ("/(^analy) ses$/"," $1sis "), Array (" [^f]) ves$/"," $1fe "), Array ("/(Hive) s$/","$"), Array ("/(tive) s$/", "$"), Array ("/[[LR]) ves$/", "$1f"), Array ("/[^aeiouy]|qu) ies$/", "$1y"), Array ("/(s) eries$/"," $1eries "), Array ("/(m) ovies$/"," $1ovie "), Array ("/(X|CH|SS|SH) es$/"," $ "), Array (" [M|l]) ice$/"," $ 1ouse "), Array ("/(BUS) es$/"," $ "), Array ("/(O) es$/"," $ "), Array ("/(shoe) s$/"," $ "), Array ("/(Cris|ax|test) es$/"," $1is "), Array ("/[[Octop|vir]) i$/"," $1us "), Array ("/(Alias|status) es$/"," $ "), Array ("/^ (ox) en/"," $ "), Array ("/( Vert|ind) ices$/"," $1ex "), Array ("/(MATR) ices$/"," $1ix "), Array ("/(Quiz) zes$/"," $ "); $irregular = Array (' Move ', ' moves '), array (' sex ', ' sexes '), array (' child ', ' children '), Array (' Mans ', ' Men ') , array (' person ', ' people ')); $uncountable = Array (' sheep ', ' Fish ', ' series ', ' species ', ' money ', ' rice ', ' information ', ' equipment '); Save some time in the "case" singular and plural are the same if (In_array ($string), $uncountable) return $string; Check for irregular singular forms foreach ($iRregular as $noun) {if (Strtolower ($string) = = $noun [0]) return $noun [1];}//Check for matches using regular Expre Ssions foreach ($plural as $pattern) {if (Preg_match ($pattern [0], $string)) return preg_replace ($pattern [0], $patt ERN[1], $string); return $string; }