Sha256: 8120cb256ae0a94f38bba536d96fd04efe082bfae98331704124ec9b3b2a0830

Contents?: true

Size: 810 Bytes

Versions: 7

Compression:

Stored size: 810 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)
        traverse_map_if data[locale] do |key, value|
          next if pattern_key?(key) || ignore_key?(key, :unused)
          key = depluralize_key(locale, key)
          [key, value] unless used_key?(key)
        end.uniq
      end

      def remove_unused!(locales = self.locales)
        exclude = unused_keys.map(&:first).to_set
        locales.each do |locale|
          data[locale] = list_to_tree traverse_map_if(data[locale]) { |key, value|
            [key, value] unless exclude.include?(depluralize_key(locale, key))
          }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
i18n-tasks-0.2.19 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.18 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.17 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.15 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.14 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.13 lib/i18n/tasks/unused_keys.rb
i18n-tasks-0.2.12 lib/i18n/tasks/unused_keys.rb