Suppose one has the following en.yml
假设有一个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
可以理解地抛出一个I18n :: MissingInterpolationArgument,但我无法弄清楚传递缺失参数的语法是什么
# views/books/edit.html
f.label :price, :currency => "USD"
does not work.
不起作用。
1 个解决方案
#1
10
I would try:
我会尝试:
<%= f.label I18n.t(:price, :scope => "activerecord.attribute.book", :currency => "USD") %>
#1
10
I would try:
我会尝试:
<%= f.label I18n.t(:price, :scope => "activerecord.attribute.book", :currency => "USD") %>