Skip to content

Commit

Permalink
Use localized date formats in interpolate_hash
Browse files Browse the repository at this point in the history
Interpolated strings containing Times or Dates should respect
default formatting options and locale. This also avoids using
Rails' Time#to_s which will throw a deprecation warning if
a :default format is set.
  • Loading branch information
davidgumberg committed Aug 17, 2023
1 parent 7cf0947 commit cb79900
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/i18n/interpolate/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def interpolate_hash(string, values)
config.missing_interpolation_argument_handler.call(key, values, string)
end
value = value.call(values) if value.respond_to?(:call)
$3 ? sprintf("%#{$3}", value) : value

if value.respond_to?(:strftime)
backend.localize(locale, value)
else
$3 ? sprintf("%#{$3}", value) : value
end
end
end

Expand Down

0 comments on commit cb79900

Please sign in to comment.