From d2ba4650e5d76f091e1426461525029df6a40868 Mon Sep 17 00:00:00 2001 From: Julius Pabrinkis Date: Thu, 8 Jun 2017 22:27:52 +0100 Subject: [PATCH] Add temporary i18n-js workaround for Spree translations until upgrade --- config/initializers/i18n-js.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 config/initializers/i18n-js.rb diff --git a/config/initializers/i18n-js.rb b/config/initializers/i18n-js.rb new file mode 100644 index 0000000000..c46e4d9177 --- /dev/null +++ b/config/initializers/i18n-js.rb @@ -0,0 +1,30 @@ +# This is coppied from https://github.com/fnando/i18n-js/blob/master/lib/i18n/js.rb +# As in spree core en.yml there are translations - +# en: +# no: "No" +# yes: "Yes" +# Which become to true and false and those have no #to_sym method +# TODO - remove this after spree core locales are fixed + +module I18n + module JS + # Filter translations according to the specified scope. + def self.filter(translations, scopes) + scopes = scopes.split(".") if scopes.is_a?(String) + scopes = scopes.clone + scope = scopes.shift + if scope == "*" + results = {} + translations.each do |scope, translations| + tmp = scopes.empty? ? translations : filter(translations, scopes) + scope_symbol = scope.respond_to?(:to_sym) ? scope.to_sym : scope.to_s.to_sym + results[scope_symbol] = tmp unless tmp.nil? + end + return results + elsif translations.respond_to?(:key?) && translations.key?(scope.to_sym) + return {scope.to_sym => scopes.empty? ? translations[scope.to_sym] : filter(translations[scope.to_sym], scopes)} + end + nil + end + end +end