lib/i18n/tasks/missing_keys.rb in i18n-tasks-0.9.3 vs lib/i18n/tasks/missing_keys.rb in i18n-tasks-0.9.4

- old
+ new

@@ -87,28 +87,31 @@ def locale_key_missing?(locale, key) !key_value?(key, locale) && !ignore_key?(key, :missing) end # @param [::I18n::Tasks::Data::Tree::Siblings] forest - def collapse_missing_used_locales!(forest) - locales_and_nodes_by_key = {} - to_remove = [] + # @yield [::I18n::Tasks::Data::Tree::Node] + # @yieldreturn [Boolean] whether to collapse the node + def collapse_same_key_in_locales!(forest) + locales_and_node_by_key = {} + to_remove = [] forest.each do |root| locale = root.key - root.leaves { |node| - if node.data[:type] == :missing_used - (locales_and_nodes_by_key[node.full_key(root: false)] ||= []) << [locale, node] - to_remove << node + root.keys { |key, node| + next unless yield node + if locales_and_node_by_key.key?(key) + locales_and_node_by_key[key][0] << locale + else + locales_and_node_by_key[key] = [[locale], node] end + to_remove << node } end - forest.remove_nodes_collapsing_emptied_ancestors! to_remove - keys_and_nodes_by_locale = {} - locales_and_nodes_by_key.each { |key, locales_and_nodes| - locales = locales_and_nodes.map(&:first).sort.join('+') - (keys_and_nodes_by_locale[locales] ||= []) << [key, locales_and_nodes[0][1]] - } - keys_and_nodes_by_locale.map { |locales, keys_nodes| + forest.remove_nodes_and_emptied_ancestors! to_remove + locales_and_node_by_key.inject({}) { |inv, (key, (locales, node))| + (inv[locales.sort.join('+')] ||= []) << [key, node] + inv + }.map { |locales, keys_nodes| keys_nodes.each { |(key, node)| forest["#{locales}.#{key}"] = node } } forest