The Complete Production SOP: How to Deploy and Run Next-Intl & Multi-Language Localization in Autonomous AI Agents
Step-by-step SOP to install and run Next-Intl & Multi-Language Localization in Codex, Claude Code, and Cursor. Includes verified prompts, sandbox rules, and troubleshooting.
Technical Overview & Architectural Context
Autonomous coding agents like Codex, Claude Code, Cursor, and Windsurf frequently hallucinate or generate brittle patterns when implementing Next.js internationalization. Without deterministic guidance, LLMs commonly create mismatched routing structures (e.g., mixing Next.js App Router dynamic segments `[locale]` with obsolete Pages Router `next.config.js` i18n configurations), fail to configure global TypeScript declarations for message key autocompletion, or introduce race conditions inside Server Component translation contexts. These errors cascade into broken static generation, hydration mismatches, and fragmented localization states. The `i18n-localization` skill establishes an ironclad procedural boundary for AI agents. It instructs agents to enforce Next-Intl App Router architecture, automate type-safe message declaration via `declare module 'next-intl'`, configure dynamic request configuration (`getRequestConfig`), and implement strict locale routing middleware. By supplying deterministic verification recipes, this skill prevents context degradation, eliminates hallucinated routing schemes, and guarantees that every localized route satisfies production-grade type checking and SSR pluralization rules.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules.
Agent runtimes monitor localized execution boundaries via workspace-level or user-level rules. For Cursor and Windsurf, rules are placed in `.cursor/rules` or workspace root; for Claude Code and Codex CLI, the manifest resides in the `.agents/skills` registry. Mounting `i18n-localization` gives the agent deterministic operational parameters for handling translation namespaces, routing middlewares, and type generation without manual human intervention.
mkdir -p .agents/skills/i18n-localization && curl -fsSL https://askills.dev/api/skills/i18n-localization/raw -o .agents/skills/i18n-localization/SKILL.md---
name: "i18n-localization"
description: "Configure type-safe internationalization (i18n), localized routing, and pluralization rules with next-intl."
category: "fullstack"
targetRuntimes: ["codex", "claude-code", "cursor", "windsurf"]
---
# Next-Intl & Multi-Language Localization Rules
1. App Router Only: Always place localized routes inside `app/[locale]/`.
2. Strict Typing: Create `global.d.ts` extending `IntlMessages` to enable autocompletion for translation keys.
3. Dynamic Loading: Implement `src/i18n/request.ts` using `getRequestConfig` to validate `routing.locales`.
4. Middleware: Standardize routing with `createMiddleware(routing)` matching pattern `['/', '/(de|en|es|fr)/:path*']`.
5. Formatting: Always utilize `useTranslations`, `useFormatter`, or `getTranslations` (Server Components).Specify supported locales in a lightweight `src/i18n/routing.ts` manifest. Feeding a tiny single-source routing file saves over 1,500 LLM context tokens otherwise wasted explaining locale lists across disparate prompts.
Ensure directory permissions allow writing to `.agents/` and `src/i18n/`. Sandboxed runtimes in Claude Code or Codex Desktop will halt with EACCES if write scopes are restricted to `src/app` only.
Dependency Installation & Global Type Ingestion
Install next-intl and configure zero-runtime TypeScript definitions for auto-completing translation keys.
The skill enforces `next-intl` installation and explicitly instructs the agent to register a global declaration file. This enables IDE-level autocompletion and prevents the agent from writing unverified string keys that trigger runtime missing-translation warnings.
pnpm add next-intlimport en from './messages/en.json';
type Messages = typeof en;
declare global {
// Enforces type-safe messages via next-intl globally
interface IntlMessages extends Messages {}
}Never store translations directly inside TypeScript objects. Using nested JSON files (`messages/en.json`) allows the agent to validate JSON schemas deterministically without compiling code.
Verify that `tsconfig.json` includes `global.d.ts`. If `include` excludes the root directory, TypeScript compiler (`tsc`) will fail to bind `IntlMessages`.
Intent Matching & Trigger Invocation
Invoke the agent using targeted prompts that trigger the i18n architectural workflow.
Provide direct natural language instructions that activate the skill's procedural boundaries. The agent detects keywords like 'next-intl', 'localized routing', and 'translation namespaces', adhering directly to the SOP steps defined in SKILL.md.
claude-code "Apply i18n-localization skill: configure routing.ts, request.ts, and localized middleware for locales en, es, and fr"import { defineRouting } from 'next-intl/routing';
import { createNavigation } from 'next-intl/navigation';
export const routing = defineRouting({
locales: ['en', 'es', 'fr'],
defaultLocale: 'en',
localePrefix: 'as-needed'
});
export const { Link, redirect, usePathname, useRouter } = createNavigation(routing);Use action verbs matching the frontmatter definition: 'configure type-safe internationalization', 'implement localized routing', and 'set pluralization rules'.
Do not mix older `next-intl/middleware` default imports with Next.js 15 proxy configurations. Always rely on `defineRouting` and `createMiddleware` from `next-intl/middleware`.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks before accepting agent deliverables.
The agent must run type checks and automated tests verifying that all translation namespaces parse correctly, navigation links compile, and middleware matches incoming locale paths without infinite redirect loops.
pnpm tsc --noEmit && pnpm next lintimport createMiddleware from 'next-intl/middleware';
import { routing } from './i18n/routing';
export default createMiddleware(routing);
export const config = {
// Match only internationalized pathnames, skipping api, _next, and static assets
matcher: ['/', '/(es|en|fr)/:path*', '/((?!_next|_vercel|.*\\..*).*)']
};Inspect `git diff src/middleware.ts` before committing to ensure the agent did not erase pre-existing authentication or telemetry middleware matchers.
Omitting static file exclusions in the middleware matcher will cause the agent's tests to fail due to localized routing intercepting `favicon.ico` or public static assets.
Real-World Scenario: Migrate Monolingual App Router Dashboard to Type-Safe Bilingual (en/de) Architecture
“Using the i18n-localization skill, convert our monolingual Next.js App Router project to support English ('en') and German ('de'). Move existing pages into app/[locale], configure next-intl request setup, export type-safe Link/useRouter utilities, and extract dashboard strings into messages/en.json and messages/de.json.”
Runtime Troubleshooting & Failure Modes
Root Cause: Next.js App Router cannot locate the dynamic message loader because next-intl plugin was not wrapped around nextConfig in `next.config.mjs` or `next.config.js`.
// next.config.mjs
import createNextIntlPlugin from 'next-intl/plugin';
const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default withNextIntl(nextConfig);Root Cause: TypeScript fails to resolve the translation key because `global.d.ts` is missing, misconfigured, or the targeted message key does not exist in the referenced base locale JSON.
// Ensure messages/en.json contains the namespace:
// {"common": {"title": "Welcome"}}
// And verify global.d.ts imports the file properly:
import en from './messages/en.json';
type Messages = typeof en;
declare global { interface IntlMessages extends Messages {} }Frequently Asked Questions (Next-Intl & Multi-Language Localization SOP)
Q:Can I use Next-Intl & Multi-Language Localization across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification supported across all modern agent runtimes. By placing the file in `.agents/skills/i18n-localization/SKILL.md` or referencing it in runtime rule configurations, any agent inherits the same deterministic SOP.
Q:How does Next-Intl & Multi-Language Localization prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. Agents rely on structured routing definitions (`routing.ts`) and global type files (`global.d.ts`), avoiding the need to re-read hundreds of lines of translation dictionaries on every turn.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes. It requires standard workspace file read/write permissions and standard package manager access (`pnpm add next-intl`) without root privileges.
Ready to equip your autonomous agent with Next-Intl & Multi-Language Localization?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.