lib/i18n/tasks/missing_keys.rb in i18n-tasks-0.9.27 vs lib/i18n/tasks/missing_keys.rb in i18n-tasks-0.9.28

- old
+ new

@@ -1,24 +1,25 @@ # frozen_string_literal: true require 'set' module I18n::Tasks - module MissingKeys - MISSING_TYPES = { - used: { glyph: '✗', summary: 'used in code but missing from base locale' }, - diff: { glyph: '∅', summary: 'translated in one locale but not in the other' } - }.freeze + module MissingKeys # rubocop:disable Metrics/ModuleLength + MISSING_TYPES = %w[ + used + diff + plural + ].freeze def self.missing_keys_types - @missing_keys_types ||= MISSING_TYPES.keys + @missing_keys_types ||= MISSING_TYPES end def missing_keys_types MissingKeys.missing_keys_types end - # @param types [:used, :diff] all if `nil`. + # @param types [:used, :diff, :plural] all if `nil`. # @return [Siblings] def missing_keys(locales: nil, types: nil, base_locale: nil) locales ||= self.locales types ||= missing_keys_types base = base_locale || self.base_locale @@ -50,9 +51,29 @@ end def missing_used_forest(locales, _base = base_locale) locales.inject(empty_forest) do |forest, locale| forest.merge! missing_used_tree(locale) + end + end + + def missing_plural_forest(locales, _base = base_locale) + locales.each_with_object(empty_forest) do |locale, forest| + next unless I18n.exists?(:'i18n.plural.keys', locale) + required_keys = Set.new(I18n.t(:'i18n.plural.keys', locale: locale, resolve: false)) + tree = empty_forest + plural_nodes data[locale] do |node| + children = node.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) + ) + end + tree.set_root_key!(locale, type: :missing_plural) + forest.merge!(tree) end end # keys present in compared_to, but not in locale def missing_diff_tree(locale, compared_to = base_locale)