I created new Rails 3 project. I try to use translations in my views like this:
= t('.translate_test')
In my browser i looks "translate_test"
instead "my test translation"
witch i set in en.yml.
My main question - why i can't see error like "Missing translation: en ..."
?
I've created this initializer to raise
an exception - args are passed so you will know which i18n key is missing!
# only for development and test
if Rails.env.development? || Rails.env.test?
# raises exception when there is a wrong/no i18n key
module I18n
class JustRaiseExceptionHandler < ExceptionHandler
def call(exception, locale, key, options)
if exception.is_a?(MissingTranslationData)
raise exception.to_exception
else
super
end
end
end
end
I18n.exception_handler = I18n::JustRaiseExceptionHandler.new
end
Source
In Rails 3 they don't show you this text anymore. If you inspect the element in the html source you will see the translation missing message.
You can turn fallbacks off, try to put in your environment or an initializer the following:
config.i18n.fallbacks = false
I use the simplest and view specific solution to display the errors in View when the translation is missing by adding this style in your application.css.scss or any global stylesheet:
.translation_missing{
font-size: 30px;
color: red;
font-family: Times;
&:before{
content: "Translation Missing :: ";
font-size: 30px;
font-family: Times;
color: red;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With