-
-
Notifications
You must be signed in to change notification settings - Fork 331
feat: Add useExtracted (experimental)
#2080
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # packages/next-intl/.size-limit.ts # packages/next-intl/__mocks__/react.tsx # packages/next-intl/src/navigation/shared/createSharedNavigationFns.tsx # packages/next-intl/src/react-server/index.test.tsx # packages/next-intl/src/server/react-server/RequestLocale.tsx # packages/next-intl/src/server/react-server/getConfig.tsx
# Conflicts: # pnpm-lock.yaml
…rbo-config # Conflicts: # pnpm-lock.yaml
In Next.js 15.3, [Turbopack config has become stable](https://nextjs.org/blog/next-15-3#turbopack-configuration-in-nextconfigts-stable). With this fix, the new option is used in order to avoid a deprecation warning.
# Conflicts: # packages/next-intl/src/plugin/getNextConfig.tsx
…on APIs (#1922) With #959, the middleware already handled decoding of non-ASCII characters. This allows you to define localized [`pathnames`](https://next-intl.dev/docs/routing#pathnames) like so: ```tsx import {defineRouting} from 'next-intl/routing'; export const routing = defineRouting({ locales: ['en', 'ja'], defaultLocale: 'en', pathnames: { '/about': { 'de': '/über-uns' } } ``` Since Next.js automatically encodes incoming pathnames, this supports incoming requests both for decoded pathnames (e.g. `/de/über-uns`), as well as encoded ones (e.g. `/de/%C3%BCber-uns`). One piece has been missing though: Pathnames returned from [navigation APIs](https://next-intl.dev/docs/routing/navigation) should be turned into an encoded form. Now, `next-intl` handles this as well: ```tsx import {Link, getPathname} from '@/i18n/navigation'; // href="/de/%C3%BCber-uns" <Link href="/about" locale="de" /> // pathname = "/de/%C3%BCber-uns" const pathname = getPathname({href: '/about', locale: 'de'}); ``` This change brings the navigation APIs in line with [Google's recommendation to encode non-ASCII pathnames](https://developers.google.com/search/docs/crawling-indexing/url-structure).
# Conflicts: # examples/example-app-router-playground/tests/main.spec.ts
<!-- CURSOR_SUMMARY --> > [!NOTE] > Introduces an experimental message extraction pipeline (JSON/PO) with new `useExtracted`/`getExtracted` APIs, Turbopack/Webpack loaders, and an example app showcasing it. > > - **Experimental extraction**: > - Add extractor core (`src/extractor/*`): compiler, catalog manager/locales/persister, save scheduler, SWC-based message extractor, formatters (JSON/PO), utilities, and public export `next-intl/extractor`. > - New loaders: `extractor/extractionLoader` and `extractor/catalogLoader` (+ `.d.ts` shims). > - **Plugin/Config**: > - Extend plugin to wire loaders and rules for Turbopack/Webpack; add `experimental.srcPath`, `messages` and `extract` options; refactor next flags (`hasStableTurboConfig`, `isNextJs16OrHigher`). > - Adjust rollup build and type exposure; size-limit tweaks. > - **APIs**: > - React: export `useExtracted` (client/server) and server `getExtracted`; client re-exports from `use-intl/react`. > - **Examples/Tests**: > - New example `examples/example-app-router-extracted` demonstrating extraction; extensive extractor tests. > - Bump `examples/example-use-intl` to `use-intl@^4`. > - **Misc**: > - Package metadata/exports/files updates; add `@swc/core` and `@types/webpack` dev dep; remove obsolete example config. > - Tools: simplify side-effect import stripping in build script. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit db387c4. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on December 27
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
|
|
||
| // This message continues to exist in this file | ||
| const index = idsToRemove.indexOf(message.id); | ||
| if (index !== -1) idsToRemove.splice(index, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug
When a message is removed from a file, the code only deletes it from messagesById if it was in idsToRemove. However, this logic is flawed because a message might be used in multiple files. When removing a message from one file, the code should only delete it from messagesById if it's not used in any other file. Currently, if a message exists in File A and File B, and you remove it from File A, it will be incorrectly deleted from messagesById even though it's still used in File B. This will cause the message to disappear from the catalog entirely, breaking File B's translations.
The fix should check if the message ID exists in any other file before deleting from messagesById:
for (const id of idsToRemove) {
// Only delete if not used in any other file
let usedElsewhere = false;
for (const [filePath, messages] of this.messagesByFile) {
if (filePath !== absoluteFilePath && messages.has(id)) {
usedElsewhere = true;
break;
}
}
if (!usedElsewhere) {
this.messagesById.delete(id);
}
}
→ Discussion
TODO
Note
Adds experimental message extraction (extractor, loaders, plugin options) and new
useExtracted/getExtractedAPIs, with docs and an example app.useExtracted(client/server) andgetExtractedutilities; fallback handling and tests; types exported to support usage.src/extractor/**): compiler, catalog (JSON/PO) formatters/persistence, source scanning, utilities, tests.next-intl/extractor/extractionLoader,.../catalogLoader) and wire via plugin options (extract,messages,srcPath) increateNextIntlPlugin/getNextConfig.@swc/core; adjust size limits.docs/src/pages/docs/usage/plugin.mdx), refine configuration docs, nav meta updates, minor footer/links tweaks.examples/example-app-router-extractedshowcasing extraction (PO catalogs, tests); remove legacyexamples/example-app-router-single-locale/next.config.mjs; bumpexamples/example-use-intltouse-intl@^4.tools/src/getBuildConfig.js.Written by Cursor Bugbot for commit c8efecc. This will update automatically on new commits. Configure here.