12 / 13
Translation, locale routing and date and currency formatting with next-intl.
Supporting multiple languages involves three separate jobs: working out the language from the URL (routing), translating the text (localization), and showing dates, numbers and currency according to the user's language (formatting).1 This guide sets all three up with next-intl. next-intl is a library specific to Next.js. If you use Vite and plain React, there is a short alternative at the end of the guide.
A locale is the identity of a set of language and formatting preferences. It usually holds the user's language and, optionally, their region: en-US is US English, nl-NL is Dutch in the Netherlands, nl is Dutch with no region.1
| Job | The question | In next-intl |
|---|---|---|
| Routing | Which language? /tr/urunler or /en/products? | defineRouting, the proxy |
| Localization | What is the text? | messages/*.json, useTranslations |
| Formatting | How are numbers, dates and money written? | useFormatter |
next-intl's formatting layer is built on the browser's built-in Intl API: Intl.DateTimeFormat, NumberFormat, PluralRules, RelativeTimeFormat and ListFormat provide the language-aware formatting.2
The setup was tried with Next.js 16 and next-intl 4.
pnpm add next-intlmessages/
├── tr.json
└── en.json
src/
├── i18n/
│ ├── routing.ts
│ ├── navigation.ts
│ └── request.ts
├── app/
│ └── [locale]/
│ ├── layout.tsx
│ └── page.tsx
└── proxy.ts
next.config.ts// next.config.ts
import type { NextConfig } from 'next'
import createNextIntlPlugin from 'next-intl/plugin'
const nextConfig: NextConfig = {}
const withNextIntl = createNextIntlPlugin()
export default withNextIntl(nextConfig)// src/i18n/routing.ts
import { defineRouting } from 'next-intl/routing'
export const routing = defineRouting({
locales: ['tr', 'en'],
defaultLocale: 'tr',
})locales is every language you support, and defaultLocale is the fallback used when none of them matches.3
// src/proxy.ts
import createMiddleware from 'next-intl/middleware'
import { routing } from './i18n/routing'
export default createMiddleware(routing)
export const config = {
// skip /api, /trpc, /_next, /_vercel and any path with a dot in it (favicon.ico and the like)
matcher: '/((?!api|trpc|_next|_vercel|.*\\..*).*)',
}// src/i18n/navigation.ts
import { createNavigation } from 'next-intl/navigation'
import { routing } from './routing'
export const { Link, redirect, usePathname, useRouter, getPathname } =
createNavigation(routing)// src/i18n/request.ts
import * as rootParams from 'next/root-params'
import { notFound } from 'next/navigation'
import { getRequestConfig } from 'next-intl/server'
import { hasLocale } from 'next-intl'
import { routing } from './routing'
export default getRequestConfig(async ({ locale }) => {
if (!locale) {
const paramValue = await rootParams.locale()
if (hasLocale(routing.locales, paramValue)) {
locale = paramValue
} else {
notFound()
}
}
return {
locale,
messages: (await import(`../../messages/${locale}.json`)).default,
}
})// src/app/[locale]/layout.tsx
import { NextIntlClientProvider } from 'next-intl'
import { getLocale } from 'next-intl/server'
import { routing } from '@/i18n/routing'
export function generateStaticParams() {
return routing.locales.map((locale) => ({ locale }))
}
export default async function LocaleLayout({ children }: { children: React.ReactNode }) {
const locale = await getLocale()
return (
<html lang={locale}>
<body>
<NextIntlClientProvider>{children}</NextIntlClientProvider>
</body>
</html>
)
}Move your existing layout.tsx and page.tsx under app/[locale]/.4 generateStaticParams builds the page statically at build time for every language.4
Warning
Watch the version. The proxy.ts file is the new name for middleware.ts, used from Next.js 16 onwards. next/root-params is on by default in Next.js 16.3 and later; earlier versions need the experimental.rootParams setting.4 In tutorials written for Next.js 15 you will see middleware.ts and setRequestLocale; the concepts are the same.5
Using a translation in a component:
// messages/tr.json
{
"HomePage": {
"title": "Mağazaya hoş geldiniz"
}
}// src/app/[locale]/page.tsx
import { useTranslations } from 'next-intl'
export default function HomePage() {
const t = useTranslations('HomePage')
return <h1>{t('title')}</h1>
}useTranslations('HomePage') binds the call to a namespace, and t('title') resolves to the HomePage.title key. In an async Server Component, use getTranslations instead of useTranslations.67
You can do the routing with a path prefix (/fr/products) or with a domain (my-site.fr/products).1 The user's browser language arrives in the Accept-Language header, and it is the recommended basis for choosing a language.1
next-intl does this in the proxy. In a trial run, a request arriving with Accept-Language: en-US was redirected from / to /en, and one with tr-TR to /tr. An unsupported path (/de) is redirected to /en/de and falls through to a 404.
| Option | Meaning | Default |
|---|---|---|
localePrefix: 'always' | A language prefix on every path: /en/about | Yes3 |
localePrefix: 'as-needed' | No prefix in the default language (/about), a prefix in the others (/de/about)3 | |
localePrefix: 'never' | No language prefix in the URL. Useful with domain- or cookie-based routing3 | |
localeDetection | Detects the language from the Accept-Language header and the cookie | On. Set it to false and the language comes only from the URL3 |
localeCookie | Stores the last detected language in the NEXT_LOCALE session cookie | On3 |
pathnames | Translates the paths too: '/about': { de: '/über-uns' }3 | None |
domains | Binds each domain to its own languages3 | None |
The docs suggest translating the paths as well (pathnames) when SEO matters.3
Take components like Link, redirect and useRouter from @/i18n/navigation rather than next/link. They add the language prefix for you and handle localized paths (/de/über-uns, for example).4 To switch language, the locale prop is enough:
import { Link } from '@/i18n/navigation'
<Link href="/" locale="en">EN</Link>The Next.js docs also show a route with no library: picking the language in the proxy with @formatjs/intl-localematcher and negotiator and redirecting to a path like /en-US/products, moving every special file under app/[lang], and loading a dictionary (dictionaries/en.json) for each language.1 Because the dictionaries are loaded in a Server Component, the translation files do not grow the client bundle.1 This route means fewer dependencies, but you write the plural, formatting and localized-link work yourself. The docs list other libraries too: next-international, lingui, tolgee, paraglide-next.1
Messages are one JSON file per language and can be nested. Keys cannot contain a dot, because the dot expresses the nesting.6 You write the text in ICU syntax:
// messages/tr.json
{
"HomePage": {
"title": "Mağazaya hoş geldiniz",
"cart": "{count, plural, =0 {Sepetiniz boş} =1 {Sepetinizde 1 ürün var} other {Sepetinizde # ürün var}}",
"price": "Fiyat: {price, number, ::currency/TRY}",
"date": "Güncelleme tarihi: {date, date, long}"
}
}const t = useTranslations('HomePage')
t('cart', { count: 2 }) // Sepetinizde 2 ürün var
t('price', { price: 1234.5 }) // Fiyat: ₺1.234,50
t('date', { date }) // Güncelleme tarihi: 16 Ekim 2026 (in the server's time zone)Arguments: "Hello {name}!" with t('message', { name: 'Jane' }). Argument names hold letters, digits and underscores. To write a curly brace as text, use a single quote.6
Plurals: {count, plural, =0 {...} =1 {...} other {...}}. The # formats the number. The categories are zero, one, two, few, many and other. An exact match (=0) takes priority.6 In a trial run, Intl.PluralRules returned other, one and other for 0, 1 and 2 in Turkish, English and German alike. In languages such as Polish and Arabic, extra categories like few and many come into play, which is why you should leave the plural rule to the translator of each language.
Select: {gender, select, female {...} male {...} other {...}}. The other branch is required.6
Rich text: binds the tags inside a message to a component: t.rich('message', { guidelines: (chunks) => <a href="/rules">{chunks}</a> }). t.raw returns the raw content, so sanitize it before using it with dangerouslySetInnerHTML.6
You can do the formatting inside the message with ICU, or in code with useFormatter:
import { useFormatter } from 'next-intl'
const format = useFormatter()
const updated = new Date('2026-10-15T21:00:00Z')
format.number(1234.5, { style: 'currency', currency: 'EUR' })
format.dateTime(updated, { dateStyle: 'long', timeZone: 'Europe/Istanbul' })
format.relativeTime(updated, now) // en: "2 hours ago"format.number and format.dateTime accept the Intl.NumberFormat and Intl.DateTimeFormat options from MDN.89 The same value is written like this by language:
| Locale | Money (1234.5) | Date (October 15, 2026, 21:00 UTC, Istanbul) |
|---|---|---|
tr | ₺1.234,50 | 16 Ekim 2026 |
en | $1,234.50 | October 16, 2026 |
de | 1.234,50 € | 16. Oktober 2026 |
In the table it is the product itself that decides the currency code (TRY, USD, EUR), and the locale only decides how it is displayed. The thing to watch with the date is the time zone: the same instant is October 15 in UTC and October 16, 00:00 in Istanbul. Pass the time zone explicitly and store dates as full ISO 8601 text, like 2020-11-20T10:36:01.516Z.9
relativeTime rounds its values, so 126 minutes shows as "2 hours ago". To force the unit, pass { now, unit: 'day' }. The useNow hook gives you the reference time and can keep updating with updateInterval.9
You can define global formats and use them by name: format.dateTime(date, 'short'), format.number(499.9, 'price', { currency: 'USD' }).98
You tell a search engine about the language versions of the same content with hreflang. Google accepts it as HTML <link> tags, as an HTTP Link header or in an XML sitemap, and the three are equivalent, so pick one.10
Be reciprocal: every version has to list itself and all the others. If two pages do not point at each other, the tags are ignored.10
The codes: an ISO 639-1 language code and an optional ISO 3166-1 Alpha 2 region code (tr, en-GB). A country code cannot stand on its own.10
x-default: the fallback page for users who match no language, a language selection page for example.10
Full URLs: the alternate addresses have to be written with their protocol.10
Google does not detect the language from lang or hreflang; hreflang only groups the versions.10
In next-intl, alternateLinks is on by default. The proxy adds the link header for search engines itself, x-default included.3 In a trial run, the /tr response carried this header:
link: <http://localhost:3100/tr>; rel="alternate"; hreflang="tr",
<http://localhost:3100/en>; rel="alternate"; hreflang="en",
<http://localhost:3100/>; rel="alternate"; hreflang="x-default"To add your own links, set alternateLinks: false.3 Use a translation for the page title and description too:
import { getTranslations } from 'next-intl/server'
export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
const { locale } = await params
const t = await getTranslations({ locale, namespace: 'Metadata' })
return { title: t('title') }
}Writing translation keys into JSON by hand is enough on a small project, but it becomes a management problem as you grow. One video uses a cloud platform called i18nexus: when a new translation is added, the platform translates the text into the other languages with OpenAI and the CLI downloads the translation JSON files into the project.5 That is a commercial service and not the only option. The docs list other tools such as tolgee and lingui.1 Whichever you pick, having a human review the machine translation is a good rule.
next-intl cannot be used in a Vite or plain React project. A common alternative is react-i18next: the useTranslation hook returns t and i18n, and it is wired up with initReactI18next.11
// src/i18n.ts
import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
i18n.use(initReactI18next).init({
lng: 'tr',
fallbackLng: 'en',
resources: {
en: { translation: { title: 'Welcome', cart_one: '{{count}} item', cart_other: '{{count}} items' } },
tr: { translation: { title: 'Hoş geldiniz', cart_one: '{{count}} ürün', cart_other: '{{count}} ürün' } },
},
interpolation: { escapeValue: false },
})
export default i18nimport { useTranslation } from 'react-i18next'
const { t } = useTranslation()
t('title') // Hoş geldiniz
t('cart', { count: 2 }) // 2 ürünThe plural syntax here is not ICU but i18next's _one and _other key suffixes. This setup was tried on the server with renderToString. The routing, the language in the URL and the hreflang work are all yours to write in this case.
Add tr and en to one of your e-commerce pages. Verify that / redirects according to the browser language.
Write the cart text with plural and check the output for 0, 1 and 2.
Show the price and the date with useFormatter. Change the language and watch the separators (the dot and the comma) and the month names change.
Set localePrefix: 'as-needed' and see the prefix disappear in the default language. Look at the link header with curl -I.
Watch the Next.js 15: i18n with next-intl video and note the differences from your own version.5
Sources
The locale concept, routing by sub-path or domain, `Accept-Language`, dictionaries, `generateStaticParams` and the library list.
The language-aware formatting APIs: `DateTimeFormat`, `NumberFormat`, `PluralRules`, `RelativeTimeFormat`, `ListFormat`.
`locales`, `defaultLocale`, `localePrefix`, `localeDetection`, `localeCookie`, `alternateLinks`, `pathnames` and `domains`.
`routing.ts`, `proxy.ts`, `navigation.ts`, `request.ts`, the `[locale]` segment and the Next.js version notes.
The `[locale]` segment, the configuration files, static generation, the locale switcher and AI-assisted translation with i18nexus. August 2025.
The JSON structure, namespaces, and the ICU argument, plural, select and rich text syntax.
Setup, `createNextIntlPlugin`, `useTranslations` and `getTranslations`.
`format.number`, currency, global formats and the ICU number formats.
`format.dateTime`, `relativeTime`, `useNow` and the ISO 8601 suggestion.
`hreflang`, reciprocal links, `x-default` and the language codes.
Wiring up React with `useTranslation` and `initReactI18next`.
Check the lesson's main ideas with three questions.
Your progress is stored only in this browser.
Last updated: November 3, 2026