Next.js 16 i18n: proxy.ts, App Router and Server Components
Next.js 16 renamed middleware.ts to proxy.ts. If your i18n routing lives in middleware, that is the one file you have to touch. Everything else in a...
Table of Contents
Next.js 16 renamed middleware.ts to proxy.ts. If your i18n routing lives in middleware, that is the one file you have to touch. Everything else in a Next.js i18n setup (Server Components, generateStaticParams, hreflang) works the way it did in 15.
This guide builds a Next.js 16 app with locale routing, Server Components, a client component, CDN-delivered translations and per-locale SEO tags. It uses @better-i18n/next on top of next-intl. The code runs: full repo.
Tested on Next.js 16.4.6, next-intl 4.16.2, React 19.3.1 and @better-i18n/next 0.10.0.
1. What changed in Next.js 16
Two things matter for i18n.
middleware.ts is now proxy.ts. The old name still exists but is deprecated. The exported function is called proxy. You can migrate with the official codemod:
npx @next/codemod@latest middleware-to-proxy .
It renames the file, renames the middleware export to proxy, and renames the related config flags (for example skipMiddlewareUrlNormalize to skipProxyUrlNormalize).
proxy.ts runs on the Node.js runtime. You cannot set runtime in it, and the edge runtime is not supported. The Next.js upgrade guide says that if you need edge, keep using middleware. For i18n this is usually fine. Locale detection is a few header and cookie reads.
One gotcha: with a src/ directory, proxy.ts must live in src/, next to app/. Put it in the project root and Next.js ignores it with no error. Your / route will just 404. The build output should list ƒ Proxy (Middleware). If it does not, the file is in the wrong place.
next-intl added Next.js 16 support in 4.4.0 and documents proxy.ts itself. Any current 4.x works. (I checked the next-intl release notes. The only Next.js 16-related claims I rely on here are from there and from the Next.js docs.)
2. Project setup
npm install next@16 react react-dom next-intl @better-i18n/next
@better-i18n/next declares peer dependencies on next >=15, next-intl >=4, and React 18+. It uses next-intl for routing and message formatting, and adds the CDN fetching, the locale detection and a client provider.
Create the config once and import it everywhere:
// i18n.config.ts
import { createI18n } from "@better-i18n/next";
export const i18n = createI18n({
project: "better-i18n/demo", // org-slug/project-slug
defaultLocale: "en",
localePrefix: "always",
timeZone: "UTC",
});
localePrefix accepts "always", "as-needed" (the default) or "never". I use "always": every URL has a locale, /en and /tr, which keeps hreflang simple. Setting timeZone avoids server and client formatting differences.
Hook it into next-intl:
// next.config.ts
import type { NextConfig } from "next";
import createNextIntlPlugin from "next-intl/plugin";
const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
const nextConfig: NextConfig = {};
export default withNextIntl(nextConfig);
// src/i18n/request.ts
import { i18n } from "../../i18n.config";
export default i18n.requestConfig;
requestConfig resolves the locale for each request and loads that locale's messages from the CDN.
3. Locale routing in proxy.ts
// src/proxy.ts
import { i18n } from "../i18n.config";
export const proxy = i18n.betterMiddleware();
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"],
};
That is the whole file. The matcher matters: without one, Next.js runs the proxy on static files too.
betterMiddleware() fetches the available locales from the manifest, detects the locale, and hands routing to next-intl. I ran it against the built app:
| Request | Result |
|---|---|
GET / with Accept-Language: tr-TR | 307 to /tr, plus a locale=tr cookie |
GET / with no header | 307 to /en |
GET / with NEXT_LOCALE=de | 307 to /de |
The last row is worth knowing. In "always" mode the redirect from / follows next-intl's own NEXT_LOCALE cookie. The locale cookie that Better i18n writes did not change the redirect in my test. If you rely on cookie persistence, test your own flow.
betterMiddleware() also takes a callback, which is where auth goes. It receives the detected locale and the response:
export const proxy = i18n.betterMiddleware(async (request, { locale }) => {
const loggedIn = request.cookies.has("session");
if (!loggedIn && request.nextUrl.pathname.startsWith(`/${locale}/account`)) {
return NextResponse.redirect(new URL(`/${locale}/login`, request.url));
}
// Return nothing to keep the i18n response (headers and cookies included).
});
(NextResponse comes from next/server. I did not run this exact callback in the demo repo; the callback signature is from the package types.)
i18n.proxy also exists on the object. It is the plain next-intl variant without the callback. Use betterMiddleware.
4. Server Components: messages and type-safe keys
The layout sets the request locale, loads messages and wraps the tree in the provider:
// src/app/[locale]/layout.tsx
import { getMessages, setRequestLocale } from "next-intl/server";
import { BetterI18nProvider } from "@better-i18n/next/client";
import { i18n } from "../../../i18n.config";
export async function generateStaticParams() {
const locales = await i18n.getLocales();
return locales.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const messages = await getMessages();
return (
<html lang={locale}>
<body>
<BetterI18nProvider locale={locale} messages={messages} config={i18n.config}>
{children}
</BetterI18nProvider>
</body>
</html>
);
}
In Next.js 16, params is a Promise. Await it.
Pages use getTranslations:
// src/app/[locale]/page.tsx
import { getTranslations, setRequestLocale } from "next-intl/server";
export default async function Home({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations("home");
return <h1>{t("badge")}</h1>;
}
Call setRequestLocale in every page and layout. In my first build I only called it in the layout, and /[locale] came out as dynamic (ƒ). After adding it to the page, the build listed /en, /ar, /de and the rest as static (●). Static pages are what you want for marketing and docs pages.
For type-safe keys, pull the source locale once and tell next-intl about its shape:
npx @better-i18n/cli pull -l en -o ./locales
// global.d.ts
import type messages from "./locales/en.json";
declare module "next-intl" {
interface AppConfig {
Messages: typeof messages;
}
}
Now t("badgee") fails tsc with a "not assignable to parameter" error. Re-run pull when you add keys. The typing comes from next-intl's AppConfig; the CLI's job is only to give you the JSON.
5. Client components and the provider
Client components use the same useTranslations hook. The provider from the layout passes messages down, so there is no second fetch.
// src/components/LocaleList.tsx
"use client";
import { useTranslations } from "next-intl";
type Language = { code: string; nativeName?: string };
export function LocaleList({ languages }: { languages: Language[] }) {
const t = useTranslations("footer");
return (
<>
<p>{t("languages", { count: languages.length })}</p>
<nav>
{languages.map((l) => (
<a key={l.code} href={`/${l.code}`} hrefLang={l.code}>
{l.nativeName ?? l.code}
</a>
))}
</nav>
</>
);
}
The server page fetches the language list with getManifestLanguages(i18n.config) from @better-i18n/next/server and passes it as a prop. I first used the client hook useManifestLanguages. It renders with an empty list on the server, so the server HTML said "0 languages" until the client fetched. Pass server data as props when the text has to be in the HTML.
For a switcher, plain links are the safest choice for SEO. The package also exports useSetLocale(). It sets the cookie and swaps messages on the client without a server round-trip. That is nice for apps behind a login. For public pages, I prefer real URLs.
6. Delivering translations from the CDN without a redeploy
Translations are not bundled into your build. @better-i18n/next reads them from the CDN at request time and caches them with Next.js's data cache. A translator publishes, and your site changes. No git push, no deploy. See CDN delivery for how publishing and edge caching work.
Defaults in 0.10.0 (read from the package source):
| Option | Default (production) | What it controls |
|---|---|---|
manifestRevalidateSeconds | 60 | How fast new locales show up |
messagesRevalidateSeconds | 5 | How fast edited strings show up |
Both are 0 in development. Versioned snapshot URLs are cached as immutable.
Waiting up to a minute is fine for most teams. If you want changes instantly, add the webhook route. It verifies the HMAC signature and revalidates the cache tags:
// src/app/api/i18n/revalidate/route.ts
import { createRevalidateHandler } from "@better-i18n/next/revalidate";
export const POST = createRevalidateHandler({
secret: process.env.BETTER_I18N_WEBHOOK_SECRET!,
});
Import it from @better-i18n/next/revalidate. The package root only exports its types. I tested the route: no signature returns 401, a valid x-better-i18n-signature returns 200 with {"revalidated":true,...}. On Next.js 16 it also prints a deprecation warning, because revalidateTag now expects a second argument. The call still works. The warning comes from the package, not from your code.
7. SEO: hreflang, canonical and sitemap per locale
Set alternates in generateMetadata. Use the locale list from the manifest, so a new language gets hreflang tags without a code change:
// src/app/[locale]/layout.tsx (add to the file above)
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { locale } = await params;
const locales = await i18n.getLocales();
return {
metadataBase: new URL(process.env.NEXT_PUBLIC_BASE_URL ?? "http://localhost:3000"),
alternates: {
canonical: `/${locale}`,
languages: {
...Object.fromEntries(locales.map((l) => [l, `/${l}`])),
"x-default": `/${i18n.config.defaultLocale}`,
},
},
};
}
I confirmed the HTML has <link rel="canonical">, one hreflang link per locale and x-default.
The sitemap needs the same alternates:
// src/app/sitemap.ts
import type { MetadataRoute } from "next";
import { i18n } from "../../i18n.config";
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL ?? "http://localhost:3000";
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const locales = await i18n.getLocales();
const languages = Object.fromEntries(locales.map((l) => [l, `${BASE_URL}/${l}`]));
return locales.map((locale) => ({
url: `${BASE_URL}/${locale}`,
lastModified: new Date(),
alternates: { languages },
}));
}
One rule from experience: only list a locale in the sitemap and hreflang if the page is really translated. A locale with English text under a /de/ URL is a duplicate-content problem, not a feature.
8. Migrating from the Next.js 15 setup
If you followed an older guide, the diff is small:
- Run
npx @next/codemod@latest middleware-to-proxy . - Check the result is in the right folder (
src/proxy.tsif you usesrc/). - Make sure
export default i18n.middlewarebecameexport const proxy = i18n.betterMiddleware(). The oldi18n.middlewareis marked deprecated in the package types. - Add
setRequestLocale(locale)to every page and layout under[locale]if you want static output. - Await
paramseverywhere. Runnpx @next/codemod@canary next-async-request-api .if any of it is still synchronous. - Bump
@better-i18n/nextto 0.10.0 andnext-intlto a 4.x version.
If you stay on Next.js 15 for now, middleware.ts keeps working. The package supports next >=15. If you are choosing a library, this comparison covers the options. For the short framework page, see Next.js i18n.
FAQ
Does middleware.ts still work in Next.js 16?
Yes, it is deprecated, not removed. The Next.js upgrade guide recommends proxy.ts, and middleware is the option if you still need the edge runtime.
Does next-intl work with Next.js 16?
Yes. next-intl 4.4.0 added Next.js 16 support and its docs cover proxy.ts. I ran 4.16.2 on Next.js 16.4.6.
Do I need to redeploy when a translation changes? No. Messages come from the CDN and are revalidated every 5 seconds in production by default. Add the webhook route if you want a publish to apply immediately.
Can I use this on the edge runtime?
Not with proxy.ts. It is Node.js only. Keep middleware.ts for edge, or use the Node runtime.
Try it
Clone the demo repo, change project in i18n.config.ts to your own, and run it. To host your own translations and publish without a deploy, create a free project.