aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-12 08:28:30 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-12-17 09:05:41 -0200
commitc445c6d1b99c987b7f98943db46f705a3acc400f (patch)
tree0c8781fa9336ba1f06c39696197e83f852c357ae /activesupport
parentaaa5463cc0d81e400ddfb4fdacc0caee319fd587 (diff)
downloadrails-c445c6d1b99c987b7f98943db46f705a3acc400f.tar.gz
rails-c445c6d1b99c987b7f98943db46f705a3acc400f.tar.bz2
rails-c445c6d1b99c987b7f98943db46f705a3acc400f.zip
Default I18n.enforce_available_locales to true
We will default this option to true from now on to ensure users properly handle their list of available locales whenever necessary. This option was added as a security measure and thus Rails will follow it defaulting to secure option. Also improve the handling of I18n config options in its railtie, taking the new enforce_available_locales option into account, by setting it as the last one in the process. This ensures no other configuration will trigger a deprecation warning due to that setting.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/i18n_railtie.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb
index dcdea70443..ac9bca44b6 100644
--- a/activesupport/lib/active_support/i18n_railtie.rb
+++ b/activesupport/lib/active_support/i18n_railtie.rb
@@ -8,6 +8,8 @@ module I18n
config.i18n.railties_load_path = []
config.i18n.load_path = []
config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
+ # Enforce I18n to check the available locales when setting a locale.
+ config.i18n.enforce_available_locales = true
# Set the i18n configuration after initialization since a lot of
# configuration is still usually done in application initializers.
@@ -31,10 +33,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
+ # Avoid issues with setting the default_locale by disabling available locales
+ # check while configuring.
+ enforce_available_locales = app.config.i18n.delete(:enforce_available_locales)
+ enforce_available_locales = I18n.enforce_available_locales unless I18n.enforce_available_locales.nil?
+ I18n.enforce_available_locales = false
app.config.i18n.each do |setting, value|
case setting
@@ -49,6 +52,9 @@ module I18n
init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
+ # Restore avalable locales check so it will take place from now on.
+ I18n.enforce_available_locales = enforce_available_locales
+
reloader = ActiveSupport::FileUpdateChecker.new(I18n.load_path.dup){ I18n.reload! }
app.reloaders << reloader
ActionDispatch::Reloader.to_prepare { reloader.execute_if_updated }