mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-22 05:18:51 +00:00
Add temporary i18n-js workaround for Spree translations until upgrade
This commit is contained in:
committed by
Maikel Linke
parent
3adb13e62c
commit
d2ba4650e5
30
config/initializers/i18n-js.rb
Normal file
30
config/initializers/i18n-js.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user