diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-10 21:42:03 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-10 21:42:03 +0100 |
commit | 0cffe1b316b010b53dd5b5c6a63e4082d23e216d (patch) | |
tree | 05c419c6428a2bcdc083a3f2682856fa07473d76 /actionview/lib/action_view | |
parent | efa445c7b5fe17b4f1a2aeb6ad5dcac464dbe9d6 (diff) | |
parent | 82aab15dac7b15f7d19ef9f931068e8777c17e55 (diff) | |
download | rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.tar.gz rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.tar.bz2 rails-0cffe1b316b010b53dd5b5c6a63e4082d23e216d.zip |
Merge pull request #20638 from jaimeiniesta/locale-aware-pluralize-helper
Pass the current locale to Inflector from the pluralize text helper.
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/helpers/text_helper.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/actionview/lib/action_view/helpers/text_helper.rb b/actionview/lib/action_view/helpers/text_helper.rb index 432693bc23..58ce042f12 100644 --- a/actionview/lib/action_view/helpers/text_helper.rb +++ b/actionview/lib/action_view/helpers/text_helper.rb @@ -204,12 +204,12 @@ module ActionView # Attempts to pluralize the +singular+ word unless +count+ is 1. If # +plural+ is supplied, it will use that when count is > 1, otherwise - # it will use the Inflector to determine the plural form. + # it will use the Inflector to determine the plural form for the given locale, + # which defaults to I18n.locale # - # 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 + # The word will be pluralized using rules defined for the locale + # (you must define your own inflection rules for languages other than English). + # See ActiveSupport::Inflector.pluralize # # pluralize(1, 'person') # # => 1 person @@ -217,7 +217,7 @@ module ActionView # pluralize(2, 'person') # # => 2 people # - # pluralize(3, 'person', 'users') + # pluralize(3, 'person', plural: 'users') # # => 3 users # # pluralize(0, 'person') @@ -225,7 +225,14 @@ module ActionView # # pluralize(2, 'Person', locale: :de) # # => 2 Personen - def pluralize(count, singular, plural = nil, locale: nil) + def pluralize(count, singular, deprecated_plural = nil, plural: nil, locale: I18n.locale) + if deprecated_plural + ActiveSupport::Deprecation.warn("Passing plural as a positional argument " \ + "is deprecated and will be removed in Rails 5.1. Use e.g. " \ + "pluralize(1, 'person', plural: 'people') instead.") + plural ||= deprecated_plural + end + word = if (count == 1 || count =~ /^1(\.0+)?$/) singular else |