Rails: How to use i18n with Rails 4 enums

后端 未结 16 2286
天涯浪人
天涯浪人 2020-11-28 04:10

Rails 4 Active Record Enums are great, but what is the right pattern for translating with i18n?

16条回答
  •  悲&欢浪女
    2020-11-28 04:52

    I didn't find any specific pattern either, so I simply added:

    en:
      user_status:
        active:   Active
        pending:  Pending...
        archived: Archived
    

    to an arbitrary .yml file. Then in my views:

    I18n.t :"user_status.#{user.status}"
    

提交回复
热议问题