rails-template icon indicating copy to clipboard operation
rails-template copied to clipboard

Configure I18n to raise an error when translations are missing in test mode

Open joshmcarthur opened this issue 2 years ago • 4 comments

Quite a few of our applications use I18n to try and separate content from code. Quite often, we end up accidentally using a fallback translation value, when we intended for an actual value to be present. To defend against that, often our tests will use I18n.t! to raise when it can't find a value. I think a more elegant solution would be just to tell ActionView to raise an error at that point when our translations are missing, rather than rely on the test writer to check. This is likely to cause some short-term pain, since sometimes the fallback value is sufficient for the feature, but will result in a higher-quality application at the end of the day.

I would be open to adding this to development.rb as well, but I'm unsure how much it would interfere with trying to prototype up a template for a feature.

joshmcarthur avatar Aug 15 '22 21:08 joshmcarthur

+1 for adding it to development as well

robotdana avatar Aug 15 '22 22:08 robotdana

i think more recent rails versions had a version of this config that also raised for non action_view contexts, i'll see if i can find it

robotdana avatar Aug 15 '22 22:08 robotdana

https://github.com/rails/rails/pull/31571

robotdana avatar Aug 15 '22 22:08 robotdana

Nice, I'll update to use that. I was just making a quick edit based on a google based on a "Why am I typing I18n.t! again". I expect the build failures are due to missing translations in our generated apps, which is maybe a good justification for this anyway.

joshmcarthur avatar Aug 15 '22 22:08 joshmcarthur