Rails:如何在Rails 4枚举中使用i18n [英] Rails: How to use i18n with Rails 4 enums

查看:50
本文介绍了Rails:如何在Rails 4枚举中使用i18n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 4 活动记录枚举很好,但是正确的翻译方式是什么i18n吗?

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

推荐答案

我也没有找到任何特定的模式,所以我只添加了:

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

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

到任意.yml文件。然后在我看来:

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

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

这篇关于Rails:如何在Rails 4枚举中使用i18n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