Unreliable translation on select #options optgroups

Created on 9 November 2022, over 1 year ago
Updated 14 September 2023, 10 months ago

Problem/Motivation

The select element type's #options field does not play well with translations when they contain optgroups and subsequently silently fails to translate some of the options.

Steps to reproduce

Using the following YAML for the webform source :

optgroup_select:
  '#type': select
  '#title': 'Example select with optgroup'
  '#options':
    Fruits:
      - Banana
      - Strawberry
      - Mango
    Vegetables:
      3: Turnip
      4: Eggplant
      5: Carrot

And translating it to this (in french in my case), either on the translation UI or in a config directory:

Fruits:
  - Banane
  - Fraise
  - Mangue
LΓ©gumes:
  3: Navet
  4: Aubergine
  5: Carotte

Results in the (master) english version:

And the following french version:

Note that the fruits are successfully translated, but not the vegetables.
I think it may be linked to how fruits is an array while vegetables is an object, because changing the fruits IDs to a text value or other numbers makes them untranslated as well.

Additionally, the translation UI shows the same thing as the above screenshot while the config files contain the correct data.

I have attached the configuration files below.

Proposed resolution

We should be able to edit the select's #options fields reliably, even if it contain optgroups.

πŸ› Bug report
Status

Fixed

Version

6.1

Component

Code

Created by

πŸ‡«πŸ‡·France maxime-adagp Paris, France πŸ‡«πŸ‡·

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024