From fdf545a83474ff99fcbb97e94e3a06b9daaf4961 Mon Sep 17 00:00:00 2001 From: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Date: Tue, 15 Mar 2022 22:50:25 +0800 Subject: [PATCH] prevent null translations from being merged (#12162) --- app/src/stores/collections.ts | 26 ++++++++++++++++---------- app/src/stores/fields.ts | 12 +++++++----- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/stores/collections.ts b/app/src/stores/collections.ts index 00dba4ee9e..6b195cc180 100644 --- a/app/src/stores/collections.ts +++ b/app/src/stores/collections.ts @@ -54,18 +54,24 @@ export const useCollectionsStore = defineStore({ for (let i = 0; i < collection.meta.translations.length; i++) { const { language, translation, singular, plural } = collection.meta.translations[i]; - const literalInterpolatedTranslation = translation ? translation.replace(/([{}@$|])/g, "{'$1'}") : ''; + const literalInterpolatedTranslation = translation ? translation.replace(/([{}@$|])/g, "{'$1'}") : null; i18n.global.mergeLocaleMessage(language, { - collection_names: { - [collection.collection]: literalInterpolatedTranslation, - }, - collection_names_singular: { - [collection.collection]: singular, - }, - collection_names_plural: { - [collection.collection]: plural, - }, + ...(literalInterpolatedTranslation && { + collection_names: { + [collection.collection]: literalInterpolatedTranslation, + }, + }), + ...(singular && { + collection_names_singular: { + [collection.collection]: singular, + }, + }), + ...(plural && { + collection_names_plural: { + [collection.collection]: plural, + }, + }), }); } } diff --git a/app/src/stores/fields.ts b/app/src/stores/fields.ts index 74dd42e551..ffd85bf4d4 100644 --- a/app/src/stores/fields.ts +++ b/app/src/stores/fields.ts @@ -76,14 +76,16 @@ export const useFieldsStore = defineStore({ const { language, translation } = field.meta.translations[i]; // Interpolate special characters in vue-i18n to prevent parsing error. Ref #11287 - const literalInterpolatedTranslation = translation ? translation.replace(/([{}@$|])/g, "{'$1'}") : ''; + const literalInterpolatedTranslation = translation ? translation.replace(/([{}@$|])/g, "{'$1'}") : null; i18n.global.mergeLocaleMessage(language, { - fields: { - [field.collection]: { - [field.field]: literalInterpolatedTranslation, + ...(literalInterpolatedTranslation && { + fields: { + [field.collection]: { + [field.field]: literalInterpolatedTranslation, + }, }, - }, + }), }); } }