Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vite] Parentheses in catalog pathnames causes them to be unrecognized #1819

Closed
jozefmery opened this issue Dec 14, 2023 · 1 comment · Fixed by #1820
Closed

[Vite] Parentheses in catalog pathnames causes them to be unrecognized #1819

jozefmery opened this issue Dec 14, 2023 · 1 comment · Fixed by #1820

Comments

@jozefmery
Copy link
Contributor

jozefmery commented Dec 14, 2023

Describe the bug
Importing a catalog that has parentheses in the pathname throws the following error in the Vite integration:

Error: Requested resource <pathname_with_parentheses> is not matched to any of your catalogs paths specified in "lingui.config".

To Reproduce

await import("./(foo).catalog.po")

Minimal reproduction in a Remix.run app (using the unstable Vite integration): repl

Expected behavior
The catalog should be recognized correctly regardless of special characters and imported successfully.

Additional context

Why do I care about parentheses in pathnames? I would like to generate a separate catalog for each route, so that each of them can load their own translations with minimal network overhead. However, Remix uses parentheses in pathnames for defining optional parameters, causing the imports to fail.

Finally, I'd like to thank the authors for creating the sexiest I18N solution there is. Thank you.

@jozefmery jozefmery changed the title [Vite] Parenthesis in the catalog pathname break the loader [Vite] Parentheses in the catalog pathname break the loader Dec 14, 2023
@jozefmery jozefmery changed the title [Vite] Parentheses in the catalog pathname break the loader [Vite] Parentheses in catalog pathnames causes them to be unrecognized Dec 14, 2023
@jozefmery
Copy link
Contributor Author

jozefmery commented Dec 15, 2023

I did a little digging and the issue seems to come from the micromatch library, see:
micromatch/micromatch#123

Although the lingui vite plugin uses the micromatch.capture, internally, the capture method uses the problematic makeRe function. See here: https://github.com/micromatch/micromatch/blob/90dc0cd3e186b8ab4dd05bfc41e2b98f5067a49b/index.js#L363

Fixing this issue may be as simple as escaping the parentheses so they are not interpreted as RegEx capture groups. If I can, I'll try to cook up a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants