nickh
nickh

Reputation: 4841

Show missing I18n translations in views

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!

Upvotes: 2

Views: 2982

Answers (3)

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

Upvotes: 0

Christoph Petschnig
Christoph Petschnig

Reputation: 4157

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.

Upvotes: 1

thesis
thesis

Reputation: 2575

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

Upvotes: 2

Related Questions