Skip to content

Commit

Permalink
Include interpolation values to translation_missing helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kirs committed Sep 18, 2015
1 parent a8f4568 commit 0f138d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion actionview/lib/action_view/helpers/translation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ def translate(key, options = {})
raise e if raise_error

keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope])
content_tag('span', keys.last.to_s.titleize, :class => 'translation_missing', :title => "translation missing: #{keys.join('.')}")
title = "translation missing: #{keys.join('.')}"

interpolations = options.except(:default)
if interpolations.any?
title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(', ')
end

content_tag('span', keys.last.to_s.titleize, class: 'translation_missing', title: title)
end
end
alias :t :translate
Expand Down
6 changes: 6 additions & 0 deletions actionview/test/template/translation_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def test_returns_missing_translation_message_wrapped_into_span
assert_equal true, translate(:"translations.missing").html_safe?
end

def test_returns_missing_translation_message_with_unescaped_interpolation
expected = '<span class="translation_missing" title="translation missing: en.translations.missing, name: Kir, year: 2015, vulnerable: &amp;quot; onclick=&amp;quot;alert()&amp;quot;">Missing</span>'
assert_equal expected, translate(:"translations.missing", name: "Kir", year: "2015", vulnerable: %{" onclick="alert()"})
assert translate(:"translations.missing").html_safe?
end

def test_raises_missing_translation_message_with_raise_config_option
ActionView::Base.raise_on_missing_translations = true

Expand Down

0 comments on commit 0f138d1

Please sign in to comment.