[英]Passing a variable to the i18n translations in simple_form
我需要传入一个变量来生成一个简单形式的字段标签。 通过正常的翻译,您可以通过以下方式进行此操作: http : //guides.rubyonrails.org/i18n.html#passing-variables-to-translations但是对于我的生活,我无法使用简单的形式。
我试图通过它使用:
= f.input :name, :contact_type => f.object.contact_type.to_s
在simple_form.en.yml文件中:
en:
simple_form:
labels:
contacts:
name: "Name %{contact_type}"
这是输出:名称%{contact_type}“
一起忽略变量。 有没有办法实现这个目标?
谢谢,
瑞安伦迪
您需要将标签显式添加到表单输入,如下所示:
= f.input :name,
:contact_type => f.object.contact_type.to_s,
:label => t(:'simple_form.labels.contacts.name', :contact_type => "Whatever contact type")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.