aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/i18n_railtie.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/i18n_railtie.rb')
-rw-r--r--activesupport/lib/active_support/i18n_railtie.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/i18n_railtie.rb b/activesupport/lib/active_support/i18n_railtie.rb
index db09919fd3..a25e951080 100644
--- a/activesupport/lib/active_support/i18n_railtie.rb
+++ b/activesupport/lib/active_support/i18n_railtie.rb
@@ -14,19 +14,34 @@ module I18n
@reloader ||= ActiveSupport::FileUpdateChecker.new([]){ I18n.reload! }
end
- # Add I18n::Railtie.reloader to ActionDispatch callbacks. Since, at this
+ # Add <tt>I18n::Railtie.reloader</tt> to ActionDispatch callbacks. Since, at this
# point, no path was added to the reloader, I18n.reload! is not triggered
# on to_prepare callbacks. This will only happen on the config.after_initialize
# callback below.
initializer "i18n.callbacks" do
- ActionDispatch::Callbacks.to_prepare do
+ ActionDispatch::Reloader.to_prepare do
I18n::Railtie.reloader.execute_if_updated
end
end
- # Set the i18n configuration only after initialization since a lot of
+ # Set the i18n configuration after initialization since a lot of
# configuration is still usually done in application initializers.
config.after_initialize do |app|
+ I18n::Railtie.initialize_i18n(app)
+ end
+
+ # Trigger i18n config before any eager loading has happened
+ # so it's ready if any classes require it when eager loaded
+ config.before_eager_load do |app|
+ I18n::Railtie.initialize_i18n(app)
+ end
+
+ protected
+
+ # Setup i18n configuration
+ def self.initialize_i18n(app)
+ return if @i18n_inited
+
fallbacks = app.config.i18n.delete(:fallbacks)
app.config.i18n.each do |setting, value|
@@ -44,9 +59,9 @@ module I18n
reloader.paths.concat I18n.load_path
reloader.execute_if_updated
- end
- protected
+ @i18n_inited = true
+ end
def self.include_fallbacks_module
I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
@@ -66,7 +81,7 @@ module I18n
I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
end
-
+
def self.validate_fallbacks(fallbacks)
case fallbacks
when ActiveSupport::OrderedOptions
@@ -78,4 +93,4 @@ module I18n
end
end
end
-end \ No newline at end of file
+end