published fresh until

Next.js: how do I extract hardcoded strings into i18n keys?

Summary As of October 2026, keep your existing i18n runtime and migrate one route at a time: inventory visible strings, wrap them deliberately, extract catalogs, then lint for new literals. next-intl now documents experimental inline extraction; Lingui offers macro-based extraction. If you use Lingui, run lingui extract.

Not for choosing App Router locale routing, see nextjs-app-router-i18n-next-intl-or-react-i18next

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Keep the existing i18n runtime, migrate visible strings one route at a time, and add extraction plus lint checks so hardcoded UI text stops returning.

What changed

How to migrate

1. Inventory JSX text, visible string attributes such as placeholder, title and accessible labels, form errors, metadata and toast text. Exclude route IDs, analytics names, CSS classes, code examples and user-authored content. Mark ambiguous strings for review. 2. Pick the matching row below. Keep an existing next-intl or i18next app on its runtime unless a separate migration has been justified. For explicit stable keys, next-intl's useTranslations('Checkout') with t('pay') and messages/en.json remains a straightforward path. 3. If deliberately adopting next-intl inline extraction, follow the linked experimental setup: createNextIntlPlugin receives experimental.extract, experimental.messages and experimental.srcPath. The docs show extract: true with message path, format, locales and sourceLocale. Start with one component using useExtracted; confirm catalog output before expanding. This is generated-key extraction, not a requirement to convert an existing hand-keyed catalog. 4. On react-i18next, wrap selected strings with t/<Trans> and use an extractor supported by the current i18next documentation. Configure scan paths, namespaces and key syntax for the actual project. Runtime missing-key collection sees executed paths only. Do not assume changing a lint rule extracts a catalog. 5. On Lingui, wrap JSX with <Trans> from @lingui/react/macro and other messages with its documented macros; then run lingui extract and the project compile step through the local CLI. Confirm the Next.js integration and macro transform before changing many files. 6. For bulk wrapping, have the agent write a small AST codemod and fixtures for the patterns you actually use. Preview one route first. Rewrite complete phrases with interpolation and plurals, not fragments joined by concatenation. Preserve whitespace, rich-text elements and Server/Client Component boundaries; do not add a hook in module scope or an async Server Component. 7. Add a regression lint gate. Lingui's ESLint plugin offers lingui/no-unlocalized-strings. Its rule configuration needs project-specific exclusions. The i18next ecosystem's eslint-plugin-i18next provides i18next/no-literal-string; verify the rule options and the accepted wrappers before enabling it. Start with migrated UI folders and expand deliberately. Documentation checked 2026-10-28. 8. In CI, typecheck and production-build the Next.js app, regenerate catalogs, and fail on an unexpected catalog diff. On Lingui, lingui check sync checks source/catalog synchronization, and lingui check missing --mode catalog catches untranslated entries before fallbacks; see the current CLI, checked 2026-10-28. Capture the migrated routes in the source and target locales and inspect accessible names as well as visible labels.

Versions and licences

Official repository manifest snapshots, checked on the dates shown below, rather than verified npm dist-tags. Choose reviewed compatible pins; adopting a new runtime is a separate migration.

RuntimeSnapshot and licenceOfficial source
next-intlAs of November 2026, 4.16.0; MIT; checked 2026-11-24Manifest
react-i18nextAs of November 2026, 18.0.3; MIT; checked 2026-11-24Manifest
@lingui/coreAs of November 2026, 6.12.0; MIT; checked 2026-11-24Manifest

When to pick which

OptionPick whenNot for
next-intl manual keysThe app already uses next-intl and translators need deliberate stable IDsAssuming it scans arbitrary unwrapped JSX
next-intl useExtractedInline source messages and generated keys fit, and you accept an experimental APITreating a historical RFC as the current setup guide
react-i18next + extraction toolingExisting namespaces, plugins and translation operations are built around i18nextExpecting runtime collection to visit every screen
Lingui macros + CLIExtraction and compile-time message workflows are central to the projectAvoiding macro/build integration work

What breaks

Unwrapped literals remain in English. Treat any codemod output as untested: review it for translated identifiers, lost spaces around inline elements and hooks used where they are invalid. Plural fragments that worked in English may produce incorrect target-language sentences. Hash-based generated IDs can change when source wording changes; inspect catalog churn before approving deletions.

What to test

Require codemod fixtures for JSX text, attributes, interpolation, rich text, plural messages, server/client code and excluded non-UI strings. A second pass should be empty. Confirm the production build renders both locales without hydration mismatches, translated errors remain accessible, and an intentionally added UI literal makes lint fail.

Community evidence

  • In next-intl discussion 456, ReesMorris reports building custom extraction after a catalog became hard to maintain; the discussion also records tradeoffs around descriptions, hashes and bundler integration. This is experience with a custom approach, not proof that it is the preferred current integration.
  • In useExtracted feedback discussion 2036, amannn addresses locale-catalog configuration and users report integration difficulties. Treat the discussion as feedback and use the current official docs for configuration; reports on other versions do not establish your app's behaviour.

Pitfalls

Do not switch i18n libraries merely to run one extraction pass. Do not auto-delete dynamic keys without an allowlist or turn lint false positives into broad exemptions. Avoid using one generic key for words with different meanings. Have a human review grammar, translator context and catalog deletions.

A prompt for your agent

Your training data may predate next-intl extraction and the current Lingui CLI. Read the linked official extraction and lint pages before editing; do not guess package names or flags. Inspect our installed runtime and component boundaries. Inventory one route's user-visible strings, propose keys and context, write bounded codemod fixtures, then migrate that route and prove extraction, lint, typecheck and production build work. List dynamic keys and ambiguous text for review.

Limits

No codemod, extraction, lint run or Next.js build was executed. Community evidence is concentrated in next-intl discussions, with no independent comparative trial across all three runtimes. Extraction finds statically recognized patterns; it cannot guarantee complete coverage of dynamic content or accurate translations.

Started from a post by @amannn, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Next.js: how do I extract hardcoded strings into i18n keys?
Summary: As of October 2026, keep your existing i18n runtime and migrate one route at a time: inventory visible strings, wrap them deliberately, extract catalogs, then lint for new literals. next-intl now documents experimental inline extraction; Lingui offers macro-based extraction. If you use Lingui, run `lingui extract`.
Copy for agent
get the whatworks thread nextjs-extract-hardcoded-strings-i18n-keys-codemod-lint and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread nextjs-extract-hardcoded-strings-i18n-keys-codemod-lint
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks