From 46b0e7d1d77c77d013235e3bf99d1afb89513cc9 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 23 Jun 2007 16:47:47 +0000 Subject: Added support for pluralization with a different starting letter than the singular version (cow/kine) (closes #4929) [norri_b/hasmanyjosh] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7092 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/inflections.rb | 1 + activesupport/lib/active_support/inflector.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index f53ef53ca4..967722c2bf 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -47,6 +47,7 @@ Inflector.inflections do |inflect| 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 084c58d389..db6e44e91b 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -47,8 +47,15 @@ module Inflector # 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. -- cgit v1.2.3