Skip to content

Commit dfd1e95

Browse files
committed
Reorder i18n hooks and reword comments
If eager loading is enabled, `before_eager_load` runs before `after_initialize`. I believe it is natural to define these hooks matching that order. For this to make sense, it is important to highlight that initialize_i18n is idempotent.
1 parent 219e753 commit dfd1e95

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

activesupport/lib/active_support/i18n_railtie.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ class Railtie < Rails::Railtie
1414

1515
config.eager_load_namespaces << I18n
1616

17-
# Set the i18n configuration after initialization since a lot of
18-
# configuration is still usually done in application initializers.
19-
config.after_initialize do |app|
17+
# Make sure i18n is ready before eager loading, in case any eager loaded
18+
# code needs it.
19+
config.before_eager_load do |app|
2020
I18n::Railtie.initialize_i18n(app)
2121
end
2222

23-
# Trigger i18n config before any eager loading has happened
24-
# so it's ready if any classes require it when eager loaded.
25-
config.before_eager_load do |app|
23+
# i18n initialization needs to run after application initialization, since
24+
# initializers may configure i18n.
25+
#
26+
# If the application eager loaded, this was done on before_eager_load. The
27+
# hook is still OK, though, because initialize_i18n is idempotent.
28+
config.after_initialize do |app|
2629
I18n::Railtie.initialize_i18n(app)
2730
end
2831

0 commit comments

Comments
 (0)