Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Overwrite `t` helper in Rails views to raise in tests, which it otherwise doesn't do, even if I18n is configured to.

View lib-i18n_raise_on_missing_in_action_view.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Overwrite `t` helper in Rails views to raise in tests,
# which it otherwise doesn't do, even if I18n is configured to.
#
# Installation:
# put in lib/i18n_raise_on_missing_in_action_view.rb
# and require "i18n_raise_on_missing_in_action_view" in e.g. config/environments/test.rb
 
if Rails.env.test?
module ActionView::Helpers::TranslationHelper
def t_with_raise(*args)
value = t_without_raise(*args)
 
if value.to_s.match(/title="translation missing: (.+)"/)
raise "Translation missing: #{$1}"
else
value
end
end
alias_method :translate_with_raise, :t_with_raise
 
alias_method_chain :t, :raise
alias_method_chain :translate, :raise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.