aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-05-28 22:53:42 +0930
committerMatthew Draper <matthew@trebex.net>2017-05-28 22:54:54 +0930
commit352865d0f835c24daa9a2e9863dcc9dde9e5371a (patch)
tree32e5e2638a38369c100ac80916bb09072e79bfd7 /activesupport/lib
parent58a5aa40ec869839fc514116fb81a135050082f6 (diff)
parent7c45146b15e682de11251180eaa4e75ac50e07cd (diff)
downloadrails-352865d0f835c24daa9a2e9863dcc9dde9e5371a.tar.gz
rails-352865d0f835c24daa9a2e9863dcc9dde9e5371a.tar.bz2
rails-352865d0f835c24daa9a2e9863dcc9dde9e5371a.zip
Merge pull request #29097 from EilisHamilton/fix_uncountable_pluralization_locale
Fix pluralization of uncountables when given a locale
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb15
1 files changed, 9 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 1b089a7538..ff1a0cb8c7 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -28,7 +28,7 @@ module ActiveSupport
# pluralize('CamelOctopus') # => "CamelOctopi"
# pluralize('ley', :es) # => "leyes"
def pluralize(word, locale = :en)
- apply_inflections(word, inflections(locale).plurals)
+ apply_inflections(word, inflections(locale).plurals, locale)
end
# The reverse of #pluralize, returns the singular form of a word in a
@@ -45,7 +45,7 @@ module ActiveSupport
# singularize('CamelOctopi') # => "CamelOctopus"
# singularize('leyes', :es) # => "ley"
def singularize(word, locale = :en)
- apply_inflections(word, inflections(locale).singulars)
+ apply_inflections(word, inflections(locale).singulars, locale)
end
# Converts strings to UpperCamelCase.
@@ -387,12 +387,15 @@ module ActiveSupport
# Applies inflection rules for +singularize+ and +pluralize+.
#
- # apply_inflections('post', inflections.plurals) # => "posts"
- # apply_inflections('posts', inflections.singulars) # => "post"
- def apply_inflections(word, rules)
+ # If passed an optional +locale+ parameter, the uncountables will be
+ # found for that locale.
+ #
+ # apply_inflections('post', inflections.plurals, :en) # => "posts"
+ # apply_inflections('posts', inflections.singulars, :en) # => "post"
+ def apply_inflections(word, rules, locale = :en)
result = word.to_s.dup
- if word.empty? || inflections.uncountables.uncountable?(result)
+ if word.empty? || inflections(locale).uncountables.uncountable?(result)
result
else
rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }