@@ -151,15 +151,26 @@ def pluralize(locale, entry, count)
151
151
entry [ key ]
152
152
end
153
153
154
- # Interpolates values into a given string .
154
+ # Interpolates values into a given subject .
155
155
#
156
- # interpolate "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
156
+ # if the given subject is a string then:
157
+ # method interpolates "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
157
158
# # => "file test.txt opened by %{user}"
158
- def interpolate ( locale , string , values = { } )
159
- if string . is_a? ( ::String ) && !values . empty?
160
- I18n . interpolate ( string , values )
159
+ #
160
+ # if the given subject is an array then:
161
+ # each element of the array is recursively interpolated (until it finds a string)
162
+ # method interpolates ["yes, %{user}", ["maybe no, %{user}, "no, %{user}"]], :user => "bartuz"
163
+ # # => "["yes, bartuz",["maybe no, bartuz", "no, bartuz"]]"
164
+
165
+
166
+ def interpolate ( locale , subject , values = { } )
167
+ return subject if values . empty?
168
+
169
+ case subject
170
+ when ::String then I18n . interpolate ( subject , values )
171
+ when ::Array then subject . map { |element | interpolate ( locale , element , values ) }
161
172
else
162
- string
173
+ subject
163
174
end
164
175
end
165
176
0 commit comments