Skip to content

Translating enum values (SelectField) and booleans #2768

@davidgm0

Description

@davidgm0

The only thing I found related to translating enum values is this: #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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    i18ntranslations and language support

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions