Skip to content

Commit 8624996

Browse files
committed
Make MissingTranslation exception handler respect :rescue_format
1 parent 5daef25 commit 8624996

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

actionpack/lib/action_view/helpers/translation_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ module I18n
55
class ExceptionHandler
66
include Module.new {
77
def call(exception, locale, key, options)
8-
exception.is_a?(MissingTranslation) ? super.html_safe : super
8+
if exception.is_a?(MissingTranslation)
9+
options[:rescue_format] == :html ? super.html_safe : super
10+
else
11+
super
12+
end
913
end
1014
}
1115
end

actionpack/test/template/translation_helper_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,19 @@ def test_delegates_localize_to_i18n
3838
def test_returns_missing_translation_message_wrapped_into_span
3939
expected = '<span class="translation_missing" title="translation missing: en.translations.missing">Missing</span>'
4040
assert_equal expected, translate(:"translations.missing")
41+
assert_equal true, translate(:"translations.missing").html_safe?
4142
end
4243

4344
def test_returns_missing_translation_message_using_nil_as_rescue_format
4445
expected = 'translation missing: en.translations.missing'
4546
assert_equal expected, translate(:"translations.missing", :rescue_format => nil)
47+
assert_equal false, translate(:"translations.missing", :rescue_format => nil).html_safe?
48+
end
49+
50+
def test_i18n_translate_defaults_to_nil_rescue_format
51+
expected = 'translation missing: en.translations.missing'
52+
assert_equal expected, I18n.translate(:"translations.missing")
53+
assert_equal false, I18n.translate(:"translations.missing").html_safe?
4654
end
4755

4856
def test_translation_returning_an_array

0 commit comments

Comments
 (0)