aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-05 04:27:19 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-05 04:27:19 -0800
commitf0c58621f104492aa1c2b6cb13ecb2d6c60541fa (patch)
tree537593924b3da1aadc30f9722af4dbf65f9c7019
parentd71c1fc6a7f4a7fcdb84b8c091fb29c53b09dc68 (diff)
parent73b57a515f650595b21b9f26b4a5a3c9c982691e (diff)
downloadrails-f0c58621f104492aa1c2b6cb13ecb2d6c60541fa.tar.gz
rails-f0c58621f104492aa1c2b6cb13ecb2d6c60541fa.tar.bz2
rails-f0c58621f104492aa1c2b6cb13ecb2d6c60541fa.zip
Merge pull request #13190 from senny/set_enforce_available_locales_first
Set `i18n.enforce_available_locales` before any other configuration option.
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/i18n_railtie.rb5
-rw-r--r--railties/test/application/initializers/i18n_test.rb11
3 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 2cb44d8371..ea4aaff610 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Ensure `config.i18n.enforce_available_locales` is set before any other
+ configuration option.
+
+ *Yves Senn*
+
* Added `Date#all_week/month/quarter/year` for generating date ranges.
*Dmitriy Meremyanin*
diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb
index 890dd9380b..dcdea70443 100644
--- a/activesupport/lib/active_support/i18n_railtie.rb
+++ b/activesupport/lib/active_support/i18n_railtie.rb
@@ -31,6 +31,11 @@ module I18n
fallbacks = app.config.i18n.delete(:fallbacks)
+ if app.config.i18n.has_key?(:enforce_available_locales)
+ # this option needs to be set before `default_locale=` to work properly.
+ I18n.enforce_available_locales = app.config.i18n.delete(:enforce_available_locales)
+ end
+
app.config.i18n.each do |setting, value|
case setting
when :railties_load_path
diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb
index 97df073ec7..2a64cd8ba7 100644
--- a/railties/test/application/initializers/i18n_test.rb
+++ b/railties/test/application/initializers/i18n_test.rb
@@ -183,5 +183,16 @@ en:
load_app
assert_fallbacks ca: [:ca, :"es-ES", :es, :'en-US', :en]
end
+
+ test "config.i18n.enforce_available_locales is set before config.i18n.default_locale is" do
+ add_to_config <<-RUBY
+ config.i18n.default_locale = :it
+ config.i18n.enforce_available_locales = true
+ RUBY
+
+ assert_raises(I18n::InvalidLocale) do
+ load_app
+ end
+ end
end
end