Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: consider i18n structure when building path regex #6937

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading