Show missing I18n translations in views

2.8k views Asked by At

As stated in ActionView's documentation, the t view helper in Rails automatically mangles missing translations. Eg:

irb> helper.t('words.foo_bar')
=> "<span class="translation_missing" title="translation missing: en.words.foo_bar">Foo Bar</span>"

Is there any way to disable this globally? I'd much rather see "translation missing: en.words.asdf" .

The only workaround that I've found is to use I18n.t "..." instead of t "..." in views.

Thanks!

3

There are 3 answers

2
Christoph Petschnig On

I have this file in my config/initializers directory, which shows me all translation lookups that failed and where they originated from in the log output: https://gist.github.com/1594660

Maybe this is exactly what you are looking for.

2
thesis On

Try to put this code in your development.rb

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = false
0
ramiro lopes canadell On

The solution I found to show the "translation missing" instead of the span tag is to put this in my initializer:

config.action_view.debug_missing_translation = false

This is explained in the Rails guides here: https://guides.rubyonrails.org/v5.2.0/configuring.html#configuring-action-view