【问题标题】:i18n for select boxesi18n 用于选择框
【发布时间】:2011-10-04 17:32:54
【问题描述】:

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

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

locales/de.yml

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

【问题讨论】:

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


    【解决方案1】:

    在模型中:

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

    在视图中:

    <%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
    

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2013-11-17
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      相关资源
      最近更新 更多