mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add safe html support to arrays of translations
This commit is contained in:
parent
242ae67ebe
commit
42c353705a
2 changed files with 10 additions and 4 deletions
|
@ -85,8 +85,11 @@ module ActionView
|
|||
end
|
||||
end
|
||||
translation = I18n.translate(scope_key_by_partial(key), html_safe_options.merge(raise: i18n_raise))
|
||||
|
||||
if translation.respond_to?(:map)
|
||||
translation.map { |element| element.respond_to?(:html_safe) ? element.html_safe : element }
|
||||
else
|
||||
translation.respond_to?(:html_safe) ? translation.html_safe : translation
|
||||
end
|
||||
else
|
||||
I18n.translate(scope_key_by_partial(key), options.merge(raise: i18n_raise))
|
||||
end
|
||||
|
|
|
@ -164,8 +164,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
|
|||
assert_equal "<a>Other <One></a>", translate(:'translations.count_html', count: "<One>")
|
||||
end
|
||||
|
||||
def test_translation_returning_an_array_ignores_html_suffix
|
||||
assert_equal ["foo", "bar"], translate(:'translations.array_html')
|
||||
def test_translate_marks_array_of_translations_with_a_html_safe_suffix_as_safe_html
|
||||
translate(:'translations.array_html').tap do |translated|
|
||||
assert_equal %w( foo bar ), translated
|
||||
assert translated.all?(&:html_safe?)
|
||||
end
|
||||
end
|
||||
|
||||
def test_translate_with_default_named_html
|
||||
|
|
Loading…
Reference in a new issue