Skip to content

Commit 36b2dbf

Browse files
authored
Merge pull request rails#52271 from Schwad/schwad/only_watch_local_translations
[i18n] - Do not watch translations from gems when reloading is enabled
2 parents 86d3ea1 + e617046 commit 36b2dbf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

activesupport/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those
2+
under `Rails.root`. Previously the watcher would grab all available locales, including those in gems
3+
which do not require a watcher because they won't change.
4+
5+
*Nick Schwaderer*
6+
17
* Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
28
by these values.
39

activesupport/lib/active_support/i18n_railtie.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def self.initialize_i18n(app)
6262

6363
if app.config.reloading_enabled?
6464
directories = watched_dirs_with_extensions(reloadable_paths)
65-
reloader = app.config.file_watcher.new(I18n.load_path.dup, directories) do
66-
I18n.load_path.keep_if { |p| File.exist?(p) }
65+
root_load_paths = I18n.load_path.select { |path| path.start_with?(Rails.root.to_s) }
66+
reloader = app.config.file_watcher.new(root_load_paths, directories) do
67+
I18n.load_path.delete_if { |p| p.start_with?(Rails.root.to_s) && !File.exist?(p) }
6768
I18n.load_path |= reloadable_paths.flat_map(&:existent)
6869
end
6970

0 commit comments

Comments
 (0)