class I18n::Tasks::Reports::Base
Attributes
task[R]
Public Class Methods
new(task = I18n::Tasks::BaseTask.new)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 7 def initialize(task = I18n::Tasks::BaseTask.new) @task = task end
Protected Instance Methods
collapse_missing_tree!(forest)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 70 def collapse_missing_tree!(forest) forest = task.collapse_plural_nodes!(forest) task.collapse_same_key_in_locales!(forest) { |node| node.data[:type] == :missing_used } end
eq_base_title(key_values, locale = base_locale)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 33 def eq_base_title(key_values, locale = base_locale) "Same value as #{locale} (#{key_values.count || '∅'})" end
forest_to_attr(forest)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 54 def forest_to_attr(forest) forest.keys(root: false).map do |key, node| { key: key, value: node.value, type: node.data[:type], locale: node.root.key, data: node.data } end end
format_locale(locale)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 60 def format_locale(locale) return '' unless locale if locale.split('+') == task.locales.sort 'all' else locale.tr '+', ' ' end end
inconsistent_interpolations_title(forest)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 25 def inconsistent_interpolations_title(forest) "Inconsistent interpolations (#{forest.leaves.count || '∅'})" end
missing_title(forest)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 21 def missing_title(forest) "Missing translations (#{forest.leaves.count || '∅'})" end
missing_type_info(type)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 17 def missing_type_info(type) ::I18n::Tasks::MissingKeys::MISSING_TYPES[type.to_s.sub(/\Amissing_/, '').to_sym] end
sort_by_attr!(objects, order = { locale: :asc, key: :asc })
click to toggle source
Sort keys by their attributes in order @param [Hash] order e.g. {locale: :asc, type: :desc, key: :asc}
# File lib/i18n/tasks/reports/base.rb, line 45 def sort_by_attr!(objects, order = { locale: :asc, key: :asc }) order_keys = order.keys objects.sort! do |a, b| by = order_keys.detect { |k| a[k] != b[k] } order[by] == :desc ? b[by] <=> a[by] : a[by] <=> b[by] end objects end
unused_title(key_values)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 29 def unused_title(key_values) "Unused keys (#{key_values.count || '∅'})" end
used_title(keys_nodes, filter)
click to toggle source
# File lib/i18n/tasks/reports/base.rb, line 37 def used_title(keys_nodes, filter) used_n = keys_nodes.map { |_k, node| node.data[:occurrences].size }.reduce(:+).to_i "#{keys_nodes.size} key#{'s' if keys_nodes.size != 1}#{" matching '#{filter}'" if filter}" \ "#{" (#{used_n} usage#{'s' if used_n != 1})" if used_n.positive?}" end