(react) fix translations and add missing translations

This commit improves the translations method to handle undefined values
gracefully and adds several missing translations for modals in the
French locale.
This commit is contained in:
Nathan Panchout
2025-07-29 16:37:05 +02:00
parent 7ef8930bc8
commit 06926863c6
3 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@openfun/cunningham-react": patch
---
Fix translations method and added missing translations

View File

@@ -47,7 +47,10 @@ const findTranslation = (
locale: TranslationSet,
): string | undefined => {
const [namespace, ...keys] = key.split(".");
return keys.reduce((acc, subKey) => acc[subKey], (locale as any)[namespace]);
return keys.reduce(
(acc, subKey) => acc?.[subKey],
(locale as any)[namespace],
);
};
export const CunninghamProvider = ({

View File

@@ -46,6 +46,27 @@
"year_select_button_aria_label": "Sélectionner une année",
"month_select_button_aria_label": "Sélectionner un mois"
}
},
"modals": {
"helpers": {
"delete_confirmation": {
"title": "Êtes-vous sûr ?",
"children": "Êtes-vous sûr de vouloir supprimer cet élément ?",
"cancel": "Annuler",
"delete": "Supprimer"
},
"confirmation": {
"title": "Êtes-vous sûr ?",
"children": "Êtes-vous sûr de vouloir faire cela ?",
"cancel": "Annuler",
"yes": "Oui"
},
"disclaimer": {
"title": "Avertissement",
"children": "Ceci est un avertissement",
"ok": "Ok"
}
}
}
}
}