diff options
author | Stefan Daschek <stefan@die-antwort.eu> | 2015-07-08 14:59:47 +0200 |
---|---|---|
committer | Stefan Daschek <stefan@die-antwort.eu> | 2015-07-09 14:51:13 +0200 |
commit | bb851651f19ae91b800c7eff220690d8ca8fc368 (patch) | |
tree | 5dbd9d805f5564cfadd0a80db9e6e3453a71bde3 /actionview/lib/action_view/helpers | |
parent | c2b5aa041b04e65475dd3ebb9f33a68b26e25895 (diff) | |
download | rails-bb851651f19ae91b800c7eff220690d8ca8fc368.tar.gz rails-bb851651f19ae91b800c7eff220690d8ca8fc368.tar.bz2 rails-bb851651f19ae91b800c7eff220690d8ca8fc368.zip |
Allow `pluralize` helper to take a locale.
This is already supported in `ActiveSupport::Inflector#pluralize` and `String#pluralize`, so we just forward the locale.
Diffstat (limited to 'actionview/lib/action_view/helpers')
-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}" |