Skip to content

Adding I18n translations for polymorphic fields #1994

@DavidGeismarLtd

Description

@DavidGeismarLtd
  • What were you trying to do?
    Translations for a polymorphic field item. here's an example. Item can be a program or a session and both are translated in the locale.yml file
    I have a GroupItemDashboard :
  ATTRIBUTE_TYPES = {
    # cannot be made searchable ...
    item: Field::Polymorphic.with_options(
      classes: [Program, Session],
      order: "lms_data ->'name' ASC"
    ),
    group: Field::BelongsTo.with_options(
      searchable: false
    ),
}
  FORM_ATTRIBUTES = %i[
    item
    group
  ].freeze

In my locale.yml file I have :

 activerecord:
          models:
              item:
                one: Session Ou Parcours
                other: Sessions ou Parcours
              program:
                  one: Parcours
                  other: Parcours
            session:
                  one: Session
                  other: Sessions
              group:
                one: Groupe
                other: Groupes

However, those translations for polymorphic fields are never taken into account. Neither for the input label or within the select options (see here label is "item", and select options refer to "programs" and not "parcours") :
Screenshot 2021-06-02 at 09 27 04

Is there any way to add a translation for a polymorphic field ?



* What did you end up with (logs, or, even better, example apps are great!)?
* What versions are you running?
  - Rails 6.0.3
  - administrate 0.15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbreakages in functionality that is implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions