fix: consider i18n structure when building path regex (#935)

This commit is contained in:
Daniel Lautzenheiser 2023-10-11 14:29:07 -04:00 committed by GitHub
parent 24d02b87f9
commit a508158f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import { dirname } from 'path';
import { resolveFormat } from './formats/formats'; import { resolveFormat } from './formats/formats';
import { commitMessageFormatter, slugFormatter } from './lib/formatters'; import { commitMessageFormatter, slugFormatter } from './lib/formatters';
import { import {
I18N_STRUCTURE_MULTIPLE_FOLDERS,
formatI18nBackup, formatI18nBackup,
getFilePaths, getFilePaths,
getI18nBackup, getI18nBackup,
@ -65,6 +66,7 @@ import type {
EntryData, EntryData,
EventData, EventData,
FilterRule, FilterRule,
I18nInfo,
ImplementationEntry, ImplementationEntry,
MediaField, MediaField,
ObjectValue, ObjectValue,
@ -293,6 +295,14 @@ function collectionDepth<EF extends BaseField>(collection: Collection<EF>) {
return depth; return depth;
} }
function i18nRulestring(ruleString: string, { defaultLocale, structure }: I18nInfo): string {
if (structure === I18N_STRUCTURE_MULTIPLE_FOLDERS) {
return `${defaultLocale}\\/${ruleString}`;
}
return `${ruleString}\\.${defaultLocale}\\..*`;
}
function collectionRegex<EF extends BaseField>(collection: Collection<EF>): RegExp | undefined { function collectionRegex<EF extends BaseField>(collection: Collection<EF>): RegExp | undefined {
let ruleString = ''; let ruleString = '';
@ -301,8 +311,7 @@ function collectionRegex<EF extends BaseField>(collection: Collection<EF>): RegE
} }
if (hasI18n(collection)) { if (hasI18n(collection)) {
const { defaultLocale } = getI18nInfo(collection); ruleString = i18nRulestring(ruleString, getI18nInfo(collection));
ruleString += `\\.${defaultLocale}\\..*`;
} }
return ruleString ? new RegExp(ruleString) : undefined; return ruleString ? new RegExp(ruleString) : undefined;