Skip to content
Browse files

Fix inflector to respect default locale.

The inflector was made aware of locales in 7db0b07,
but it defaulted to :en. That should actually be our default
locale instead.

Fixes #10125
  • Loading branch information...
1 parent 9039c50 commit 8cf88cc75ad0289f39fc2272c372f945b3934e76 @thenickcox thenickcox committed with steveklabnik
4 activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -28,7 +28,7 @@ class String
# 'apple'.pluralize(2) # => "apples"
# 'ley'.pluralize(:es) # => "leyes"
# 'ley'.pluralize(1, :es) # => "ley"
- def pluralize(count = nil, locale = :en)
+ def pluralize(count = nil, locale = I18n.locale)
locale = count if count.is_a?(Symbol)
if count == 1
@@ -51,7 +51,7 @@ def pluralize(count = nil, locale = :en)
# 'the blue mailmen'.singularize # => "the blue mailman"
# 'CamelOctopi'.singularize # => "CamelOctopus"
# 'leyes'.singularize(:es) # => "ley"
- def singularize(locale = :en)
+ def singularize(locale = I18n.locale)
ActiveSupport::Inflector.singularize(self, locale)
17 activesupport/test/inflector_test.rb
@@ -380,6 +380,23 @@ def test_inflector_locality
assert !ActiveSupport::Inflector.inflections.plurals.empty?
assert !ActiveSupport::Inflector.inflections.singulars.empty?
+ def test_inflector_with_default_locale
+ old_locale = I18n.locale
+ begin
+ I18n.locale = :de
+ ActiveSupport::Inflector.inflections(:de) do |inflect|
+ inflect.irregular 'region', 'regionen'
+ end
+ assert_equal('regionen', 'region'.pluralize)
+ assert_equal('region', 'regionen'.singularize)
+ ensure
+ I18n.locale = old_locale
+ end
+ end
def test_clear_all
with_dup do

6 comments on commit 8cf88cc


This needs to be I18n.default_locale. Please see #10163

Ruby on Rails member

Why are we doing this?

An application by a French company may have a default of French for their interface, but all their tables be pluralized in English as we have done always.


Two alternatives, for discussion purposes:

Ruby on Rails member

I would revert this commit. I don't see why we are doing this.


What is the status here?
From my (very limited) point of view pinning Active Record to :en seems to be a good approach.

Ruby on Rails member

This commit was reverted in d716fe0. In addition to Active Record there are more parts of Rails that use the inflector. By now you'll need to pass the locale yourself, or implement wrappers

# config/initializers/core_extensions.rb
String.class_eval do
  def xsingularize(locale=I18n.locale)

We are very close to RC1, doubt this will change for Rails 4.

Please sign in to comment.
Something went wrong with that request. Please try again.