Skip to content

Commit

Permalink
set i18n.enforce_available_locales before i18n.default_locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
senny committed Dec 5, 2013
1 parent d71c1fc commit 73b57a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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. * Added `Date#all_week/month/quarter/year` for generating date ranges.


*Dmitriy Meremyanin* *Dmitriy Meremyanin*
Expand Down
5 changes: 5 additions & 0 deletions activesupport/lib/active_support/i18n_railtie.rb
Expand Up @@ -31,6 +31,11 @@ def self.initialize_i18n(app)


fallbacks = app.config.i18n.delete(:fallbacks) 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| app.config.i18n.each do |setting, value|
case setting case setting
when :railties_load_path when :railties_load_path
Expand Down
11 changes: 11 additions & 0 deletions railties/test/application/initializers/i18n_test.rb
Expand Up @@ -183,5 +183,16 @@ class Foo < ActiveRecord::Base
load_app load_app
assert_fallbacks ca: [:ca, :"es-ES", :es, :'en-US', :en] assert_fallbacks ca: [:ca, :"es-ES", :es, :'en-US', :en]
end 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
end end

0 comments on commit 73b57a5

Please sign in to comment.