Mat*_*ski 3 ruby-on-rails internationalization simple-form
大家好,我的应用程序中我建立了一个搜索框.它看起来像这样:
= 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
Run Code Online (Sandbox Code Playgroud)
现在我不知道如何用I18n翻译这个标签.我怎样才能做到这一点?
nat*_*vda 11
查看有关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: '****'
Run Code Online (Sandbox Code Playgroud)
这指定了标签的默认值.您应该查看文档,因为还有更多选项.
其次,你也可以明确地这样做,就像这样
= f.input :car, label: I18n.t('my_car_label'), prompt: I18n.t('my-car-prompt'), placeholder: I18n.t('my-placeholder')
Run Code Online (Sandbox Code Playgroud)