Skip to content

Commit

Permalink
Refactor interpolation method
Browse files Browse the repository at this point in the history
Suggested by @clemens
  • Loading branch information
Bartuz authored and stereobooster committed Nov 9, 2017
1 parent 321bc1b commit ae859dd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/i18n/backend/base.rb
Expand Up @@ -151,13 +151,15 @@ def pluralize(locale, entry, count)
#
# interpolate "file %{file} opened by %%{user}", :file => 'test.txt', :user => 'Mr. X'
# # => "file test.txt opened by %{user}"
def interpolate(locale, string, values = {})
if string.is_a?(::String) && !values.empty?
I18n.interpolate(string, values)
elsif string.is_a?(::Array) && !values.empty?
string.map { |el| interpolate(locale, el, values) }

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

case subject
when ::String then I18n.interpolate(subject, values)
when ::Array then subject.map { |element| interpolate(locale, element, values) }
else
string
subject
end
end

Expand Down

0 comments on commit ae859dd

Please sign in to comment.