我正在使用Ruby on Rails 3.1.0和I18n gem。我想在运行时检查I18n是否缺少翻译键/值对,如果是,则使用自定义字符串。也就是说,我有:
validates :link_url,
:format => {
:with => REGEX,
:message => I18n.t(
'custom_invalid_format',
:scope => 'activerecord.errors.messages'
)
}
如果在 .yml
文件中没有以下代码。activerecord:
errors:
messages:
custom_invalid_format: This is the test error message 1
我想使用This is the test error message 2
,有可能吗?如果可以,我该如何做?
顺便提一下:出于性能方面的考虑,运行时检查翻译键/值对是否存在是可取的吗?