Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a variable to the i18n translations in simple_form

I need to pass in a variable to generate the label of a field with simple form. With normal translations you go about this in the following way: http://guides.rubyonrails.org/i18n.html#passing-variables-to-translations but for the life of me I am unable to get it to work with simple form.

I am attempting to pass it in using:

= f.input :name, :contact_type => f.object.contact_type.to_s

And in the simple_form.en.yml file:

en:
    simple_form:
        labels:
            contacts:
                name: "Name %{contact_type}"

This is outputting: Name %{contact_type}"

Ignoring the variable all together. Is there a way to accomplish this?

Thanks,

Ryan Lundie

like image 563
lundie Avatar asked Sep 17 '25 13:09

lundie


1 Answers

You need to explicitly add the label to the form input like this :

= f.input :name,
  :contact_type => f.object.contact_type.to_s,
  :label => t(:'simple_form.labels.contacts.name', :contact_type => "Whatever contact type")
like image 109
tigrish Avatar answered Sep 20 '25 02:09

tigrish