提交 cbf827bc 编写于 作者: R Rafael França

Merge pull request #22462 from lxsameer/i18n_html_wrap

wrapping i18n missing keys made optional
* `I18n.translate` helper will wrap the missing translation keys
in a <span> tag only if `debug_missing_translation` configuration
be true. Default value is `true`. For example in `application.rb`:
# in order to turn off missing key wrapping
config.action_view.debug_missing_tranlation = false
*Sameer Rahmani*
* Respect value of `:object` if `:object` is false when rendering.
Fixes #22260.
......
......@@ -6,7 +6,15 @@ module ActionView
# = Action View Translation Helpers
module Helpers
module TranslationHelper
extend ActiveSupport::Concern
include TagHelper
included do
mattr_accessor :debug_missing_translation
self.debug_missing_translation = true
end
# Delegates to <tt>I18n#translate</tt> but also performs three additional
# functions.
#
......@@ -95,6 +103,8 @@ def translate(key, options = {})
title << ", " << interpolations.map { |k, v| "#{k}: #{ERB::Util.html_escape(v)}" }.join(', ')
end
return title unless ActionView::Base.debug_missing_translation
content_tag('span', keys.last.to_s.titleize, class: 'translation_missing', title: title)
end
end
......
......@@ -6,6 +6,7 @@ module ActionView
class Railtie < Rails::Railtie # :nodoc:
config.action_view = ActiveSupport::OrderedOptions.new
config.action_view.embed_authenticity_token_in_remote_forms = false
config.action_view.debug_missing_translation = true
config.eager_load_namespaces << ActionView
......
......@@ -54,6 +54,16 @@ def test_delegates_localize_to_i18n
end
end
def test_returns_missing_tranlation_message_without_span_wrap
old_value = ActionView::Base.debug_missing_translation
ActionView::Base.debug_missing_translation = false
expected = 'translation missing: en.translations.missing'
assert_equal expected, translate(:"translations.missing")
ensure
ActionView::Base.debug_missing_translation = old_value
end
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")
......
......@@ -461,6 +461,8 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
* `config.action_view.automatically_disable_submit_tag` determines whether
submit_tag should automatically disable on click, this defaults to true.
* `config.action_view.debug_missing_translation` determins whether to wrap the missing translations key in a `<span>` tag or not. This defaults to true.
### Configuring Action Mailer
There are a number of settings available on `config.action_mailer`:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册