The Future of Web Dev
The Future of Web Dev
next-fast-i18n: Next.js i18n Library & next-intl Alternative
A Next.js i18n library and next-intl alternative with compatible ICU JSON messages, localized routing, and no Next.js configuration plugin.

next-fast-i18n is a Next.js internationalization (i18n) library that adds translations, locale-aware routing, and regional formatting to multilingual websites and apps.
It has zero runtime dependencies and lets you retain existing URLs for your default language and send selected translation namespaces to Client Components.
Features
- ICU MessageFormat syntax for interpolation, plurals with exact matches and offsets, select expressions, ordinals, and nested rich text.
- TypeScript autocomplete for translation keys and namespaces inferred from JSON dictionaries.
- Static generation of locale-specific pages through the App Router.
- Cached message dictionaries, translators, and internationalization formatters.
- Locale-aware links, router methods, and pathname helpers.
- Deterministic UTC date and integer formatting for English, German, French, and Italian.
- Optional Lite engine for projects with basic translation requirements.
Bundle Size
| Bundle | Gzip size |
|---|---|
| next-intl (default) | 16.90 KB |
| next-intl (precompiled) | 7.92 KB |
| next-fast-i18n | 7.10 KB |
| next-fast-i18n Lite | 4.05 KB |
How To Use It
1. Install the Library
In a Next.js App Router project, run:
npm install next-fast-i18nThe example uses Next.js 16 (Node.js 20.9 or later), English as the default language, and German as a second language.
It assumes your TypeScript @/* alias points to the project root. For a src/ project, place these files under src/ and point the alias there.
app/
[locale]/
layout.tsx
page.tsx
components/
cart-counter.tsx
language-switcher.tsx
lib/
config.ts
i18n.ts
navigation.ts
messages/
en.json
de.json
proxy.tsMove your existing root layout and localized pages into app/[locale]/. The locale layout owns the html and body elements.
2. Create Your Translation Dictionaries
messages/en.json:
{
"nav": {
"language": "Language"
},
"shop": {
"title": "Office accessories",
"description": "Equip your workspace for everyday tasks."
},
"cart": {
"count": "{count, plural, =0 {Your cart is empty} one {# item in your cart} other {# items in your cart}}",
"add": "Add to cart"
}
}messages/de.json:
{
"nav": {
"language": "Sprache"
},
"shop": {
"title": "Bürozubehör",
"description": "Statten Sie Ihren Arbeitsplatz für den Alltag aus."
},
"cart": {
"count": "{count, plural, =0 {Ihr Warenkorb ist leer} one {# Artikel im Warenkorb} other {# Artikel im Warenkorb}}",
"add": "In den Warenkorb"
}
}Create lib/config.ts. Use the English dictionary as the TypeScript schema for translation keys.
import type enMessages from "../messages/en.json";
export const LOCALES = ["en", "de"] as const;
export const DEFAULT_LOCALE = "en";
export type Locale = (typeof LOCALES)[number];
export type Messages = typeof enMessages;Create lib/i18n.ts to load the dictionaries on the server:
import { createServerI18n } from "next-fast-i18n/server";
import { DEFAULT_LOCALE, LOCALES, type Messages } from "./config";
export const {
getT,
getTranslations,
getLocale,
getMessages,
getClientMessages,
getFormatter,
normalizeLocale,
setRequestLocale,
} = createServerI18n<Messages, typeof LOCALES>({
locales: LOCALES,
defaultLocale: DEFAULT_LOCALE,
loadMessages: (locale) => import(`../messages/${locale}.json`),
});3. Configure Locale Routing
Create proxy.ts (use middleware.ts in Next.js 15) beside the app/ directory.
import { createLocaleProxy } from "next-fast-i18n/proxy";
import { DEFAULT_LOCALE, LOCALES } from "./lib/config";
export const config = {
// Skip API routes, Next.js assets, and public files.
matcher: ["/((?!api|_next|_vercel|.*\\..*).*)"],
};
export default createLocaleProxy({
defaultLocale: DEFAULT_LOCALE,
locales: LOCALES,
});With this configuration, use unprefixed paths for English:
| Requested URL | Result |
|---|---|
/ | Internally rewrites to /en |
/de | Serves the German page |
/en | 308 redirect to / |
/en/pricing?tier=pro | 308 redirect to /pricing?tier=pro |
/de/pricing | Serves the German pricing route if it exists |
The proxy sets the x-locale request header from the URL and overwrites incoming values. The locale derives from the URL, independent of browser language or locale cookies. Adjust the matcher if your app has dynamic routes containing dots.
4. Create the Locale Layout
Create app/[locale]/layout.tsx:
import type { ReactNode } from "react";
import { notFound } from "next/navigation";
import { hasLocale } from "next-fast-i18n";
import { I18nProvider } from "next-fast-i18n/client";
import { DEFAULT_LOCALE, LOCALES } from "@/lib/config";
import { getClientMessages, setRequestLocale } from "@/lib/i18n";
import { LanguageSwitcher } from "@/components/language-switcher";
export function generateStaticParams() {
return LOCALES.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params,
}: {
children: ReactNode;
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
if (!hasLocale(LOCALES, locale)) notFound();
setRequestLocale(locale);
const messages = await getClientMessages(locale, ["nav"]);
return (
<html lang={locale}>
<body>
<I18nProvider
locale={locale}
defaultLocale={DEFAULT_LOCALE}
locales={LOCALES}
messages={messages}
>
<LanguageSwitcher />
{children}
</I18nProvider>
</body>
</html>
);
}Call setRequestLocale(locale) before request-based translation lookups in statically rendered pages and layouts. Pass the locale explicitly to translation calls when you already have the route parameter.
5. Add Typed Client Hooks and a Language Switcher
Create lib/navigation.ts:
"use client";
import {
createNavigation,
createTypedTranslations,
} from "next-fast-i18n/client";
import { DEFAULT_LOCALE, LOCALES, type Messages } from "./config";
export const useTranslations = createTypedTranslations<Messages>();
export const {
Link, useRouter, usePathname, getPathname,
localizeHref, stripLocalePrefix,
} = createNavigation({
defaultLocale: DEFAULT_LOCALE,
locales: LOCALES,
});Create components/language-switcher.tsx:
"use client";
import { useLocale } from "next-fast-i18n/client";
import { Link, usePathname, useTranslations } from "@/lib/navigation";
export function LanguageSwitcher() {
const locale = useLocale();
const pathname = usePathname();
const t = useTranslations("nav");
return (
<nav aria-label={t("language")}>
<Link href={pathname} locale="en"
aria-current={locale === "en" ? "page" : undefined}>
English
</Link>{" "}
<Link href={pathname} locale="de"
aria-current={locale === "de" ? "page" : undefined}>
Deutsch
</Link>
</nav>
);
}The switcher uses the unprefixed pathname to construct links to the corresponding language versions. For example, /de/pricing becomes /pricing when a visitor selects English.
6. Basic Usage: Translate a Server Component
Create app/[locale]/page.tsx:
import { getT, setRequestLocale } from "@/lib/i18n";
export default async function StorePage({
params,
}: {
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setRequestLocale(locale);
const t = await getT({ locale, namespace: "shop" });
return (
<main>
<h1>{t("title")}</h1>
<p>{t("description")}</p>
</main>
);
}7. Add ICU Plurals to an Interactive Cart
Create components/cart-counter.tsx:
"use client";
import { useState } from "react";
import { useTranslations } from "@/lib/navigation";
export function CartCounter() {
const [count, setCount] = useState(0);
const t = useTranslations("cart");
return (
<section>
<p>{t("count", { count })}</p>
<button type="button" onClick={() => setCount((n) => n + 1)}>
{t("add")}
</button>
</section>
);
}Extend the server page from Step 6. Add the following imports at the top of app/[locale]/page.tsx:
import { I18nMessages } from "next-fast-i18n/client";
import { getClientMessages } from "@/lib/i18n";
import { CartCounter } from "@/components/cart-counter";After the getT() call, select the cart namespace:
const cartMessages = await getClientMessages(locale, ["cart"]);Insert the following JSX below the description paragraph, inside <main>:
<I18nMessages messages={cartMessages}>
<CartCounter />
</I18nMessages>The root provider receives nav, the nested provider adds cart, and the shop messages stay on the server. The counter displays “Your cart is empty,” “1 item in your cart,” or the appropriate plural message as its state changes.
8. Run the Application
npm run dev -- --hostname localhostOpen http://localhost:3000 and http://localhost:3000/de to view both locales. Visit http://localhost:3000/en to check the permanent redirect to the English root. Run npm run build before deployment to check that both locale pages can be generated.
9. Set Localized Page Metadata
For a public site, export generateMetadata() from app/[locale]/page.tsx. Replace the example origin with your site’s production origin.
import type { Metadata } from "next";
export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
const t = await getT({ locale, namespace: "shop" });
return {
metadataBase: new URL("https://shop.example.com"),
title: t("title"),
description: t("description"),
alternates: {
canonical: locale === "de" ? "/de" : "/",
languages: { en: "/", de: "/de", "x-default": "/" },
},
};
}Server Configuration and API
createServerI18n() Options
| Option | Description |
|---|---|
locales | Required supported locale codes. |
defaultLocale | Required fallback locale. Match the default locale in the proxy. |
loadMessages | Required function that returns a dictionary, a promise, or an imported JSON module. |
localeHeader | Request header used to resolve the locale. Defaults to x-locale. Match the proxy setting. |
formats | Named date/time, number, and list format presets. |
timeZone | Optional time zone for date formatting. |
Server Helpers
| Method | Purpose |
|---|---|
getT(namespace?) | Resolves a translator for the current request locale. Alias: getTranslations(). |
getT({ locale, namespace }) | Resolves a translator for a specified locale and namespace. Omit the namespace for the entire dictionary. |
getLocale() | Retrieves the resolved request locale. |
getMessages(locale?) | Loads the full dictionary for a given or current locale. |
getClientMessages(locale, namespaces) | Returns only the specified namespaces or message paths. |
getFormatter({ locale?, now?, timeZone? }) | Creates a locale-aware formatter. All options are optional. |
setRequestLocale(locale) | Stores the locale in the current React request cache. |
normalizeLocale(value) | Returns a valid configured locale or the default locale. |
Translator Methods
| Method | Purpose |
|---|---|
t(key, values?) | Resolves a translation with optional interpolation and ICU formatting. |
t.rich(key, values?) | Renders rich-text messages using callbacks for tags. |
t.markup(key, values?) | Processes tags with markup callbacks. Returns a string or an array of text and callback results. |
t.raw(key) | Retrieves the original message value. |
t.has(key) | Checks if a translation key exists. |
Standalone Translation
Use the core package to translate messages in utilities that do not need React or Next.js. For example, in a TypeScript file under lib/:
import { createTranslator } from "next-fast-i18n";
import deMessages from "../messages/de.json";
const t = createTranslator({
locale: "de",
messages: deMessages,
namespace: "cart",
});
t("count", { count: 3 }); // 3 Artikel im WarenkorbThe core also exports pickMessages(messages, paths) and mergeMessages(base, extra) for selecting and deep-merging dictionaries.
Client Provider and Navigation API
I18nProvider Props
| Prop | Description |
|---|---|
locale | Required active locale. |
messages | Required dictionary accessible to descendant client components. |
children | Required React children. |
locales | Supported locales. Defaults to an array containing the active locale. |
defaultLocale | Defaults to the first supported locale. |
formats | Optional named formatting presets. |
timeZone | Optional date formatting time zone. |
trailingSlash | Defaults to false. Keep aligned with the proxy and Next.js settings. |
I18nMessages takes messages and children. It deep-merges its message dictionary with the parent provider for its descendants.
| API | Purpose |
|---|---|
useTranslations(namespace?) | Reads a translator for the active locale. |
createTypedTranslations<Messages>() | Returns a hook with typed namespaces and keys. |
useLocale() | Returns the active locale code. |
useFormatter() | Returns date, time, number, list, and relative-time formatters. |
Link | Wraps Next.js Link with a string href and optional locale prop. |
usePathname() | Returns the pathname with its locale prefix removed. |
useRouter() | Adds locale-aware push, replace, and prefetch methods to navigation. |
getPathname({ href, locale }) | Replaces an existing locale prefix and generates a localized URL. |
localizeHref(href, locale) | Adds the requested locale prefix for an unprefixed path. |
stripLocalePrefix(pathname) | Removes a configured locale prefix. |
For a project with a pricing route, import useRouter from @/lib/navigation in a Client Component. Call its navigation method from an event handler:
const router = useRouter();
const openGermanPricing = () => router.push("/pricing", { locale: "de" });Attach openGermanPricing to a button’s onClick. The router also accepts a scroll option in push() and replace().
Locale Proxy Options
| Option | Description |
|---|---|
locales | Required supported locale codes. |
defaultLocale | Required default locale. |
localeHeader | Defaults to x-locale. |
trailingSlash | Defaults to false. |
origin | Optional canonical origin string or function returning the origin from a NextRequest. Useful behind a reverse proxy. |
For integration with existing authentication or redirect logic, call createLocaleProxy(options).resolve(pathname, search) to inspect the routing decision. It returns a redirect action with a location and 308 status, a rewrite action with a pathname and locale, or a next action with a locale. Call the handler with the NextRequest when your custom checks are complete.
Formatting Dates, Numbers, and Rich Text
Import getFormatter() from @/lib/i18n for Server Components or useFormatter() from next-fast-i18n/client for Client Components. The full formatter accepts native Intl options and named presets for dates, numbers, and lists. Use matching formats and timeZone settings in the server factory and client provider when both render formatted values.
const fmt = await getFormatter({ locale: "de" });
const price = fmt.number(49.95, {
style: "currency",
currency: "EUR",
});
const published = fmt.dateTime(
new Date("2026-01-05T12:00:00Z"),
{ dateStyle: "long" },
);The formatter also exposes dateTimeRange(start, end, options?), list(items, options?), and relativeTime(date, options?). Pass a fixed now to getFormatter() or the relative-time call when rendering time-sensitive messages against a specific reference time.
For UTC dates and integer grouping, the core exports deterministic CLDR helpers:
import { formatDateMedium, formatDateLong, formatInteger } from "next-fast-i18n";
formatDateMedium(new Date("2026-01-05T12:00:00Z"), "de"); // 05.01.2026
formatDateLong(new Date("2026-01-05T12:00:00Z"), "de"); // 5. Januar 2026
formatInteger(1234567, "de"); // 1.234.567The built-in CLDR tables cover en, de, fr, and it. Other locales fall back to Intl. The full formatter also uses Intl for custom formatting options, such as a different time zone or currency format.
For rich text, add these properties to the shop namespace in your English and German dictionaries, respectively:
"shipping": "Orders of <strong>{amount}</strong> or more qualify for free shipping.""shipping": "Ab <strong>{amount}</strong> ist der Versand kostenlos."In your server page, import getFormatter from @/lib/i18n and call const fmt = await getFormatter({ locale }); before the return statement. Render the message with a tag callback:
<p>
{t.rich("shipping", {
amount: fmt.number(75, { style: "currency", currency: "EUR" }),
strong: (chunks) => <strong>{chunks}</strong>,
})}
</p>Full ICU vs. Lite
Use the default engine for multilingual applications that need locale-specific plural categories, ICU select and selectordinal, inline number/date/time formatting, or nested rich text.
For basic interpolation, Western-style plurals, flat rich text, and simple date and number formatting, use the Lite entry points:
import { createServerI18n } from "next-fast-i18n/lite/server";
import { createTypedTranslations } from "next-fast-i18n/lite/client";Change the full server and client imports throughout your app to the corresponding Lite entry points. Keep the proxy import unchanged. Use next-fast-i18n/lite for standalone translation utilities.
The Lite formatter supports basic number(value) and dateTime(date, { dateStyle: "medium" | "long" }) calls. Retain the full formatter for currency, date ranges, lists, or relative time.
Migrating From next-intl
- Remove the next-intl plugin from
next.config.tsand replace your routing middleware withcreateLocaleProxy(). - Replace
i18n/request.tswith the server factory from Step 2. Keep compatible ICU JSON dictionaries. - Replace
NextIntlClientProviderwithI18nProviderand select the messages needed by client components. - Replace navigation imports from
next-intl/navigationwith the helpers from Step 5. - Audit translated pathnames, locale-detection behavior, date formatting, and any extraction workflows before removing the old library.
Keep next-intl if your project relies on its built-in translated pathnames (such as /about and /ueber-uns), live useNow() hook, or translation extraction workflow. These features require application-level implementations or separate tooling after migration.

