Skip to content

Commit f5fae0e

Browse files
authored
fix: allow parentheses in catalog pathnames (#1820)
1 parent 8830f2e commit f5fae0e

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

packages/cli/src/api/catalog/getCatalogs.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,22 @@ describe("getCatalogForFile", () => {
407407
catalog,
408408
})
409409
})
410+
411+
it("should allow parentheses in path names", async () => {
412+
const catalog = new Catalog(
413+
{
414+
name: null,
415+
path: "./src/locales/(asd)/{locale}",
416+
include: ["./src/"],
417+
format,
418+
},
419+
mockConfig({ format: "po", rootDir: "." })
420+
)
421+
const catalogs = [catalog]
422+
423+
expect(getCatalogForFile("./src/locales/(asd)/en.po", catalogs)).toEqual({
424+
locale: "en",
425+
catalog,
426+
})
427+
})
410428
})

packages/cli/src/api/catalog/getCatalogs.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,13 @@ export function getCatalogForFile(file: string, catalogs: Catalog[]) {
132132
for (const catalog of catalogs) {
133133
const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`
134134
const catalogGlob = replacePlaceholders(catalogFile, { locale: "*" })
135-
const match = micromatch.capture(
136-
normalizeRelativePath(path.relative(catalog.config.rootDir, catalogGlob)),
137-
normalizeRelativePath(file)
135+
const matchPattern = normalizeRelativePath(
136+
path.relative(catalog.config.rootDir, catalogGlob)
138137
)
138+
.replace("(", "\\(")
139+
.replace(")", "\\)")
140+
141+
const match = micromatch.capture(matchPattern, normalizeRelativePath(file))
139142
if (match) {
140143
return {
141144
locale: match[0],

0 commit comments

Comments
 (0)