diff --git a/packages/cli/src/api/catalog/getCatalogs.test.ts b/packages/cli/src/api/catalog/getCatalogs.test.ts index 70a8e4c31..b555af5e4 100644 --- a/packages/cli/src/api/catalog/getCatalogs.test.ts +++ b/packages/cli/src/api/catalog/getCatalogs.test.ts @@ -407,4 +407,22 @@ describe("getCatalogForFile", () => { catalog, }) }) + + it("should allow parentheses in path names", async () => { + const catalog = new Catalog( + { + name: null, + path: "./src/locales/(asd)/{locale}", + include: ["./src/"], + format, + }, + mockConfig({ format: "po", rootDir: "." }) + ) + const catalogs = [catalog] + + expect(getCatalogForFile("./src/locales/(asd)/en.po", catalogs)).toEqual({ + locale: "en", + catalog, + }) + }) }) diff --git a/packages/cli/src/api/catalog/getCatalogs.ts b/packages/cli/src/api/catalog/getCatalogs.ts index f764a33e6..b92672ba8 100644 --- a/packages/cli/src/api/catalog/getCatalogs.ts +++ b/packages/cli/src/api/catalog/getCatalogs.ts @@ -132,10 +132,13 @@ export function getCatalogForFile(file: string, catalogs: Catalog[]) { for (const catalog of catalogs) { const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}` const catalogGlob = replacePlaceholders(catalogFile, { locale: "*" }) - const match = micromatch.capture( - normalizeRelativePath(path.relative(catalog.config.rootDir, catalogGlob)), - normalizeRelativePath(file) + const matchPattern = normalizeRelativePath( + path.relative(catalog.config.rootDir, catalogGlob) ) + .replace("(", "\\(") + .replace(")", "\\)") + + const match = micromatch.capture(matchPattern, normalizeRelativePath(file)) if (match) { return { locale: match[0],