Skip to content

Commit

Permalink
fix: allow parentheses in catalog pathnames (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefmery committed Dec 18, 2023
1 parent 8830f2e commit f5fae0e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions packages/cli/src/api/catalog/getCatalogs.test.ts
Expand Up @@ -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,
})
})
})
9 changes: 6 additions & 3 deletions packages/cli/src/api/catalog/getCatalogs.ts
Expand Up @@ -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],
Expand Down

1 comment on commit f5fae0e

@vercel
Copy link

@vercel vercel bot commented on f5fae0e Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.