diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-18 21:37:28 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-18 21:37:28 +0200 |
commit | 77370f27db8b70f67756e6948a4bd4a102cdbb7a (patch) | |
tree | e3b09ec5349a8d1039b8395f27e919df73995190 /actionview | |
parent | d4a2470f89c4f1edb8bd21d59008af8ad664369f (diff) | |
parent | 0f138d1a8b2b6b361e1fc1fea2bb927bce66b909 (diff) | |
download | rails-77370f27db8b70f67756e6948a4bd4a102cdbb7a.tar.gz rails-77370f27db8b70f67756e6948a4bd4a102cdbb7a.tar.bz2 rails-77370f27db8b70f67756e6948a4bd4a102cdbb7a.zip |
Merge pull request #21632 from kirs/feature/translation-helper-include-interpolation
Include interpolation values to translation_missing helper
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/translation_helper.rb | 9 | ||||
-rw-r--r-- | actionview/test/template/translation_helper_test.rb | 6 |
2 files changed, 14 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/translation_helper.rb b/actionview/lib/action_view/helpers/translation_helper.rb index 0615bd2e0d..dde1ef22ac 100644 --- a/actionview/lib/action_view/helpers/translation_helper.rb +++ b/actionview/lib/action_view/helpers/translation_helper.rb @@ -88,7 +88,14 @@ module ActionView 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 diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 749d0dd7fd..261576bead 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -60,6 +60,12 @@ class TranslationHelperTest < ActiveSupport::TestCase 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: &quot; onclick=&quot;alert()&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 |