如何在rails I18n中转换以下代码
f.select :option,[["This is a Scam","Scam"],["This is a Spam","Spam"],["This is a bot","Bot"]]发布于 2017-09-06 13:05:28
试试这个:
config/locales/es.yml
es:
helpers:
model:
select_attr:
values:
scam: 'estafa'
spam: 'correo no deseado'
bot: 'larva del moscardón'config/locales/en.yml
en:
helpers:
model:
select_attr:
values:
scam: 'Scam'
spam: 'Spam'
bot: 'Bot'并将select helper修改为
= f.select :option, [
[I18n.t("helpers.model.select_attr.values.scam", 'Scam')],
[I18n.t("helpers.model.select_attr.values.spam", 'Spam')],
[I18n.t("helpers.model.select_attr.values.bot", 'Bot')]
]Rails根据选定的区域设置选项值(en或es),如上面的示例所示。
该选项内部数组的第一个属性是一个label,它将显示给用户。第二个-是一个选项value,它被保存到数据库字段option。
更多信息,您可以在ActionView::Helpers::FormOptionsHelper文档页面阅读。
https://stackoverflow.com/questions/46075883
复制相似问题