From cb79900004d12c7dced6b4cb8357ed604cf3714b Mon Sep 17 00:00:00 2001 From: David Gumberg Date: Thu, 17 Aug 2023 01:31:43 -0400 Subject: [PATCH] Use localized date formats in `interpolate_hash` 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. --- lib/i18n/interpolate/ruby.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/i18n/interpolate/ruby.rb b/lib/i18n/interpolate/ruby.rb index 5b50593f..b2dc365d 100644 --- a/lib/i18n/interpolate/ruby.rb +++ b/lib/i18n/interpolate/ruby.rb @@ -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