Comments (6)
Could you elaborate on this a bit? because i dind't get the problem from you reproduction link
from js-lingui.
@thekip The key issue is next page route with catch-all segments, like /test/[...param].page.ts
(I use page.ts
as page extension), it can not works as expected like my reproduction. First test case should print ar
too, but got undefined
.
I will provide a Next.js demo laterly.
from js-lingui.
But how it's related to lingui? It seems a nextjs issue, not lingui.
from js-lingui.
But how it's related to lingui? It seems a nextjs issue, not lingui.
- Next.js catch-all segments ref: https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes#catch-all-segments
getCatalogForFile
withmicromatch
ref: https://github.dev/lingui/js-lingui/blob/04b7cef9876168bc376b55424ecc0b0ebde976c1/packages/cli/src/api/catalog/getCatalogs.ts#L135-L138
So I think getCatalogForFile
with micromatch
should cover Next.js catch-all segments routes. Now I patched @lingui/cli
with:
diff --git a/dist/api/catalog/getCatalogs.js b/dist/api/catalog/getCatalogs.js
index ecfc08388fa90c7efc4e826a0683488ea124734d..fbcbbe726220119687552d0f148f9da6fca48625 100644
--- a/dist/api/catalog/getCatalogs.js
+++ b/dist/api/catalog/getCatalogs.js
@@ -93,7 +93,7 @@ function getCatalogForFile(file, catalogs) {
for (const catalog of catalogs) {
const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`;
const catalogGlob = (0, utils_1.replacePlaceholders)(catalogFile, { locale: "*" });
- const match = micromatch_1.default.capture((0, utils_1.normalizeRelativePath)(path_1.default.relative(catalog.config.rootDir, catalogGlob)), (0, utils_1.normalizeRelativePath)(file));
+ const match = micromatch_1.default.capture(((0, utils_1.normalizeRelativePath)(path_1.default.relative(catalog.config.rootDir, catalogGlob))).replace(/\[/g, '\\[').replace(/\]/g, '\\]'), (0, utils_1.normalizeRelativePath)(file));
if (match) {
return {
locale: match[0],
diff --git a/dist/extract-experimental/buildExternalizeFilter.js b/dist/extract-experimental/buildExternalizeFilter.js
index f836f0f9840a4ec6f382695bb42706fb9ef4292a..ffabcfc8f60e128dd3a855e930d9cb6b86c507c1 100644
--- a/dist/extract-experimental/buildExternalizeFilter.js
+++ b/dist/extract-experimental/buildExternalizeFilter.js
@@ -1,6 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPackageJson = exports.buildExternalizeFilter = void 0;
+
+const fs = require('node:fs')
+
function createPackageRegExp(packageName) {
return new RegExp("^" + packageName + "(?:\\/.+)?");
}
@@ -33,6 +36,15 @@ async function getPackageJson(rootDir) {
throw new Error("We could not able to find your package.json file. " +
"Check that `rootDir` is pointing to the folder with package.json");
}
- return await import(packageJsonPath);
+
+ try {
+ return JSON.parse(await fs.promises.readFile(packageJsonPath, "utf-8"))
+ } catch (e) {
+ throw new Error(
+ `Unable to read package.json file at path ${packageJsonPath}. \n\n Error: ${
+ e.message
+ }`
+ )
+ }
}
exports.getPackageJson = getPackageJson;
from js-lingui.
Okay, now i've got your point. So it's somehow related to compiling/extracting with CLI and path with "[]" symbols processed incorrectly.
If you provide a nexts repro repo it would be much easier to understand the case.
from js-lingui.
After investigation, with Runkit demo I find out the key issue, so I use the demo directly, it's my fault.
from js-lingui.
Related Issues (20)
- Cannot kill git pre-commit hook while lingui command is running HOT 4
- Provide some way to turn off newline collapsing HOT 2
- `unraw` default export resolution error in React Native 0.73.2 HOT 1
- Dynamic loading not working with Expo HOT 1
- Support check the translated `msgstr` as expected HOT 2
- Lingui doesn't extract msg within a msg HOT 2
- lingui extract-experimental empty space after {} HOT 2
- Error when aliasing Trans from '@lingui/react' in presence of macro Trans from '@lingui/macro' HOT 2
- `Nextjs` `swc` plugin example not working HOT 3
- Macro: t inside t causing ReferenceError: t is not defined HOT 3
- why not working plural macro? please help me...
- Improve React syntax with useLingui HOT 13
- [SIMPLE PATCH READY] Simple hack for compatibility with Turbopack (NextJS) HOT 2
- Missing auto-generated `id` for `<Trans>` macro when using Typescript HOT 4
- ERROR in ./node_modules/@lingui/macro/dist/index.mjs 347:24 Module parse failed HOT 7
- a special message cant compile. HOT 1
- `lingui` can be null HOT 2
- Compile messages to JSON HOT 5
- Support Gatsby HOT 2
- Cannot find type definition file for './node_modules/@lingui/macro/global'. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-lingui.