🎯

next-intl-app-router

🎯Skill

from liuchiawei/agent-skills

VibeIndex|
What it does

Configures Next.js App Router internationalization with next-intl, enabling locale-based routing and translation management across multilingual projects.

πŸ“¦

Part of

liuchiawei/agent-skills(24 items)

next-intl-app-router

Installation

πŸ“‹ No install commands found in docs. Showing default command. Check GitHub for actual instructions.
Quick InstallInstall with npx
npx skills add liuchiawei/agent-skills --skill next-intl-app-router
6Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

Configures and uses next-intl for Next.js App Router with locale-based routing. Use when adding or changing i18n, locale routing, translations, next-intl plugin, middleware/proxy, or message files in Next.js App Router projects.

Overview

# next-intl (App Router)

Setup and usage of next-intl with prefix-based locale routing (e.g. /en/about, /ja/about). Use this skill in any Next.js App Router project.

Example code: Copy-paste examples live in this skill's [examples/](examples/) folder. See [examples/README.md](examples/README.md) for where each file goes in your project.

File layout

Keep this structure:

```

β”œβ”€β”€ messages/

β”‚ β”œβ”€β”€ en.json

β”‚ β”œβ”€β”€ ja.json

β”‚ └── ...

β”œβ”€β”€ next.config.ts

└── src/

β”œβ”€β”€ i18n/

β”‚ β”œβ”€β”€ request.ts

β”‚ β”œβ”€β”€ routing.ts

β”‚ └── navigation.ts

β”œβ”€β”€ proxy.ts # Next.js 16+ (was middleware.ts)

└── app/

β”œβ”€β”€ layout.tsx # Root layout, no NextIntlClientProvider here

└── [locale]/

β”œβ”€β”€ layout.tsx

β”œβ”€β”€ page.tsx

└── ...

```

Root layout does not wrap with NextIntlClientProvider; only app/[locale]/layout.tsx does.

---

1. Next config

Wire the plugin (default path ./i18n/request.ts):

```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);

```

Custom path: createNextIntlPlugin('./src/i18n/request.ts').

---

2. Routing config

Central config in src/i18n/routing.ts:

```ts

import { defineRouting } from "next-intl/routing";

export const routing = defineRouting({

locales: ["en", "ja", "zh-CN", "zh-TW"],

defaultLocale: "en",

});

```

---

3. Request config

src/i18n/request.ts: resolve locale from the [locale] segment and load messages.

```ts

import { getRequestConfig } from "next-intl/server";

import { hasLocale } from "next-intl";

import { routing } from "./routing";

export default getRequestConfig(async ({ requestLocale }) => {

const requested = await requestLocale;

const locale = hasLocale(routing.locales, requested)

? requested

: routing.defaultLocale;

return {

locale,

messages: (await import(../../messages/${locale}.json)).default,

};

});

```

---

4. Proxy / middleware (Next.js 16)

Next.js 16 uses proxy.ts instead of middleware.ts. Same API:

```ts

// src/proxy.ts

import createMiddleware from "next-intl/middleware";

import { routing } from "./i18n/routing";

export const proxy = createMiddleware(routing);

export const config = {

matcher: "/((?!api|trpc|_next|_vercel|.\\..).*)",

};

```

Matcher: all pathnames except /api, /trpc, /_next, /_vercel, and paths containing a dot (e.g. favicon.ico).

---

5. Navigation helpers

Use project navigation wrappers so links keep the current locale:

```ts

// src/i18n/navigation.ts

import { createNavigation } from "next-intl/navigation";

import { routing } from "./routing";

export const { Link, redirect, usePathname, useRouter, getPathname } =

createNavigation(routing);

```

In components: import Link (and others) from @/i18n/navigation, not from next/navigation or next/link, for locale-aware URLs. Example: [examples/Nav-client.tsx](examples/Nav-client.tsx), [examples/BackToHomeButton.tsx](examples/BackToHomeButton.tsx).

---

6. Locale layout and static rendering

app/[locale]/layout.tsx must (full file: [examples/app-locale-layout.tsx](examples/app-locale-layout.tsx)):

  1. Validate locale with hasLocale β†’ notFound() if invalid.
  2. Call setRequestLocale(locale) for static rendering.
  3. Wrap children with NextIntlClientProvider and getMessages().

```tsx

// app/[locale]/layout.tsx

import { NextIntlClientProvider, hasLocale } from "next-intl";

import { setRequestLocale } from "next-intl/server";

import { notFound } from "next/navigation";

import { routing } from "@/i18n/routing";

import { getMessages } from "next-intl/server";

type Props = {

children: React.ReactNode;

params: Promise<{ locale: string }>;

};

export function generateStaticParams() {

return routing.locales.map((locale) => ({ locale }));

}

export default async function LocaleLayout({ children, params }: Props) {

const { locale } = await params;

if (!hasLocale(routing.locales, locale)) notFound();

setRequestLocale(locale);

const messages = await getMessages();

return (

{children}

);

}

```

---

7. Pages under `[locale]`

