raise_on_missing_translations in controller

137 views
Skip to first unread message

Wojtek Kruszewski

unread,
Jun 2, 2015, 3:30:11 AM6/2/15
to rubyonra...@googlegroups.com
`config.action_view.raise_on_missing_translations` is used in ActionView::Helpers::TranslationHelper 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 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.

-- 
Reply all
Reply to author
Forward
0 new messages