File tree 3 files changed +19
-20
lines changed
activesupport/lib/active_support
3 files changed +19
-20
lines changed Original file line number Diff line number Diff line change @@ -28,18 +28,7 @@ def translate(key, **options)
28
28
end
29
29
end
30
30
31
- if options [ :raise ] . nil?
32
- options [ :default ] = [ ] unless options [ :default ]
33
- options [ :default ] << MISSING_TRANSLATION
34
- end
35
-
36
- result = ActiveSupport ::HtmlSafeTranslation . translate ( key , **options )
37
-
38
- if result == MISSING_TRANSLATION
39
- +"translation missing: #{ key } "
40
- else
41
- result
42
- end
31
+ ActiveSupport ::HtmlSafeTranslation . translate ( key , **options )
43
32
end
44
33
alias :t :translate
45
34
@@ -48,9 +37,5 @@ def localize(object, **options)
48
37
I18n . localize ( object , **options )
49
38
end
50
39
alias :l :localize
51
-
52
- private
53
- MISSING_TRANSLATION = -( 2 **60 )
54
- private_constant :MISSING_TRANSLATION
55
40
end
56
41
end
Original file line number Diff line number Diff line change @@ -146,15 +146,19 @@ def test_translate_escapes_interpolations_in_translations_with_a_html_suffix
146
146
def test_translate_marks_translation_with_missing_html_key_as_safe_html
147
147
@controller . stub :action_name , :index do
148
148
translation = @controller . t ( "<tag>.html" )
149
- assert_equal "translation missing: <tag>.html" , translation
150
149
assert_equal false , translation . html_safe?
150
+ assert_equal "Translation missing: en.<tag>.html" , translation
151
151
end
152
152
end
153
153
def test_translate_marks_translation_with_missing_nested_html_key_as_safe_html
154
154
@controller . stub :action_name , :index do
155
155
translation = @controller . t ( ".<tag>.html" )
156
- assert_equal "translation missing: abstract_controller.testing.translation.index.<tag>.html" , translation
157
156
assert_equal false , translation . html_safe?
157
+ assert_equal ( <<~MSG . strip , translation )
158
+ Translation missing. Options considered were:
159
+ - en.abstract_controller.testing.translation.index.<tag>.html
160
+ - en.abstract_controller.testing.translation.<tag>.html
161
+ MSG
158
162
end
159
163
end
160
164
end
Original file line number Diff line number Diff line change @@ -7,8 +7,18 @@ module HtmlSafeTranslation # :nodoc:
7
7
def translate ( key , **options )
8
8
if html_safe_translation_key? ( key )
9
9
html_safe_options = html_escape_translation_options ( options )
10
- translation = I18n . translate ( key , **html_safe_options )
11
- html_safe_translation ( translation )
10
+
11
+ exception = false
12
+ exception_handler = -> ( *args ) do
13
+ exception = true
14
+ I18n . exception_handler . call ( *args )
15
+ end
16
+ translation = I18n . translate ( key , **html_safe_options , exception_handler : exception_handler )
17
+ if exception
18
+ translation
19
+ else
20
+ html_safe_translation ( translation )
21
+ end
12
22
else
13
23
I18n . translate ( key , **options )
14
24
end
You can’t perform that action at this time.
0 commit comments