Missing translations keys — Gotta Catch ’Em All
Published in
1 min readOct 23, 2018
A few years back, Rails 4.1.0 introducedraise_on_missing_translations
flag for Action View. Setting this key to true
in your environment configuration will make Rails raises exception if you have a missing translation keys:
# In config/environments/test.rb (and development.rb)
config.action_view.raise_on_missing_translations = true
However, one thing that people may have missed is that this configuration only applies to Rails views. If you call I18n.translate
or I18n.t
directly from your specs, or when you build a JSON output, Rails won’t raise any exception at all.
So, instead, you will want to directly set an I18n
exception handler like this:
# config/initializers/i18n.rb
if Rails.env.in?(%(development test))
I18n.exception_handler = Proc.new do |exception, *_|
raise exception.to_exception
end
end