Skip to content

Commit

Permalink
Missing plural keys: minor optimization
Browse files Browse the repository at this point in the history
Refs #309
Refs #310
  • Loading branch information
glebm committed Oct 26, 2018
1 parent 27716c5 commit 5dca119
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/i18n/tasks/missing_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ def missing_used_forest(locales, _base = base_locale)
end
end

def missing_plural_forest(locales, _base = base_locale) # rubocop:disable Metrics/AbcSize
def missing_plural_forest(locales, _base = base_locale)
locales.each_with_object(empty_forest) do |locale, tree|
next unless I18n.exists?(:'i18n.plural.keys', locale)

required_keys = Set.new(I18n.t(:'i18n.plural.keys', locale: locale, resolve: false))

data[locale].leaves.map(&:parent).compact.uniq.each do |node|
children = node.children
present_keys = Set.new(children.to_hash.keys.map(&:to_sym))
next if !plural_forms?(children) || present_keys.superset?(required_keys)
children = node.children
next unless plural_forms?(children)
present_keys = Set.new(children.map { |c| c.key.to_sym })
next if present_keys.superset?(required_keys)
tree[node.full_key] = node.derive(
value: children.to_hash,
children: nil,
data: node.data.merge(missing_keys: (required_keys - present_keys).to_a)
value: children.to_hash,
children: nil,
data: node.data.merge(missing_keys: (required_keys - present_keys).to_a)
)
end

Expand Down

0 comments on commit 5dca119

Please sign in to comment.