Rails 3 Translation Missing Error

posted on Tuesday, February 08, 2011

In one of my projects I had to use I18n and I had a problem always seeing something like:
translation missing: ru.activerecord.errors.messages.record_invalid when there is no translation found.
I prefer to see default English translation if there is a translation missing error, why not ?
Especially in development mode.
So here is a small piece of code that you can put into config/initializers folder:

module I18n
  def self.custom_handler(exception, locale, key, options)
    case exception
    when I18n::MissingTranslationData
      I18n::Backend::Simple.new.translate(:en, key, options || {})
    else
      raise exception
    end
  end
end
I18n.exception_handler = :custom_handler
Continue reading