diff --git a/src/openforms/formio/components/translations.py b/src/openforms/formio/components/translations.py index 51a400252d..075283233e 100644 --- a/src/openforms/formio/components/translations.py +++ b/src/openforms/formio/components/translations.py @@ -10,9 +10,17 @@ def translate_options( if not (translations := option.get("openForms", {}).get("translations")): continue - translated_label = translations.get(language_code, {}).get("label", "") - if enabled and translated_label: - option["label"] = translated_label + if enabled: + translated_label = translations.get(language_code, {}).get("label", "") + translated_description = translations.get(language_code, {}).get( + "description", "" + ) + + if translated_label: + option["label"] = translated_label + + if translated_description: + option["description"] = translated_description # always clean up del option["openForms"]["translations"] # type: ignore diff --git a/src/openforms/formio/tests/test_component_translations.py b/src/openforms/formio/tests/test_component_translations.py index 5a2bb94270..cc2a97dd1b 100644 --- a/src/openforms/formio/tests/test_component_translations.py +++ b/src/openforms/formio/tests/test_component_translations.py @@ -553,7 +553,10 @@ def test_options_translated(self, lang_code, translation): "label": "First option", "openForms": { "translations": { - lang_code: {"label": translation}, + lang_code: { + "label": translation, + "description": translation, + }, } }, } @@ -565,8 +568,11 @@ def test_options_translated(self, lang_code, translation): assert "values" in component opt1 = component["values"][0] assert "label" in opt1 + assert "description" in opt1 assert "openForms" in opt1 + self.assertEqual(opt1["label"], translation) + self.assertEqual(opt1["description"], translation) self.assertNotIn("translations", opt1["openForms"]) @@ -726,7 +732,10 @@ def test_options_translated(self, lang_code, translation): "label": "First option", "openForms": { "translations": { - lang_code: {"label": translation}, + lang_code: { + "label": translation, + "description": translation, + }, } }, } @@ -738,8 +747,10 @@ def test_options_translated(self, lang_code, translation): assert "values" in component opt1 = component["values"][0] assert "label" in opt1 + assert "description" in opt1 assert "openForms" in opt1 self.assertEqual(opt1["label"], translation) + self.assertEqual(opt1["description"], translation) self.assertNotIn("translations", opt1["openForms"]) diff --git a/src/openforms/formio/typing/base.py b/src/openforms/formio/typing/base.py index 709598728d..b46f28d401 100644 --- a/src/openforms/formio/typing/base.py +++ b/src/openforms/formio/typing/base.py @@ -50,6 +50,7 @@ class OptionDict(TypedDict): value: str label: str + description: NotRequired[str] openForms: NotRequired[OpenFormsOptionExtension]