ruby-on-rails – 简单表格I18n标签
发布时间:2020-12-17 01:50:41 所属栏目:百科 来源:网络整理
导读:大家好,我的应用程序中我建立了一个搜索框.它看起来像这样: = 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: Lo
|
大家好,我的应用程序中我建立了一个搜索框.它看起来像这样:
= 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翻译这个标签.我怎样才能做到这一点? 解决方法
查看有关i18n:
https://github.com/plataformatec/simple_form#i18n的简单文档
它描述得很好,并且非常详细. 例如(来自文档): 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: '****'
这指定了标签的默认值. 其次,你也可以明确地这样做,就像这样 = f.input :car,label: I18n.t('my_car_label'),prompt: I18n.t('my-car-prompt'),placeholder: I18n.t('my-placeholder')
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
