Skip to content

Commit ada3d77

Browse files
committed
Use Kernel#Array to wrap the default value
1 parent d216d1e commit ada3d77

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

actionpack/lib/abstract_controller/translation.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ def translate(key, **options)
2323
key = "#{path}.#{action_name}#{key}"
2424
end
2525

26-
if ActiveSupport::HtmlSafeTranslation.html_safe_translation_key?(key)
27-
if options[:default]
28-
options[:default] = [options[:default]] unless options[:default].is_a?(Array)
29-
options[:default] = options[:default].map do |value|
30-
value.is_a?(String) ? ERB::Util.html_escape(value) : value
31-
end
26+
if options[:default] && ActiveSupport::HtmlSafeTranslation.html_safe_translation_key?(key)
27+
options[:default] = Array(options[:default]).map do |value|
28+
value.is_a?(String) ? ERB::Util.html_escape(value) : value
3229
end
3330
end
3431

activesupport/lib/active_support/html_safe_translation.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ def translate(key, **options)
99
html_safe_options = html_escape_translation_options(options)
1010

1111
exception = false
12+
1213
exception_handler = ->(*args) do
1314
exception = true
1415
I18n.exception_handler.call(*args)
1516
end
17+
1618
translation = I18n.translate(key, **html_safe_options, exception_handler: exception_handler)
19+
1720
if exception
1821
translation
1922
else

0 commit comments

Comments
 (0)