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, + }, }, - }, + }), }); } }