From 2d5fcfe48fc98da229be73d193a17da75a72f4c5 Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Thu, 14 Mar 2024 13:00:02 +0100 Subject: [PATCH] fix: apply duplicate i18n values on entry load --- packages/decap-cms-core/src/lib/i18n.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/decap-cms-core/src/lib/i18n.ts b/packages/decap-cms-core/src/lib/i18n.ts index 75e5defaf729..d029211d016e 100644 --- a/packages/decap-cms-core/src/lib/i18n.ts +++ b/packages/decap-cms-core/src/lib/i18n.ts @@ -219,6 +219,24 @@ export function formatI18nBackup( return i18n; } +function applyDefaultI18nValues( + collection: Collection, + value: EntryValue, + defaultLocaleValue: EntryValue, +) { + if (collection.get('fields') === undefined) { + return; + } + collection.get('fields').forEach(field => { + if (field && field.get(I18N) === I18N_FIELD.DUPLICATE) { + const data = value.data[field.get('name')]; + if (!data) { + value.data[field.get('name')] = defaultLocaleValue.data[field.get('name')]; + } + } + }); +} + function mergeValues( collection: Collection, structure: I18N_STRUCTURE, @@ -234,6 +252,9 @@ function mergeValues( .filter(e => e.locale !== defaultEntry!.locale) .reduce((acc, { locale, value }) => { const dataPath = getLocaleDataPath(locale); + if (defaultEntry) { + applyDefaultI18nValues(collection, value, defaultEntry.value); + } return set(acc, dataPath, value.data); }, {});