Module: I18n::Tasks::Interpolations

Included in:
BaseTask
Defined in:
lib/i18n/tasks/interpolations.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.variable_regexObject

Returns the value of attribute variable_regex.



6
7
8
# File 'lib/i18n/tasks/interpolations.rb', line 6

def variable_regex
  @variable_regex
end

Instance Method Details

#inconsistent_interpolations(locales: nil, base_locale: nil) ⇒ Object

rubocop:disable Metrics/AbcSize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/i18n/tasks/interpolations.rb', line 10

def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize
  locales ||= self.locales
  base_locale ||= self.base_locale
  result = empty_forest
  variable_regex = I18n::Tasks::Interpolations.variable_regex

  data[base_locale].key_values.each do |key, value|
    next if !value.is_a?(String) || ignore_key?(key, :inconsistent_interpolations)

    base_vars = Set.new(value.scan(variable_regex))
    (locales - [base_locale]).each do |current_locale|
      node = data[current_locale].first.children[key]
      next unless node&.value.is_a?(String)

      if base_vars != Set.new(node.value.scan(variable_regex))
        result.merge!(node.walk_to_root.reduce(nil) { |c, p| [p.derive(children: c)] })
      end
    end
  end

  result.each { |root| root.data[:type] = :inconsistent_interpolations }
  result
end