Sha256: 5ca89025a2d317c59c143133ab25eea8fd88721ef8fca8a63e8b6247aeaeb3b5

Contents?: true

Size: 784 Bytes

Versions: 16

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true
module ThemeCheck
  module ShopifyLiquid
    module SystemTranslations
      extend self

      def translations
        @translations ||= YAML.load(File.read("#{__dir__}/../../../data/shopify_translation_keys.yml")).to_set
      end

      def translations_hash
        @translations_hash ||= translations.reduce({}) do |acc, k|
          dig_set(acc, k.split('.'), "")
        end
      end

      def include?(key)
        translations.include?(key)
      end

      private

      def dig_set(obj, keys, value)
        key = keys.first
        if keys.length == 1
          obj[key] = value
        else
          obj[key] = {} unless obj[key]
          dig_set(obj[key], keys.slice(1..-1), value)
        end
        obj
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.14.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.13.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.12.1 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.12.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.11.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.10.3 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.10.2 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.10.1 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.10.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.9.2 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.9.1 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.9.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.8.0 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.7.2 lib/theme_check/shopify_liquid/system_translations.rb
theme-check-1.7.1 lib/theme_check/shopify_liquid/system_translations.rb