当我打电话时:
t 'to_translate'
我的模板中的方法,我希望它在不实际传递第二个参数的情况下引发错误,如下所示:
t 'to_translate', :raise => true
这将节省我在每次翻译中的大量输入。或者有解决方法吗?
感谢您的回答。
当我打电话时:
t 'to_translate'
我的模板中的方法,我希望它在不实际传递第二个参数的情况下引发错误,如下所示:
t 'to_translate', :raise => true
这将节省我在每次翻译中的大量输入。或者有解决方法吗?
感谢您的回答。
您可以在I18n 文档第 6.2 段中找到答案
“[..] 默认异常处理不允许在自动化测试期间轻松捕获丢失的翻译。为此,可以指定不同的异常处理程序。指定的异常处理程序必须是 I18n 模块上的方法或带有#call 的类方法:
module I18n
class JustRaiseExceptionHandler < ExceptionHandler
def call(exception, locale, key, options)
if exception.is_a?(MissingTranslation)
raise exception.to_exception
else
super
end
end
end
end
I18n.exception_handler = I18n::JustRaiseExceptionHandler.new
这只会重新引发 MissingTranslationData 异常,将所有其他输入传递给默认异常处理程序。”
在http://guides.rubyonrails.org/i18n.html#using-different-exception-handlers上了解更多信息