I have a user table with a level column. The level column is numeric and the value is 0, 1, or 2.
Is there anyway to get the Internationalization (I18n) API to convert the numeric value so that in开发者_如何学JAVA english 0 = Foobar, 1 = Foo, 2 = Bar? Then in another language 0,1,2 could return something else?
Thanks
I found you can do this by adding something like the following to your locales files:
en:
user:
level:
'0': 'Admin'
'1': 'Editor'
'2': 'Contributer'
Then in a view:
<%= f.select :level, (0..2).to_a.map { |level| [t(level, :scope => 'user.level'), level] } %>
There might be a better way, but this seem to be working well for me!
精彩评论