Sha256: 9aabc2170e0a542fea1624dfa70ef20f6011e1c2fcc92fcc1e7b143c0b44c4ba
Contents?: true
Size: 1.24 KB
Versions: 21
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module ThemeCheck module SystemTranslations extend self def translations @translations ||= YAML.load(File.read("#{__dir__}/../../../data/shopify_translation_keys.yml")).to_set end def include?(key) translations.include?(key) end end class TranslationKeyExists < LiquidCheck severity :error category :translation doc docs_url(__FILE__) def on_variable(node) return unless @theme.default_locale_json&.content&.is_a?(Hash) return unless node.value.filters.any? { |name, _| name == "t" || name == "translate" } return unless (key_node = node.children.first) return unless key_node.value.is_a?(String) unless key_exists?(key_node.value) || SystemTranslations.include?(key_node.value) add_offense( "'#{key_node.value}' does not have a matching entry in '#{@theme.default_locale_json.relative_path}'", node: node, markup: key_node.value, ) end end private def key_exists?(key) pointer = @theme.default_locale_json.content key.split(".").each do |token| return false unless pointer.key?(token) pointer = pointer[token] end true end end end
Version data entries
21 entries across 21 versions & 1 rubygems