Skip to content

Commit

Permalink
Make MissingTranslation exception handler respect :rescue_format
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix committed Jun 15, 2011
1 parent 4a96ab4 commit 190101e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion actionpack/lib/action_view/helpers/translation_helper.rb
Expand Up @@ -5,7 +5,11 @@ module I18n
class ExceptionHandler
include Module.new {
def call(exception, locale, key, options)
exception.is_a?(MissingTranslationData) ? super.html_safe : super
if exception.is_a?(MissingTranslationData)
options[:rescue_format] == :html ? super.html_safe : super
else
super
end
end
}
end
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/translation_helper_test.rb
Expand Up @@ -38,11 +38,19 @@ def test_delegates_localize_to_i18n
def test_returns_missing_translation_message_wrapped_into_span
expected = '<span class="translation_missing" title="translation missing: en.translations.missing">Missing</span>'
assert_equal expected, translate(:"translations.missing")
assert_equal true, translate(:"translations.missing").html_safe?
end

def test_returns_missing_translation_message_using_nil_as_rescue_format
expected = 'translation missing: en.translations.missing'
assert_equal expected, translate(:"translations.missing", :rescue_format => nil)
assert_equal false, translate(:"translations.missing", :rescue_format => nil).html_safe?
end

def test_i18n_translate_defaults_to_nil_rescue_format
expected = 'translation missing: en.translations.missing'
assert_equal expected, I18n.translate(:"translations.missing")
assert_equal false, I18n.translate(:"translations.missing").html_safe?
end

def test_translation_returning_an_array
Expand Down

0 comments on commit 190101e

Please sign in to comment.