From 9fb26626d39d1258cce17575552d60c12081915e Mon Sep 17 00:00:00 2001 From: Anze Demsar Date: Wed, 11 Oct 2023 11:19:26 +0200 Subject: [PATCH] fix: consider i18n strucutre when determining regex ruleString for github backend (#6937) --- packages/decap-cms-core/src/backend.ts | 12 ++++++++++-- packages/decap-cms-core/src/lib/i18n.ts | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/decap-cms-core/src/backend.ts b/packages/decap-cms-core/src/backend.ts index d6faf795c67d..2150cd984fd5 100644 --- a/packages/decap-cms-core/src/backend.ts +++ b/packages/decap-cms-core/src/backend.ts @@ -47,8 +47,10 @@ import { getI18nBackup, formatI18nBackup, getI18nInfo, + I18N_STRUCTURE, } from './lib/i18n'; +import type { I18nInfo } from './lib/i18n'; import type AssetProxy from './valueObjects/AssetProxy'; import type { CmsConfig, @@ -308,6 +310,13 @@ function collectionDepth(collection: Collection) { return depth; } +function i18nRulestring(ruleString: string, { defaultLocale, structure }: I18nInfo): string { + if (structure === I18N_STRUCTURE.MULTIPLE_FOLDERS) { + return `${defaultLocale}\\/${ruleString}`; + } + return `${ruleString}\\.${defaultLocale}\\..*`; +} + function collectionRegex(collection: Collection): RegExp | undefined { let ruleString = ''; @@ -319,8 +328,7 @@ function collectionRegex(collection: Collection): RegExp | undefined { } if (hasI18n(collection)) { - const { defaultLocale } = getI18nInfo(collection) as { defaultLocale: string }; - ruleString += `\\.${defaultLocale}\\..*`; + ruleString = i18nRulestring(ruleString, getI18nInfo(collection) as I18nInfo); } return ruleString ? new RegExp(ruleString) : undefined; diff --git a/packages/decap-cms-core/src/lib/i18n.ts b/packages/decap-cms-core/src/lib/i18n.ts index 013aaf631096..75e5defaf729 100644 --- a/packages/decap-cms-core/src/lib/i18n.ts +++ b/packages/decap-cms-core/src/lib/i18n.ts @@ -24,7 +24,7 @@ export function hasI18n(collection: Collection) { return collection.has(I18N); } -type I18nInfo = { +export type I18nInfo = { locales: string[]; defaultLocale: string; structure: I18N_STRUCTURE;