For static rendering, every page under [locale] that uses next-intl must call setRequestLocale(locale) (and use use(params) if needed). Examples: [app-locale-page.tsx](examples/app-locale-page.tsx), [app-locale-about-page.tsx](examples/app-locale-about-page.tsx). (and use use(params) if needed). Layout already sets it; pages that render server components using locale should set it too.

```tsx

// app/[locale]/page.tsx

import { use } from "react";

import { setRequestLocale } from "next-intl/server";

export default function IndexPage({

params,

}: {

params: Promise<{ locale: string }>;

}) {

const { locale } = use(params);

setRequestLocale(locale);

return ;

}

```

```tsx

// app/[locale]/about/page.tsx

import { use } from "react";

import { setRequestLocale } from "next-intl/server";

import AboutContainer from "./components/AboutContainer";

export default function AboutPage({

params,

}: {

params: Promise<{ locale: string }>;

}) {

const { locale } = use(params);

setRequestLocale(locale);

return ;

}

```

Call setRequestLocale before any next-intl APIs in that layout/page.

---

8. Using translations

Client components: useTranslations(namespace):

```tsx

"use client";

import { useTranslations } from "next-intl";

import { Link } from "@/i18n/navigation";

export default function BackToHomeButton() {

const t = useTranslations("BackToHomeButton");

return (

{t("buttonText")}

);

}

```

```tsx

"use client";

import { useTranslations } from "next-intl";

import { Link } from "@/i18n/navigation";

export default function Nav() {

const t = useTranslations("Navigation");

return {t("links.about")};

}

```

Server components: use getTranslations from next-intl/server (await with locale/namespace as needed).

---

9. Messages format

One JSON file per locale under messages/. Nested keys map to namespaces and keys:

```json

{

"HomePage": {

"title": "Hello world!"

},

"LandingPage": {

"title": "Tokyo Sounds",

"navbar": {

"home": "Home",

"about": "About"

}

},

"BackToHomeButton": {

"buttonText": "Back to Home",

"tooltip": "Return to the main page"

}

}

```

  • useTranslations("LandingPage") β†’ t("title"), t("navbar.about").
  • Interpolation: "selectColor": "Select {color} color" β†’ t("selectColor", { color: "Blue" }).

---

Checklist

  • [ ] next.config.ts: createNextIntlPlugin() wraps config.
  • [ ] src/i18n/routing.ts: defineRouting with locales and defaultLocale.
  • [ ] src/i18n/request.ts: getRequestConfig + hasLocale + dynamic messages/${locale}.json.
  • [ ] src/proxy.ts (or middleware.ts): createMiddleware(routing) and matcher.
  • [ ] src/i18n/navigation.ts: createNavigation(routing) and re-export Link, etc.
  • [ ] app/[locale]/layout.tsx: hasLocale β†’ notFound, setRequestLocale, generateStaticParams, NextIntlClientProvider + getMessages().
  • [ ] Each app/[locale]/**/page.tsx: setRequestLocale(locale) when using static rendering.
  • [ ] Client components: useTranslations("Namespace"); links use Link from @/i18n/navigation.

---

Reference

  • Copy-paste examples: [examples/](examples/) β€” standalone files for use in any project.
  • Extended config (localePrefix, pathnames, etc.): [reference.md](reference.md)
  • Official: [next-intl App Router](https://next-intl.dev/docs/getting-started/app-router), [Routing setup](https://next-intl.dev/docs/routing/setup)

More from this repository10

🎯
error-diagnostics-smart-debug🎯Skill

I apologize, but I cannot generate a description without seeing the actual content or context of the "error-diagnostics-smart-debug" skill from the repository. Could you provide more details about ...

🎯
code-refactoring-tech-debt🎯Skill

Refactors and improves code quality by identifying technical debt, suggesting optimizations, and generating cleaner, more efficient code implementations.

🎯
clean-code🎯Skill

Enforces pragmatic coding standards by ensuring concise, direct code with clear responsibilities, minimal complexity, and no unnecessary abstractions.

🎯
frontend-patterns🎯Skill

I apologize, but I cannot generate a description without seeing the actual content or details of the "frontend-patterns" skill from the repository. Could you provide more context about what this sp...

🎯
page-cro🎯Skill

Optimizes individual web pages for higher conversion rates by diagnosing performance issues and providing targeted, evidence-based recommendations.

🎯
web-design-guidelines🎯Skill

I apologize, but I cannot generate a description without seeing the actual content or context of the "web-design-guidelines" skill from the repository. Could you provide me with more details about ...

🎯
tailwind-patterns🎯Skill

Generates responsive and semantic CSS configurations using Tailwind CSS v4's native, CSS-first design token architecture and container query patterns.

🎯
copywriting🎯Skill

Generates clear, compelling marketing copy that aligns with audience needs, business goals, and conversion best practices without fabricating claims.

🎯
backend-dev-guidelines🎯Skill

Enforces robust Node.js microservice architecture by defining strict backend development standards and best practices for building reliable, scalable systems.

🎯
code-review-checklist🎯Skill

Systematically reviews code for functionality, security, performance, and maintainability across multiple dimensions of software quality.