Home
Next.js
Next.js: Multiple languages with next-intl
Daniel Nguyen
Daniel Nguyen
September 16, 2026
1 min

Supporting multiple languages in Next.js can become complicated when you manage routing and translations yourself. next-intl simplifies internationalization (i18n) by providing translation APIs, locale-aware navigation, and routing support.

npm install next-intl

1. Create Translation Files

Create one JSON file for each language:

messages/
├── en.json
└── vi.json

messages/en.json

{
"Home": {
"title": "Welcome to Green Garden"
}
}

messages/vi.json

{
"Home": {
"title": "Chào mừng đến Green Garden"
}
}

2. Configure Routing

This defines the supported languages and sets Vietnamese as the default locale. Create src/i18n/routing.ts:

import { defineRouting } from "next-intl/routing";
export const routing = defineRouting({
locales: ["en", "vi"],
defaultLocale: "vi",
});

3. Configure Request Settings

This loads the correct translation file based on the requested locale and falls back to Vietnamese if the locale is unsupported. Create src/i18n/request.ts:

import { getRequestConfig } from "next-intl/server";
import { hasLocale } from "next-intl";
import { routing } from "./routing";
export default getRequestConfig(async ({ requestLocale }) => {
const requestedLocale = await requestLocale;
const locale = hasLocale(
routing.locales,
requestedLocale
)
? requestedLocale
: routing.defaultLocale;
return {
locale,
messages: (
await import(`../../messages/${locale}.json`)
).default,
};
});

4. Configure Next.js

Update next.config.ts:

import createNextIntlPlugin from "next-intl/plugin";
import type { NextConfig } from "next";
const nextConfig: NextConfig = {};
export default createNextIntlPlugin()(nextConfig);

5. Set Up Locale Routing

Create src/proxy.ts for Next.js 16:

import createMiddleware from "next-intl/middleware";
import { routing } from "./i18n/routing";
export default createMiddleware(routing);
export const config = {
matcher: "/((?!api|trpc|_next|_vercel|.*\\..*).*)",
};

Organize your pages under the [locale] segment:

src/app/
└── [locale]/
├── layout.tsx
├── page.tsx
└── plants/
└── page.tsx

6. Create the Locale Layout

Create src/app/[locale]/layout.tsx:

import { hasLocale } from "next-intl";
import { getMessages, setRequestLocale } from "next-intl/server";
import { NextIntlClientProvider } from "next-intl";
import { notFound } from "next/navigation";
import { routing } from "@/i18n/routing";
export function generateStaticParams() {
return routing.locales.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params,
}: {
children: React.ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
if (!hasLocale(routing.locales, locale)) {
notFound();
}
setRequestLocale(locale);
const messages = await getMessages();
return (
<html lang={locale}>
<body>
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
</body>
</html>
);
}

7. Use Translations

In a Server Component, use getTranslations:

import { getTranslations } from "next-intl/server";
export default async function HomePage() {
const t = await getTranslations("Home");
return <h1>{t("title")}</h1>;
}

The output depends on the current locale:

  • /vi → Chào mừng đến Green Garden
  • /en → Welcome to Green Garden

For Client Components, use useTranslations with "use client".


Tags

#NextJS

Share

Daniel Nguyen

Daniel Nguyen

Frontend Developer

Frontend developer specializing in React, Next.js, and JavaScript. Writing practical guides on modern web development at Dev98.

Expertise

React
Next.js
JavaScript
TypeScript
Python

Social Media

githublinkedinyoutubewebsite

Related Posts

Next.js
Supabase: Clients in Next.js
October 30, 2026
2 min
Dev98

Dev98

React · Next.js · Web development