Agent-skills-standard nextjs-i18n
Best practices for multi-language handling, locale routing, and detection strategies across App and Pages Router. Use when adding i18n, locale routing, or language detection in Next.js. (triggers: middleware.ts, app/[lang]/**, pages/[locale]/**, messages/*.json, next.config.js, i18n, locale, translation, next-intl, react-intl, next-translate)
install
source · Clone the upstream repo
git clone https://github.com/HoangNguyen0403/agent-skills-standard
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/HoangNguyen0403/agent-skills-standard "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/nextjs/nextjs-i18n" ~/.claude/skills/hoangnguyen0403-agent-skills-standard-nextjs-i18n && rm -rf "$T"
manifest:
skills/nextjs/nextjs-i18n/SKILL.mdsource content
Internationalization (i18n)
Priority: P2 (MEDIUM)
Maintain single source of truth for locales and ensure SEO-friendly sub-path routing.
Workflow: Add i18n to Next.js App Router Project
- Install
and createnext-intl
,messages/en.json
, etc.messages/fr.json - Add locale detection middleware in
middleware.ts - Create
with locale paramapp/[lang]/layout.tsx - Load translations server-side via
getMessages() - Add
tags inhreflanggenerateMetadata - Pre-render locales with
generateStaticParams - Verify: run
and confirm all locale paths rendernext build
Middleware Example
Implementation Guidelines
- Locale Routing: Follow URL-first approach for SEO. Use dynamic segments in App Router (
) andapp/[lang]/page.tsx
configuration ini18n
for Pages Router.next.config.js - Library Selection: Use
for App Router (modern) ornext-intl
/react-intl
for legacy apps.next-translate - Detection: Implement middleware localization in
to detect user language frommiddleware.ts
headers or cookies and perform redirects.Accept-Language - Server-Side: Load translation
dictionaries in Server Components to keep client bundle small.messages/*.json - SEO: Ensure
tags generated correctly inhreflang
API for all translated routes.metadata - Static Generation: Use
to pre-render localized versions of static pages at build time.generateStaticParams
Library Specifics
For detailed setup with common libraries, refer to:
Anti-Patterns
- No hardcoded strings in JSX: Use translation keys; never commit raw text.
- No client-side translation bundles: Load dictionaries server-side with
.getMessages() - No mixed URL locale patterns: Use sub-paths or domains consistently.