简体   繁体   中英

How do pass an i18n interpolation variable inside the form label helper?

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.

我会尝试:

<%= f.label I18n.t(:price, :scope => "activerecord.attribute.book", :currency => "USD") %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM