From efeda61e4026591e6db6de2595209c307f28e3c3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 6 Jul 2020 15:21:16 +0100 Subject: [PATCH] Bring i18n.rb from spree --- lib/spree/i18n.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/spree/i18n.rb diff --git a/lib/spree/i18n.rb b/lib/spree/i18n.rb new file mode 100644 index 0000000000..12cd95a2fb --- /dev/null +++ b/lib/spree/i18n.rb @@ -0,0 +1,36 @@ +require 'i18n' +require 'active_support/core_ext/array/extract_options' +require 'spree/i18n/base' + +module Spree + extend ActionView::Helpers::TranslationHelper + + 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 + if context + path = context.instance_variable_get("@virtual_path") + + if path + path.gsub(/spree/, '') + end + end + end + end +end