npm next-i18next 16.5.0
v16.5.0

one hour ago
  • App Router: translated paths - new pathnames option: with localeInPath: true, { '/contact': { de: '/kontakt' } } serves /de/kontakt from app/[lng]/contact, redirects /de/contact to /de/kontakt, and redirects a path without locale straight to the translated path of the detected language. [param] and [...param] segments are supported (static routes match first, and createProxy throws when the two sides of an entry use different params), encoded paths and trailingSlash work, and with hideDefaultLocale the default language's translated paths work without prefix. New helpers getLocalizedPath and getInternalPath from next-i18next build links, the language switcher and hreflang alternates. New README section "Translated Paths". (#1381)
  • Pages Router: serverInstanceKey for one server instance per tenant - serverSideTranslations keeps one i18next instance per server process: the first call creates it with that call's backend options, later calls reuse it and the namespaces it has loaded. A config built per request (a tenant header for the translation API, say) therefore only counted on the first request after a start, and every tenant got the translations of that first one. With serverInstanceKey in the config passed to serverSideTranslations (the tenant, for example), next-i18next keeps one instance per key, each created with the backend options of the first call with that key. Keys must come from a known set: each instance and its backend's reload timer live until the server stops. Without the option nothing changes.
  • Docs: multi-tenant setups - new README section "Multi-tenant Setups": serverInstanceKey for the Pages Router, and for the App Router one createServerI18next per known tenant, kept across requests. (#2245, #2252, #2278)
  • App Router: no redirect loop with hideDefaultLocale on Next.js 16.3 - Next.js runs the proxy again for the target of a rewrite. hideDefaultLocale rewrites /about to /en/about, and that second run redirected /en/about back to /about, so every page of the default language ended in a redirect loop in next start (/ too). The proxy now marks its rewrites with an x-i18next-rewritten request header and serves such a request as is. The same applies to the new translated paths.
  • Pages Router: a config file written as an ES module is used - in a project with "type": "module", next-i18next.config.js exports the config with export default. serverSideTranslations loads that file with require(), which on current Node versions returns the module namespace ({ __esModule, default }) instead of the config. The server then ignored the config (defaultLocale and everything else), and with serializeConfig (the default) appWithTranslation threw "appWithTranslation was called without config.i18n" in the browser. The default export is now used. (#2256)
  • Docs: TROUBLESHOOT.md uses the v16 imports - "How to explicitly pass the config" imported from next-i18next and next-i18next/serverSideTranslations, which v16 no longer exports; it now uses next-i18next/pages and next-i18next/pages/serverSideTranslations. The unused serverSideTranslations.js shim from v15 in the repository root is removed (it was not part of the package).
  • Pages Router: no default addPath any more, and saveMissing is documented - since 16.0.0 the built-in loader that replaced i18next-fs-backend only reads the locale files, so saveMissing: true saved nothing and no .missing.json was written (16.0.0 said the loader behaves the same; it does not for missing keys). The config still set an addPath (….missing.json) that nothing used; it is gone, so a function localePath is only called with missing: false. New README section "Missing keys (saveMissing)": add a backend that can save, in the browser, such as i18next-http-backend with an addPath to your own API route, or i18next-locize-backend. (#1921)
  • Docs: the Pages Router sections are back in the README - the v16 README had dropped them: fallback locales, unserializable configs, fallback SSG pages, client-side loading over HTTP, reloading in development, an options table (localePath, localeStructure, serializeConfig, serverInstanceKey, ...), I18NEXT_DEFAULT_CONFIG_PATH, and notes for Vercel and Netlify and for Docker, all checked against v16. The restored sections have their v15 headings again, so existing links to them work. The pages-router-simple and pages-router-auto-static-optimize examples no longer mention the removed strictMode option and link the new options table.

Don't miss a new next-i18next release

NewReleases is sending notifications on new releases.