1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #22462 from lxsameer/i18n_html_wrap

wrapping i18n missing keys made optional
This commit is contained in:
Rafael França 2015-12-18 18:47:59 -02:00
commit cbf827bc9c
5 changed files with 32 additions and 0 deletions

View file

@ -1,3 +1,12 @@
* `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.

View file

@ -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 @@ module ActionView
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

View file

@ -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

View file

@ -54,6 +54,16 @@ class TranslationHelperTest < ActiveSupport::TestCase
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")

View file

@ -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`: