我创建了新的 Rails 3 项目。我尝试在我的观点中使用这样的翻译:
= t('.translate_test')
在我的浏览器中我看起来"translate_test"
反而"my test translation"
我设置的女巫en.yml.
我的主要问题 - 为什么我看不到类似的错误"Missing translation: en ..."
?
我创建了这个初始化程序raise
异常 - 参数被传递,这样你就会知道缺少哪个 i18n 键!
# 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 http://guides.rubyonrails.org/i18n.html#using-different-exception-handlers
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)