Way Rails does not raise I18n::MissingInterpolationArgument exception?

和自甴很熟 提交于 2019-12-11 10:02:01

问题


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)

来源:https://stackoverflow.com/questions/27940385/way-rails-does-not-raise-i18nmissinginterpolationargument-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!