From a508158f59e91e0c00d1281686bf4425994aa709 Mon Sep 17 00:00:00 2001 From: Daniel Lautzenheiser Date: Wed, 11 Oct 2023 14:29:07 -0400 Subject: [PATCH] fix: consider i18n structure when building path regex (#935) --- packages/core/src/backend.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/backend.ts b/packages/core/src/backend.ts index 5f29fe1b..05208b2b 100644 --- a/packages/core/src/backend.ts +++ b/packages/core/src/backend.ts @@ -10,6 +10,7 @@ import { dirname } from 'path'; import { resolveFormat } from './formats/formats'; import { commitMessageFormatter, slugFormatter } from './lib/formatters'; import { + I18N_STRUCTURE_MULTIPLE_FOLDERS, formatI18nBackup, getFilePaths, getI18nBackup, @@ -65,6 +66,7 @@ import type { EntryData, EventData, FilterRule, + I18nInfo, ImplementationEntry, MediaField, ObjectValue, @@ -293,6 +295,14 @@ 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 = ''; @@ -301,8 +311,7 @@ function collectionRegex(collection: Collection): RegE } if (hasI18n(collection)) { - const { defaultLocale } = getI18nInfo(collection); - ruleString += `\\.${defaultLocale}\\..*`; + ruleString = i18nRulestring(ruleString, getI18nInfo(collection)); } return ruleString ? new RegExp(ruleString) : undefined;