Merge pull request #52271 from Schwad/schwad/only_watch_local_translations

[i18n] - Do not watch translations from gems when reloading is enabled
This commit is contained in:
Gannon McGibbon 2024-07-11 13:00:20 -05:00 committed by GitHub
commit 36b2dbfc1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

@ -1,3 +1,9 @@
* Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those
under `Rails.root`. Previously the watcher would grab all available locales, including those in gems
which do not require a watcher because they won't change.
*Nick Schwaderer*
* Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
by these values. by these values.

@ -62,8 +62,9 @@ def self.initialize_i18n(app)
if app.config.reloading_enabled? if app.config.reloading_enabled?
directories = watched_dirs_with_extensions(reloadable_paths) directories = watched_dirs_with_extensions(reloadable_paths)
reloader = app.config.file_watcher.new(I18n.load_path.dup, directories) do root_load_paths = I18n.load_path.select { |path| path.start_with?(Rails.root.to_s) }
I18n.load_path.keep_if { |p| File.exist?(p) } reloader = app.config.file_watcher.new(root_load_paths, directories) do
I18n.load_path.delete_if { |p| p.start_with?(Rails.root.to_s) && !File.exist?(p) }
I18n.load_path |= reloadable_paths.flat_map(&:existent) I18n.load_path |= reloadable_paths.flat_map(&:existent)
end end