i18n用于选择框

时间:2011-07-13 17:57:11

标签: ruby-on-rails internationalization rails-i18n

我有一个名为Role的模型。我在表格中使用下面的助手。有没有办法将name属性的值更改为另一种语言?

<%= f.collection_select :role_id, Role.all, :id, name, {} -%>

区域设置/ de.yml

de:
  role:
   admin: "something"
   editor: "something something"

1 个答案:

答案 0 :(得分:25)

在模型中:

class Role < ActiveRecord::Base
  def translated_name
    I18n.t(name, :scope => 'role')
  end
end

在视图中:

<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
相关问题