diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index a4046061aa3779cdd5249c590615cf8f41a2b971..be7eba5b0c58ad4dc996948850ebab057da4baac 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added support for pluralization with a different starting letter than the singular version (cow/kine) #4929 [norri_b/hasmanyjosh] + * Demote Hash#to_xml to use XmlSimple#xml_in_string so it can't read files or stdin. #8453 [candlerb, Jeremy Kemper] * Backport clean_logger changes to support ruby 1.8.2 [mislav] diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index f53ef53ca453452bded676194607e43fa02f4593..967722c2bfa3f4a1b9e4ed7d985bfa709f7d0c49 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -47,6 +47,7 @@ inflect.irregular('child', 'children') inflect.irregular('sex', 'sexes') inflect.irregular('move', 'moves') + inflect.irregular('cow', 'kine') inflect.uncountable(%w(equipment information rice money species series fish sheep)) end diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index 084c58d38918896cce97b2597be6f6f9288eba5f..db6e44e91b9fb93fa8c1875c742a388909727ace 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -47,8 +47,15 @@ def singular(rule, replacement) # irregular 'octopus', 'octopi' # irregular 'person', 'people' def irregular(singular, plural) - plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) - singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + if singular[0,1].upcase == plural[0,1].upcase + plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) + singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1]) + else + plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1]) + plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1]) + singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1]) + singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1]) + end end # Add uncountable words that shouldn't be attempted inflected. diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 9849e0b52b5cc6ec5f9ff32d5125c911ff9ca15c..684150a9255304b42a7c645657b9b2e2e1a50e8e 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -104,7 +104,9 @@ class InflectorTest < Test::Unit::TestCase "horse" => "horses", "prize" => "prizes", - "edge" => "edges" + "edge" => "edges", + + "cow" => "kine" } CamelToUnderscore = {