Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translating enum values (SelectField) and booleans #2768

Open
davidgm0 opened this issue Feb 2, 2025 · 0 comments
Open

Translating enum values (SelectField) and booleans #2768

davidgm0 opened this issue Feb 2, 2025 · 0 comments
Labels
i18n translations and language support

Comments

@davidgm0
Copy link

davidgm0 commented Feb 2, 2025

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?
@nickcharlton nickcharlton added the i18n translations and language support label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n translations and language support
Projects
None yet
Development

No branches or pull requests

2 participants