简单表格I18n标签 [英] Simple Form I18n labels
本文介绍了简单表格I18n标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我在我的应用程序中建立了一个搜索框.看起来像这样:
Hi everyone in my app I build a search box. It looks like this:
= simple_form_for :cars, {url: cars_path, method: :get} do |f|
= f.input :handover_location, collection: Location.all.map{|hl| [hl.name, hl.id]}
= f.input :return_location, collection: Location.all.map{|rl| [rl.name, rl.id]}
= f.input :car_class, collection: CarClass.all.map { |c| [c.name, c.id] }, include_blank: true
= f.submit
现在我不知道如何使用I18n翻译此标签.我该怎么办?
And now i don't know how to translate this labels with I18n. How can I do this?
推荐答案
检查有关i18n的简单格式文档: https://github.com/plataformatec/simple_form#i18n
Check the simple-form documentation regarding i18n: https://github.com/plataformatec/simple_form#i18n
它描述得很好,并且非常详细.
It is pretty well described, and goes into great detail.
例如(根据文档):
en:
simple_form:
labels:
defaults:
username: 'User name'
password: 'Password'
new:
username: 'Choose a user name'
hints:
defaults:
username: 'User name to sign in.'
password: 'No special characters, please.'
placeholders:
defaults:
username: 'Your username'
password: '****'
这指定标签的默认值. 您应该检查文档,因为还有更多选择.
This specifies the defaults for labels. You should check the documentation, because there are a lot more options.
第二,您也可以像这样
= f.input :car, label: I18n.t('my_car_label'), prompt: I18n.t('my-car-prompt'), placeholder: I18n.t('my-placeholder')
这篇关于简单表格I18n标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文