`config.action_view.raise_on_missing_translations` is used in 
ActionView::Helpers::TranslationHelper 
<https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/translation_helper.rb>
 
to re-raise exceptions on missing translation.

However, when you call `translate` from controller (e.g. redirect_to path,
 notice: t(".done")) this setting has no effect. This is because 
AbstractController::Translation#translate 
<https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/translation.rb>
 
calls I18n.translate directly, and doesn't go through TranslationHelper

Yes, obviously the config option is scoped to "action_view" but still I 
found it pretty surprising.

I wanted raise behaviour by default in controllers to, so I added this to 
ApplicationController:

  def translate(key, options={})
    super(key, options.reverse_merge(raise: ActionView::Base.
raise_on_missing_translations))
  end
  alias :t :translate

It'd be great though to have a universal raise_on_missing_translations 
option in Rails.

-- 
Kruszewski.com <http://www.Kruszewski.com>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to