Class: I18n::Hygiene::Checks::ScriptTag

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

Overview

Looks for unexpected script tags in translations.

Constant Summary collapse

SCRIPT_TAG_REGEX =
/<script.*/

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/i18n/hygiene/checks/script_tag.rb', line 15

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

  keys_with_script_tags = I18n::Hygiene::KeysWithMatchedValue.new(SCRIPT_TAG_REGEX, wrapper)

  keys_with_script_tags.each do |locale, key|
    message = ErrorMessageBuilder.new
      .title("Unexpected script tag")
      .locale(locale)
      .key(key)
      .translation(wrapper.value(locale, key))
      .create

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