Rails:simple_form 与 i18n 的关联 [英] Rails: simple_form association with i18n
问题描述
我有一个关于 simple_form gem
的问题.
I have a question regarding the simple_form gem
.
如果我有两种语言并使用 t('')
函数来翻译文本,我已将其放入我的 .yml
文件中.
If I have two languages and use the t('')
function from to translate text, which I have put into my .yml
files.
当使用 <%= f.association :type %>
时,是否可以让 simple_form 渲染
When using <%= f.association :type %>
, is it possible to let simple_form render
?
谢谢
推荐答案
可能,它会为您翻译集合:https://github.com/plataformatec/simple_form
协会文档:http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:association
Possibly, it'll translate collections for you: https://github.com/plataformatec/simple_form
Association docs: http://rubydoc.info/github/plataformatec/simple_form/master/SimpleForm/FormBuilder:association
来自文档
Simple Form 还支持在集合助手中翻译选项.例如,给定具有 :gender 属性的用户,您可能希望创建一个选择框,显示翻译标签,将男性或女性作为值发布.使用 Simple Form,您可以创建这样的输入:
From the docs
Simple Form also has support for translating options in collection helpers. For instance, given a User with a :gender attribute, you might want to create a select box showing translated labels that would post either male or female as value. With Simple Form you could create an input like this:
f.input :gender, collection: [:male, :female]
Simple Form 将尝试在您的语言环境文件中进行这样的查找,以找到要显示的正确标签:
And Simple Form will try a lookup like this in your locale file, to find the right labels to show:
en:
simple_form:
options:
user:
gender:
male: 'Male'
female: 'Female'
也许试试:<%= f.association :type, collection: [:some, :collection, :options]%>
这篇关于Rails:simple_form 与 i18n 的关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!