diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-07-09 21:24:24 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-07-09 21:24:24 +0200 |
commit | 87b4f3105f7eaa2db6cbe75ec0e4ee77146552d2 (patch) | |
tree | 753241c535e8cb331e446424f1614ece6d457cc9 /actionview/lib | |
parent | 140d5a3b2f2131c7e7184f6792a3d94646c19cc0 (diff) | |
parent | bb851651f19ae91b800c7eff220690d8ca8fc368 (diff) | |
download | rails-87b4f3105f7eaa2db6cbe75ec0e4ee77146552d2.tar.gz rails-87b4f3105f7eaa2db6cbe75ec0e4ee77146552d2.tar.bz2 rails-87b4f3105f7eaa2db6cbe75ec0e4ee77146552d2.zip |
Merge pull request #20813 from noniq/locale-argument-for-pluralize-helper
Allow `pluralize` helper to take a locale.
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/helpers/text_helper.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index c216d4401f..6a3d01667d 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -206,6 +206,11 @@ module ActionView # +plural+ is supplied, it will use that when count is > 1, otherwise # it will use the Inflector to determine the plural form. # + # If passed an optional +locale:+ parameter, the word will be pluralized + # using rules defined for that language (you must define your own + # inflection rules for languages other than English). See + # ActiveSupport::Inflector.pluralize + # # pluralize(1, 'person') # # => 1 person # @@ -217,11 +222,14 @@ module ActionView # # pluralize(0, 'person') # # => 0 people - def pluralize(count, singular, plural = nil) + # + # pluralize(2, 'Person', locale: :de) + # # => 2 Personen + def pluralize(count, singular, plural = nil, locale: nil) word = if (count == 1 || count =~ /^1(\.0+)?$/) singular else - plural || singular.pluralize + plural || singular.pluralize(locale) end "#{count || 0} #{word}" |