Prevent literal interpolation on null translations & apply to collection translations (#11482)

* translation could be null in edge cases

* add interpolation to collection translations
This commit is contained in:
Azri Kahar
2022-02-16 22:31:12 +08:00
committed by GitHub
parent 3211302a9c
commit e237f9f222
2 changed files with 4 additions and 2 deletions

View File

@@ -54,9 +54,11 @@ 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'}") : '';
i18n.global.mergeLocaleMessage(language, {
collection_names: {
[collection.collection]: translation,
[collection.collection]: literalInterpolatedTranslation,
},
collection_names_singular: {
[collection.collection]: singular,

View File

@@ -76,7 +76,7 @@ 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.replace(/([{}@$|])/g, "{'$1'}");
const literalInterpolatedTranslation = translation ? translation.replace(/([{}@$|])/g, "{'$1'}") : '';
i18n.global.mergeLocaleMessage(language, {
fields: {