Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 878
cailinanne Avatar asked Oct 17 '11 19:10

cailinanne


1 Answers

I would try:

<%= f.label I18n.t(:price, :scope => "activerecord.attribute.book", :currency => "USD") %>
like image 64
Cygnusx1 Avatar answered Nov 02 '22 18:11

Cygnusx1