prevent null translations from being merged (#12162)

This commit is contained in:
Azri Kahar
2022-03-15 22:50:25 +08:00
committed by GitHub
parent cf3e86bebd
commit fdf545a834
2 changed files with 23 additions and 15 deletions

View File

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

View File

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