Skip to content

Commit

Permalink
Yield loaded translations to block in #load_translations
Browse files Browse the repository at this point in the history
This makes introspecting the translations loaded by a file easier. Maintains backwards compatability as the block is optional.
  • Loading branch information
paarthmadan committed Feb 3, 2022
1 parent 9ec31b0 commit eb9dbf4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/i18n/backend/base.rb
Expand Up @@ -13,7 +13,10 @@ module Base
# for details.
def load_translations(*filenames)
filenames = I18n.load_path if filenames.empty?
filenames.flatten.each { |filename| load_file(filename) }
filenames.flatten.each do |filename|
loaded_translations = load_file(filename)
yield filename, loaded_translations if block_given?
end
end

# This method receives a locale, a data hash and options for storing translations.
Expand Down Expand Up @@ -226,6 +229,8 @@ def load_file(filename)
raise InvalidLocaleData.new(filename, 'expects it to return a hash, but does not')
end
data.each { |locale, d| store_translations(locale, d || {}, skip_symbolize_keys: keys_symbolized) }

data
end

# Loads a plain Ruby translations file. eval'ing the file must yield
Expand Down

0 comments on commit eb9dbf4

Please sign in to comment.