Skip to content

Commit

Permalink
fix: consider i18n strucutre when determining regex ruleString for gi…
Browse files Browse the repository at this point in the history
…thub backend (#6937)
  • Loading branch information
demshy authored Oct 11, 2023
1 parent 34f0b63 commit 1aac51d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/decap-cms-core/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = '';

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms-core/src/lib/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1aac51d

Please sign in to comment.