Class: I18n::Hygiene::Checks::MissingInterpolationVariable

Inherits:
Base
  • Object
show all
Defined in:
lib/i18n/hygiene/checks/missing_interpolation_variable.rb

Overview

Looks for translations which are missing interpolation variables.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from I18n::Hygiene::Checks::Base

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/i18n/hygiene/checks/missing_interpolation_variable.rb', line 13

def run
  wrapper = I18n::Hygiene::Wrapper.new(
    exclude_keys: config.exclude_keys,
    exclude_scopes: config.exclude_scopes
  )

  wrapper.keys_to_check(config.primary_locale).select do |key|
    checker = I18n::Hygiene::VariableChecker.new(key, wrapper, config.primary_locale, config.locales)

    checker.mismatched_variables do |locale, key, missing_variables|
      if missing_variables.any?
        message = ErrorMessageBuilder.new
          .title("Missing interpolation variable(s)")
          .locale(locale)
          .key(key)
          .translation(wrapper.value(locale, key))
          .expected(missing_variables.join(", "))
          .create

        yield Result.new(:failure, message: message)
      end
    end
  end
end