当前位置: 首页 > Skill >

i18n (Internationalization) guideline skills for nextjs web development

i18n (Internationalization) guideline skills for nextjs web development

1.0.0 2026.11.21 浏览:970
获取Skill文件查看使用说明
作者:沈言许可证:
本文目录展开

i18n for Next.js — Implementation Guide

Core Principles

  • All user-facing features must implement i18n — no hardcoded strings in components.
  • Translations must be natural and idiomatic — never use scripts or machine translation; treat quality the same as English copywriting.
  • SEO metadata, JSON-LD structured data, and sitemaps must all be locale-aware.
  • Default locale (English) uses clean URLs with no prefix (/products); other locales use a prefix (/es/products).

Supported Locales

Locale list lives in src/lib/i18n/locales.ts. Keep the sitemap script's locales array in sync with this file.

export const locales = ['en', 'es', 'fr', 'de', 'ja', 'zh-CN', /* ... add as needed */]
export const defaultLocale = 'en'
export type Locale = typeof locales[number]

Directory Structure

src/app/[lang]/
├── dictionaries/       ← One JSON file per locale
│   ├── en.json
│   ├── es.json
│   └── ...
├── dictionaries.ts     ← getDictionary(locale) server helper
├── layout.tsx          ← Root layout: generateMetadata + hreflang + JSON-LD
└── <page>/
    └── page.tsx        ← generateMetadata + page content

Translation Files

See references/translation-files.md for:

  • JSON key hierarchy conventions (page.section.key)
  • Server-side getDictionary() usage
  • Client-side useDictionary() hook usage
  • Template variable pattern ({count} substitution)
  • Fallback pattern for missing keys

Routing & Middleware

See references/routing.md for:

  • src/middleware.ts — locale detection, redirect /en/* → /*, rewrite for default locale
  • LocalizedLink component — automatically prefixes non-default locales
  • useLocale() hook — reads locale from URL params → pathname → localStorage → default
  • getLocalizedPath() / removeLocalePrefix() utilities

SEO Metadata

See references/seo-metadata.md for:

  • generateMetadata() pattern in layout/page files
  • generateAlternatesMetadata() from src/lib/i18n/seo.ts
  • Full hreflang alternates.languages output (all locales + x-default)
  • OpenGraph locale / alternateLocale fields
  • html lang attribute and LangSetter client component

Structured JSON-LD Data

See references/structured-data.md for:

  • WebApplication schema with translated featureList, description
  • BlogPosting schema with inLanguage field
  • FAQ schema with translated acceptedAnswer
  • BreadcrumbList schema with localized URLs
  • Rendering via <Script> or <script> tags

Multi-language Sitemap

See references/sitemap.md for:

  • Sitemap structure: one <url> entry per page with <xhtml:link> alternates for every locale
  • <loc> uses the default-locale (clean) URL; x-default also points there
  • Full XML example with static and dynamic pages
  • Next.js App Router sitemap.ts implementation pattern
  • What to include vs. exclude (admin/API routes excluded)
  • Hreflang language code format rules

Quick Checklist — Adding a New Feature with i18n

  1. Add translation keys to all locale JSON files in src/app/[lang]/dictionaries/
    • Add English first, then translate to all other languages naturally
  2. Server components: const dict = await getDictionary(locale) → dict?.page?.section?.key || 'fallback'
  3. Client components: const dict = useDictionary() → same fallback pattern
  4. Add generateMetadata() to the page file, calling generateAlternatesMetadata()
  5. Add JSON-LD structured data script tag with translated fields and inLanguage
  6. Update sitemap if the page is new: add it to the sitemap source (see references/sitemap.md)
  7. Use <LocalizedLink> for internal links and getLocalizedPath() for programmatic navigation

Quick Checklist — Adding a New Locale

  1. Add locale code to locales array in src/lib/i18n/locales.ts
  2. Add locale entry to dictionaries/ as <code>.json (full translation of en.json)
  3. Add entry in src/app/[lang]/dictionaries.ts import map
  4. Add display name in LanguageSwitcher languageNames map
  5. Sync the sitemap locale list with the app's locales array
  6. Regenerate / redeploy the sitemap

相关文章

更多
计算机专业常用的PHP教学课本有哪些

直接选用 PHP & MySQL Web Development ( Luke Welling 著)或 Head First PHP & SQL ( Sharon Pritchette 著),前者适合有编程基础、想深入理解后端逻辑与数据库交互的开发者,后者通过图解和互动练习降低入门门槛。若需中文原版教材,可选用 PHP

2025.11.04 929
Oracle与PHP集成查询示例:OCIDefineByName用法解析

本文提供了一个Oracle与PHP集成的查询示例,重点讲解如何使用OCIDefineByName函数绑定输出变量。文章指出在定义字段映射时,必须使用大写字段名以符合Oracle规范,并展示了完整的连接、解析、执行及游标释放流程。

2026.01.06 666
Skill 文件
  • SKILL.md
    • i18n for Next.js — Implementation Guide
    • Core Principles
    • Supported Locales
    • Directory Structure
    • Translation Files
    • Routing & Middleware
    • SEO Metadata
    • Structured JSON-LD Data
    • Multi-language Sitemap
    • Quick Checklist — Adding a New Feature with i18n
    • Quick Checklist — Adding a New Locale
  • 项目或源文件

相关 Skill

更多
Web Development Web Development 使用 HTML、CSS、JavaScript 和现代框架构建、调试和部署网站,遵循生产最佳实践。
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...