rails: I18n locale fallbacks for localized views don't work for mailers

Pull request #7368 recently fixed issues #3512 and #840 related to fallbacks for localized views for views rendered by controllers.

However the locale fallbacks are still broken for mailer views.

Having the locale set to de-at, and a file called app/views/mailer/demo.de.erb, trying to build the mail results in an ActionView::MissingTemplate exception:

ActionView::MissingTemplate: Missing template mailer/demo with {:locale=>[:"de-at"], :formats=>[:text], :handlers=>[:erb, :builder, :coffee]}. Searched in:
  * "/Users/benedikt/demo/app/views"

The issue is related to ActionView::LookupContext#skip_default_locale!, which is only called from within ActionMailer::Base:

I18n.locale = 'de-at'
context = Mailer(:new).lookup_context
context.find_all "mailer/demo" # => [app/views/mailer/demo.de.markerb]
context.skip_default_locale!
context.find_all "mailer/demo" # => []

However: The issue is not related to the value I18n.default_locale is set to, changing this to something else (even nonsense), doesn’t affect this issue.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

@robinboening, thanks for the tip on gem-patching. There is a newer version at this link https://github.com/ingoweiss/gem-patching (notice the dash vs underscore) where the author responded to https://github.com/ingoweiss/gem_patching/issues/2. The new version supports Gem::Requirement restriction operators so you can do this:

Gem.patching('actionview', '< 5') do
  class ActionView::LookupContext
    def skip_default_locale!
    end
  end
end