Next.js
Add i18n to Next.js with @babelize/sdk/next: a proxy (middleware) for locale detection, server and client component translation, and a build plugin.
@babelize/sdk/next provides Next.js-specific integration: a proxy for locale detection, server component translation, and build-time lockfile generation.
npm install @babelize/sdk @babelize/nextSDK or CLI?
Babelize has two ways to localize a Next.js app. Pick one per app:
npx babelize translate (CLI) | @babelize/sdk (this page) | |
|---|---|---|
| Your code | Rewritten once: hardcoded text becomes next-intl t() calls | You wrap text in babelizeRSC() / babelize() yourself |
| Translations live in | JSON locale files you commit and can edit | A lockfile the build plugin generates |
| URLs | A URL per language (/ja/…) by default | One URL; the locale comes from a cookie or the browser |
| Best for | An existing app you want translated with the least work | New code where you want translation calls written by hand |
See CLI › Translate for the CLI path.
Proxy
The proxy detects the user's locale and makes it available to your server and client components. In Next.js 16 the file is proxy.ts (it was middleware.ts before; that name still works but is deprecated).
// proxy.ts (middleware.ts before Next.js 16)
import { babelizeMiddleware } from "@babelize/sdk/next";
export default babelizeMiddleware({
supportedLocales: ["en", "ja", "fr", "de"],
defaultLocale: "en",
});
export const config = {
matcher: "/:path*",
};Detection Order
The proxy determines the locale by checking these sources in order:
babelize-localecookie — persists the user's preference across visitsAccept-LanguageHTTP header — the browser or system languagedefaultLocale— the configured fallback
It sets the x-babelize-locale response header and babelize-locale cookie so both server and client components can access the current locale.
Options
interface BabelizeMiddlewareOptions {
supportedLocales?: string[]; // Restrict to specific locales
defaultLocale?: string; // Fallback locale (default: "en")
localeCookie?: string; // Cookie name (default: "babelize-locale")
}Server Components
Use babelizeRSC() in async Server Components. It reads the locale from the proxy's x-babelize-locale header and translations from the pre-loaded lockfile.
Load the lockfile once at module scope, then use babelizeRSC anywhere:
// app/page.tsx
import { babelizeRSC, loadLockfile } from "@babelize/sdk/next";
import lockfile from "../babelize-lock.json";
loadLockfile(lockfile);
export default async function Home() {
return (
<div>
<h1>{await babelizeRSC("Welcome to Babelize")}</h1>
<p>{await babelizeRSC("Hello {name}", { name: "World" })}</p>
</div>
);
}Server component translations come entirely from the lockfile — no API calls, no JavaScript shipped to the client.
Client Components
For interactive parts of your app, use the React hooks from @babelize/sdk/react:
"use client";
import { useBabelize, useLocale } from "@babelize/sdk/react";
export function LocaleAwareSection() {
const babelize = useBabelize();
const { setLocale } = useLocale();
return (
<div>
<p>{babelize("This text updates when locale changes")}</p>
<button onClick={() => setLocale("fr")}>
{babelize("Switch to French")}
</button>
</div>
);
}Build Plugin
Add the build plugin to automatically discover and pre-translate strings during next build:
// next.config.ts
import withBabelize from "@babelize/next";
export default withBabelize(
{
// your Next.js config
},
{
locales: ["ja", "fr", "de"],
},
);The plugin scans your source files, extracts strings, and generates babelize-lock.json — no manual configuration needed.
Architecture
Request → Edge Middleware → Server Component → Client Component
│ │ │
Detects locale Reads lockfile React hooks
Sets cookie Returns string Re-renders
Sets header No API calls Cache-awareTypeScript
import type { BabelizeMiddlewareOptions } from "@babelize/sdk/next";
interface BabelizeMiddlewareOptions {
supportedLocales?: string[];
defaultLocale?: string;
localeCookie?: string;
}Further Reading
Last updated: 2026-11-01
React
React bindings for the Babelize SDK: the provider, hooks and components for reactive translations, usage with the Next.js App Router, and TypeScript support.
Vite Plugin
The @babelize/vite plugin scans your source for babelize() calls and generates a translation lockfile at build time. Setup, options, and mock mode.