2

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!

nickh
  • 4,721
  • 2
  • 29
  • 31

3 Answers3

2

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
thesis
  • 2,565
  • 5
  • 26
  • 37
  • Thanks for the suggestion, @thesis. Unfortunately, that results in the same output from ActionView's `#t`. – nickh May 29 '12 at 00:29
  • @Ashitaka Yeah, I restarted the server after making that change. Also, the "fallbacks" option controls whether or not a failed translation tries to use the corresponding translation in the default locale. So it won't prevent the mangling that I'm trying to avoid. – nickh May 29 '12 at 12:36
1

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.

Christoph Petschnig
  • 4,047
  • 1
  • 37
  • 46
  • Interesting. Thanks for the gist, Christoph. I guess you'd have to grep through the log every so often to look for failed translations. – nickh May 29 '12 at 12:37
  • Instead of grepping one should rather write the output to a database plus count the occurrence. I use my gist to discover failed translations while developing (or finding the correct key when building the locale file). – Christoph Petschnig May 29 '12 at 12:52
0

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

starball
  • 20,030
  • 7
  • 43
  • 238