administrate
administrate copied to clipboard
Translating enum values (SelectField) and booleans
The only thing I found related to translating enum values is this: https://github.com/thoughtbot/administrate/issues/1994. I'm not sure if I'm missing or configuring my i18n wrong and this should already work out of the box. Would this be an addition you would accept?
- What would you like to be able to do? Can you provide some examples?
Initially I was just trying to get an enum displayed in an index page to be upercase. So instead of displaying closed, display Closed. I thought it'd make sense to use i18n for this as well.
Similar for booleans
- How could we go about implementing that?
The most basic thing I found that worked was adding
# en.yml in administrate
en:
true: "true"
false: "false"
# boolean.rb
def to_s
I18n.t(data.to_s)
end
# select.rb
def data
I18n.translate(super)
end
This worked. I am not familiar with the codebase, but I guess the translation would fit better in the views. And for select fields, the translations should look more like:
activerecord:
enums:
mymodel:
state:
closed: 'Closed'
- Can you think of other approaches to the problem?