大家好,我在我的应用程序中构建了一个搜索框。它看起来像这样:
= 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')
关于ruby-on-rails - 简单表格 I18n 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23648700/