Skip to content

Commit 23069aa

Browse files
Bartuzstereobooster
authored andcommitted
Add comments exaplining new array behaviour for #interpolate
1 parent ae859dd commit 23069aa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/i18n/backend/base.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,17 @@ def pluralize(locale, entry, count)
147147
entry[key]
148148
end
149149

150-
# Interpolates values into a given string.
150+
# Interpolates values into a given subject.
151151
#
152-
# interpolate "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
152+
# if the given subject is a string then:
153+
# method interpolates "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
153154
# # => "file test.txt opened by %{user}"
155+
#
156+
# if the given subject is an array then:
157+
# each element of the array is recursively interpolated (until it finds a string)
158+
# method interpolates ["yes, %{user}", ["maybe no, %{user}, "no, %{user}"]], :user => "bartuz"
159+
# # => "["yes, bartuz",["maybe no, bartuz", "no, bartuz"]]"
160+
154161

155162
def interpolate(locale, subject, values = {})
156163
return subject if values.empty?

0 commit comments

Comments
 (0)