Skip to content

Commit

Permalink
Merge pull request #692 from uiur/optimize-fallbacks-compute
Browse files Browse the repository at this point in the history
Optimize I18n::Locale::Fallbacks#[] for recursive locale mappings
  • Loading branch information
radar committed May 6, 2024
2 parents 7842cab + fb8e34e commit 9b84d1d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/i18n/locale/fallbacks.rb
Expand Up @@ -90,11 +90,13 @@ def inspect
protected

def compute(tags, include_defaults = true, exclude = [])
result = Array(tags).flat_map do |tag|
result = []
Array(tags).each do |tag|
tags = I18n::Locale::Tag.tag(tag).self_and_parents.map! { |t| t.to_sym } - exclude
tags.each { |_tag| tags += compute(@map[_tag], false, exclude + tags) if @map[_tag] }
tags
result += tags
tags.each { |_tag| result += compute(@map[_tag], false, exclude + result) if @map[_tag] }
end

result.push(*defaults) if include_defaults
result.uniq!
result.compact!
Expand Down

0 comments on commit 9b84d1d

Please sign in to comment.