[Next.js]

Add missing strings to an existing next-i18next setup

Polyglot detects your public/locales catalogs and namespaced hooks, then merges new keys into the files your app already loads — no parallel catalog, no broken lookups.

1 Min. LesezeitAlle Frameworks

Most next-i18next projects aren't starting from zero — they have public/locales/en/common.json, namespaced useTranslation() hooks, maybe typed keys. The dangerous failure mode for any automation is writing keys somewhere your app never loads. Polyglot is built to be a guest in your catalog world instead.

The transformation

Before — pages/index.tsx
import { useTranslation } from 'next-i18next';

export default function Home() {
  const { t } = useTranslation();
  return (
    <main>
      <h1>Welcome back</h1>
      <p>{t('title')}</p>
    </main>
  );
}
After — pages/index.tsx
import { useTranslation } from 'next-i18next';

export default function Home() {
  const { t } = useTranslation();
  return (
    <main>
      <h1>{t('welcome_back')}</h1>
      <p>{t('title')}</p>
    </main>
  );
}

Notice the call is t('welcome_back') — relative, because your component's t is bound to a namespace. Polyglot reads useTranslation('ns') arguments and keyPrefix options and generates keys that resolve through the exact translator each component binds.

Keys merge into YOUR files

Merged into — public/locales/de/common.json
{
  "title": "Meine App",
  "welcome_back": "Welcome back"
}
Merged into — public/locales/en/common.json
{
  "title": "My App",
  "welcome_back": "Welcome back"
}
  • New keys land in the bound namespace file — defaultNS and localePath from next-i18next.config.js are honored.
  • Your key order and formatting survive. Merges are textual edits, not a serializer round-trip that alphabetizes your catalog.
  • Existing keys get reused. If a string's exact text already exists in the bound namespace, Polyglot calls the existing key instead of minting a duplicate — your German translation for it keeps working untouched.
  • Typed-key setups (CustomTypeOptions deriving from your JSON) type-check after wrap, because the key really is in the catalog the types derive from.

Wiring verified

✓ 1 strings auto-wrapped · 0 flagged for manual review · 0 unsafe transforms → polyglot-i18n-report.md
✓ wiring checks passed (0 injected import(s), 1 catalog value(s), 2 catalog file(s))

Try it on your repo

$ curl -fsSL https://getpolyglot.ai/install.sh | bash
$ polyglot init --framework nextjs
$ polyglot scan
$ polyglot wrap
$ polyglot translate --languages de   # 50 strings free, no signup

The dry run prints every planned change and writes nothing. If Polyglot can't resolve where a key should live, it flags the string with a recipe instead of guessing.

Im Terminal starten

Schluss mit der Suche nach unübersetzten Strings.

Installieren Sie die CLI, führen Sie einen Scan durch und sehen Sie genau, was Ihnen fehlt. Kostenlos, kein Konto erforderlich.

$curl -fsSL https://getpolyglot.ai/install.sh | bash
Add missing strings to an existing next-i18next setup | Polyglot