提交 42c35370 编写于 作者: J Juan Broullon

Add safe html support to arrays of translations

上级 242ae67e
...@@ -85,8 +85,11 @@ def translate(key, options = {}) ...@@ -85,8 +85,11 @@ def translate(key, options = {})
end end
end end
translation = I18n.translate(scope_key_by_partial(key), html_safe_options.merge(raise: i18n_raise)) translation = I18n.translate(scope_key_by_partial(key), html_safe_options.merge(raise: i18n_raise))
if translation.respond_to?(:map)
translation.respond_to?(:html_safe) ? translation.html_safe : translation translation.map { |element| element.respond_to?(:html_safe) ? element.html_safe : element }
else
translation.respond_to?(:html_safe) ? translation.html_safe : translation
end
else else
I18n.translate(scope_key_by_partial(key), options.merge(raise: i18n_raise)) I18n.translate(scope_key_by_partial(key), options.merge(raise: i18n_raise))
end end
......
...@@ -164,8 +164,11 @@ def test_translate_with_html_count ...@@ -164,8 +164,11 @@ def test_translate_with_html_count
assert_equal "<a>Other &lt;One&gt;</a>", translate(:'translations.count_html', count: "<One>") assert_equal "<a>Other &lt;One&gt;</a>", translate(:'translations.count_html', count: "<One>")
end end
def test_translation_returning_an_array_ignores_html_suffix def test_translate_marks_array_of_translations_with_a_html_safe_suffix_as_safe_html
assert_equal ["foo", "bar"], translate(:'translations.array_html') translate(:'translations.array_html').tap do |translated|
assert_equal %w( foo bar ), translated
assert translated.all?(&:html_safe?)
end
end end
def test_translate_with_default_named_html def test_translate_with_default_named_html
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册