Sha256: c54d01e5a85970c9f2c13120f6fc780e1a6206ead7b3599ee45af0505fceed41

Contents?: true

Size: 955 Bytes

Versions: 7

Compression:

Stored size: 955 Bytes

Contents

# coding: utf-8
require 'set'

module I18n
  module Tasks
    module UnusedKeys
      # @return [Array<[String, String]>] all the unused translations as an array of [key, value] pairs
      def unused_keys(locale = base_locale)
        @unused_keys         ||= {}
        @unused_keys[locale] ||= begin
          keys = data[locale].keys(root: false).map { |key, value|
            next if used_in_expr?(key) || ignore_key?(key, :unused)
            key = depluralize_key(key, locale)
            key unless used_key?(key)
          }.compact.uniq
          KeyGroup.new keys, locale: locale, type: :unused
        end
      end

      def remove_unused!(locales = nil)
        locales ||= self.locales
        unused  = unused_keys
        locales.each do |locale|
          data[locale] = data[locale].select_keys(root: false) { |key, value|
            !unused.include?(depluralize_key(key, locale))
          }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
i18n-tasks-0.4.5 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.4 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.3 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.2 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.1 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.0 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.4.0.beta1 lib/i18n/tasks/unused_keys.rb