-->

Way Rails does not raise I18n::MissingInterpolatio

2019-08-04 18:41发布

问题:

I created a dummy rails 4.1.5 application to show that I18n translate method doesn't raise I18n::MissingInterpolationArgument when the variable to be interpolated is not provided. It raises that exception only if provide something wrong. Is this the expected behaviour?

Loading development environment (Rails 4.1.5)
irb(main):001:0> I18n.backend.store_translations :en, thanks: 'Thanks %{name}!'
=> {:thanks=>"Thanks %{name}!"}
irb(main):002:0> I18n.translate :thanks
=> "Thanks %{name}!"
irb(main):003:0> I18n.translate :thanks, foo: 'bar'
I18n::MissingInterpolationArgument: missing interpolation argument :name in "Thanks %{name}!" ({:foo=>"bar"} given)