如何在表单标签助手中传递 i18n 插值变量?
假设有以下 en.yml
#en.yml
en:
activerecord:
books:
price: "Price in %{currency}"
然后可以在视图中执行以下操作
<%= t :price, :scope => "activerecord.attributes.book", :currency => "USD"%>
,它将打印“Price in USD”。
但是,当此翻译的形式
# views/books/edit.html
f.label :price
可以理解地抛出 I18n::MissingInterpolationArgument 时,我无法弄清楚如何传递货币,但我无法弄清楚传递缺少的参数
# views/books/edit.html
f.label :price, :currency => "USD"
不起作用的语法可能是什么。
Suppose one has the following en.yml
#en.yml
en:
activerecord:
books:
price: "Price in %{currency}"
Then one can do the following in a view
<%= t :price, :scope => "activerecord.attributes.book", :currency => "USD"%>
and it will print "Price in USD".
But I can't figure out how to pass the currency when this translation is in a form
# views/books/edit.html
f.label :price
understandably throws an I18n::MissingInterpolationArgument, but I can't figure out what the syntax might be to pass the missing argument
# views/books/edit.html
f.label :price, :currency => "USD"
does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试:
I would try: