# frozen_string_literal: true

require 'i18n'
require 'active_support/core_ext/array/extract_options'
require 'spree/i18n/base'

module Spree
  extend ActionView::Helpers::TranslationHelper
  extend ActionView::Helpers::TagHelper if ENV['DEPENDENCIES_NEXT']

  class << self
    # Add spree namespace and delegate to Rails TranslationHelper for some nice
    # extra functionality. e.g return reasonable strings for missing translations
    def translate(*args)
      @virtual_path = virtual_path

      options = args.extract_options!
      options[:scope] = [*options[:scope]].unshift(:spree)
      args << options
      super(*args)
    end

    alias_method :t, :translate

    def context
      Spree::ViewContext.context
    end

    def virtual_path
      return unless context

      path = context.instance_variable_get("@virtual_path")

      return unless path

      path.gsub(/spree/, '')
    end
  end
end

# frozen_string_literal: true

require 'i18n'
require 'active_support/core_ext/array/extract_options'
require 'spree/i18n/base'

module Spree
  extend ActionView::Helpers::TranslationHelper
  extend ActionView::Helpers::TagHelper

  class << self
    # Add spree namespace and delegate to Rails TranslationHelper for some nice
    # extra functionality. e.g return reasonable strings for missing translations
    def translate(*args)
      @virtual_path = virtual_path

      options = args.extract_options!
      options[:scope] = [*options[:scope]].unshift(:spree)
      args << options
      super(*args)
    end

    alias_method :t, :translate

    def context
      Spree::ViewContext.context
    end

    def virtual_path
      return unless context

      path = context.instance_variable_get("@virtual_path")

      return unless path

      path.gsub(/spree/, '')
    end
  end
end

Apply an upstream fix to Spree::I18n
Apply an upstream fix to Spree::I18n

See: https://github.com/spree/spree/commit/fe95f637c988044f3af040a043cdbcff84935295

Fixes error mentioned in the above Spree commit.
