Skip to content

Commit 1aac51d

Browse files
authored
fix: consider i18n strucutre when determining regex ruleString for github backend (#6937)
1 parent 34f0b63 commit 1aac51d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/decap-cms-core/src/backend.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ import {
4747
getI18nBackup,
4848
formatI18nBackup,
4949
getI18nInfo,
50+
I18N_STRUCTURE,
5051
} from './lib/i18n';
5152

53+
import type { I18nInfo } from './lib/i18n';
5254
import type AssetProxy from './valueObjects/AssetProxy';
5355
import type {
5456
CmsConfig,
@@ -308,6 +310,13 @@ function collectionDepth(collection: Collection) {
308310
return depth;
309311
}
310312

313+
function i18nRulestring(ruleString: string, { defaultLocale, structure }: I18nInfo): string {
314+
if (structure === I18N_STRUCTURE.MULTIPLE_FOLDERS) {
315+
return `${defaultLocale}\\/${ruleString}`;
316+
}
317+
return `${ruleString}\\.${defaultLocale}\\..*`;
318+
}
319+
311320
function collectionRegex(collection: Collection): RegExp | undefined {
312321
let ruleString = '';
313322

@@ -319,8 +328,7 @@ function collectionRegex(collection: Collection): RegExp | undefined {
319328
}
320329

321330
if (hasI18n(collection)) {
322-
const { defaultLocale } = getI18nInfo(collection) as { defaultLocale: string };
323-
ruleString += `\\.${defaultLocale}\\..*`;
331+
ruleString = i18nRulestring(ruleString, getI18nInfo(collection) as I18nInfo);
324332
}
325333

326334
return ruleString ? new RegExp(ruleString) : undefined;

packages/decap-cms-core/src/lib/i18n.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function hasI18n(collection: Collection) {
2424
return collection.has(I18N);
2525
}
2626

27-
type I18nInfo = {
27+
export type I18nInfo = {
2828
locales: string[];
2929
defaultLocale: string;
3030
structure: I18N_STRUCTURE;

0 commit comments

Comments
 (0)