44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/storefront/helpers/content_helper.rb', line 44
def t?(key, options = {})
return key if key.is_a?(::String) || key.blank?
models = Storefront::Model.model_names(options[:model] || options[:models] || options[:model_names] || storefront_config.current_scope[:resource] || [])
models << "" if models.blank?
namespaces = Array(options[:namespaces] || options[:namespace] || storefront_config.current_scope[:namespace])
namespaces << "" if namespaces.blank? && !!storefront_config.localize_with_namespace
action_name = options[:action] || storefront_config.current_scope[:action]
defaults = []
allow_blank = options[:allow_blank] == true
count = options[:count]
count_key = count != 1 ? :other : :one
keys = [key.to_s]
if options.has_key?(:present) || options.has_key?(:past) || options.has_key?(:future)
if options[:future] == true
tense_key = :future
else
tense_key = (options[:present] == true || options[:past] == false) ? :present : :past
end
else
tense_key = nil
end
if options.has_key?(:nested_model)
with_nested_model = !!options[:nested_model]
else
with_nested_model = !!storefront_config.localize_with_nested_model
end
if options.has_key?(:namespace)
with_namespace = !!options[:namespace]
else
with_namespace = !!storefront_config.localize_with_namespace
end
if with_nested_model && with_namespace
SCOPES_WITH_NAMESPACE_AND_NESTED_MODEL
elsif with_nested_model
SCOPES_WITH_NESTED_MODEL
elsif with_namespace
namespaces.each do |namespace|
keys.each do |_key|
SCOPES_WITH_NAMESPACE.each do |_path|
models.each do |model|
path = _path.dup
path.gsub!('%{namespace}', namespace)
path.gsub!('%{model}', model)
path.gsub!('%{action}', action_name)
path.gsub!('%{attribute}', _key)
path.gsub!('..', '.')
defaults << path
end
end
end
end
else
keys.each do |_key|
SCOPES.each do |_path|
models.each do |model|
path = _path.dup
path.gsub!('%{model}', model)
path.gsub!('%{action}', action_name)
path.gsub!('%{attribute}', _key)
path.gsub!('..', '.')
defaults << path
end
end
end
end
[:past, :present, :future, :allow_blank, :model, :models, :model_names, :action, :nested_model, :namespace, :namespaces].each do |key|
options.delete(key)
end
defaults.map!(&:to_sym)
defaults << ''
value = I18n.t(defaults.shift, options.merge(:default => defaults))
if value.is_a?(::Hash)
if value.has_key?(count_key)
value = value[count_key]
elsif value.has_key?(tense_key)
value = value[tense_key]
if value.is_a?(::Hash) && value.has_key?(count_key)
value = value[count_key]
end
elsif value.has_key?(count_key)
value = value[count_key]
end
end
if value.is_a?(::Hash)
if value.has_key?(:one)
value = value[:one]
end
end
if value.is_a?(::Hash)
if value.has_key?(:present)
value = value[:present]
elsif value.has_key?(:past)
value = value[:past]
elsif value.has_key?(:future)
value = value[:future]
end
end
[:scope].each do |key|
options.delete(key)
end
if value.blank? && !allow_blank
key.to_s.split(".").last.titleize
elsif options.present?
I18n.interpolate(value, options)
else
value
end
end
|