Skip to content

xiaoyu2er/nextjs-i18n-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

440 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Next.js i18n Documentation

Multilingual mirror of the official Next.js documentation, built with Astro + Starlight and deployed on Cloudflare Workers.

๐ŸŒ Live site: nextjs.im

Features

  • ๐Ÿ“š Complete mirror of official Next.js docs (v13 / v14 / v15 / latest)
  • ๐ŸŒ 9 languages: English, ็ฎ€ไฝ“ไธญๆ–‡, ็น้ซ”ไธญๆ–‡, ๆ—ฅๆœฌ่ชž, ุงู„ุนุฑุจูŠุฉ, Deutsch, Espaรฑol, Franรงais, ะ ัƒััะบะธะน
  • ๐Ÿ”„ Incremental AST-based translation with MD5 caching (51% cross-version content dedup)
  • ๐Ÿ—๏ธ Microfrontend architecture โ€” 5 Cloudflare Workers via Service Bindings
  • ๐Ÿ” Full-text search powered by Orama
  • ๐Ÿ“ Blog and Learn sections synced from Next.js official site

Architecture

nextjs-i18n-docs/
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ web/           # Latest docs worker (Astro + Starlight)
โ”‚   โ”œโ”€โ”€ web-v/         # Versioned docs worker (v13/v14/v15)
โ”‚   โ”œโ”€โ”€ router/        # Router Worker (Service Bindings + redirects)
โ”‚   โ”œโ”€โ”€ index/         # Landing page
โ”‚   โ””โ”€โ”€ tampermonkey/  # Browser userscript
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ translate/     # Incremental translation pipeline
โ”‚   โ”œโ”€โ”€ crawler/       # Blog & Learn content syncer
โ”‚   โ”œโ”€โ”€ shared/        # Shared Astro components & plugins
โ”‚   โ”œโ”€โ”€ const/         # Shared constants
โ”‚   โ””โ”€โ”€ utils/         # Shared utilities
โ”œโ”€โ”€ content/           # Latest docs + blog + learn (all languages)
โ”œโ”€โ”€ content-v13/       # v13 docs (all languages)
โ”œโ”€โ”€ content-v14/       # v14 docs (all languages)
โ”œโ”€โ”€ content-v15/       # v15 docs (all languages)
โ”œโ”€โ”€ scripts/           # Build & sync scripts
โ””โ”€โ”€ .cache/            # Translation cache (JSONL, git-tracked)

Cloudflare Workers

Worker Purpose
nextjs-docs-router Routes requests by version prefix, handles redirects
nextjs-docs-latest Serves latest (v16) docs
nextjs-docs-v13 Serves v13 docs
nextjs-docs-v14 Serves v14 docs
nextjs-docs-v15 Serves v15 docs

Getting Started

Prerequisites

  • Bun
  • Node.js 20+

Installation

bun install

Development

# Run all workers with router (recommended)
bun run dev:all

# Run only latest docs
bun run dev:latest

# Run only versioned docs (set VERSION env)
VERSION=15 bun run dev:v

Building

# Build all packages
bun run build:packages

# Build latest docs
bun run build:latest

# Build versioned docs
VERSION=15 bun run build:v

Linting & Type Checking

# Lint (biome)
bun run lint

# Auto-fix lint issues
bun run lint:fix

# Format
bun run format

# Type check all non-Astro apps & packages
bun run typecheck

Deploying

# Deploy to Cloudflare Workers
bun run deploy:latest
VERSION=15 bun run deploy:v
bun run deploy:router

Translation Pipeline

The project includes an incremental translation pipeline (packages/translate) that:

  1. Normalizes MDX files (fixes JSX tag formatting for AST parsing)
  2. Parses files into AST nodes (paragraph, heading, code, list, etc.)
  3. Caches each node by MD5 hash in JSONL format โ€” identical content across versions is translated once
  4. Translates only changed nodes via LLM (OpenRouter / MiniMax / DeepSeek)
  5. Assembles translated nodes back into valid MDX
  6. Validates output (frontmatter, tag balance, remark parsability)

Running Translation

# Translate all files
bun run translate

# Or use the shell script with options
bash scripts/translate.sh \
  --pattern "**/*.mdx" \
  --concurrency 10 \
  --api-type openai \
  --api-base-url "https://openrouter.ai/api/v1" \
  --api-key "$OPENROUTER_API_KEY" \
  --model "openrouter/hunter-alpha"

Translation Cache

Cache files are stored in .cache/ (git-tracked, JSONL format):

  • .cache/en.jsonl โ€” English source node hashes (~17K entries)
  • .cache/zh-hans.jsonl โ€” Chinese translation cache (~6K entries)

Content Sync

English docs are synced from the official Next.js repo:

# Sync docs locally (resolves latest versions from git tags)
bash scripts/sync-docs-local.sh

# Full sync + translate
bash scripts/sync-and-translate.sh

Supported Languages

Language Code Content Files
English en 1,488
็ฎ€ไฝ“ไธญๆ–‡ zh-hans 1,117
็น้ซ”ไธญๆ–‡ zh-hant 1,117
ๆ—ฅๆœฌ่ชž ja 1,117
ุงู„ุนุฑุจูŠุฉ ar 1,117
Deutsch de 1,117
Espaรฑol es 1,117
Franรงais fr 1,117
ะ ัƒััะบะธะน ru 1,117

Deployment

The project uses a microfrontend architecture with 5 Cloudflare Workers connected via Service Bindings. Deployment is automated through Cloudflare Builds with Git integration.

How it works

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚  nextjs-docs-router  โ”‚
                    โ”‚  (Service Bindings)  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚  โ”‚  โ”‚  โ”‚
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ–ผ                 โ–ผ  โ–ผ                  โ–ผ
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ docs-latest  โ”‚ โ”‚ docs-v15โ”‚ โ”‚ docs-v14โ”‚ โ”‚ docs-v13โ”‚
    โ”‚ (Astro+SL)   โ”‚ โ”‚(Astro+SLโ”‚ โ”‚(Astro+SLโ”‚ โ”‚(Astro+SLโ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The Router Worker receives all requests and forwards them to the appropriate version worker based on URL path:

  • /docs/13/* โ†’ nextjs-docs-v13
  • /docs/14/* โ†’ nextjs-docs-v14
  • /docs/15/* โ†’ nextjs-docs-v15
  • Everything else โ†’ nextjs-docs-latest

Cloudflare Builds setup

Each worker has its own Cloudflare Build connected to this repo's main branch:

Cloudflare Builds automatically runs bun install (which triggers postinstall โ†’ build:packages), so build commands only need the app-specific step:

Build project Build command Deploy command Watch paths (docs)
nextjs-docs-latest bun run build:latest cd apps/web && npx wrangler deploy apps/web/*, packages/shared/*, packages/const/*, content/*, scripts/prepare-content.ts
nextjs-docs-v13 VERSION=13 bun run build:v cd apps/web-v && npx wrangler deploy --name nextjs-docs-v13 apps/web-v/*, packages/shared/*, packages/const/*, content-v13/*, scripts/prepare-content.ts
nextjs-docs-v14 VERSION=14 bun run build:v cd apps/web-v && npx wrangler deploy --name nextjs-docs-v14 apps/web-v/*, packages/shared/*, packages/const/*, content-v14/*, scripts/prepare-content.ts
nextjs-docs-v15 VERSION=15 bun run build:v cd apps/web-v && npx wrangler deploy --name nextjs-docs-v15 apps/web-v/*, packages/shared/*, packages/const/*, content-v15/*, scripts/prepare-content.ts
nextjs-docs-router cd apps/router && bun run generate-wrangler cd apps/router && npx wrangler deploy apps/router/*, .github/nextjs-versions.json

To set up from scratch:

  1. Connect the repo โ€” In the Cloudflare dashboard, go to Workers & Pages โ†’ Builds โ†’ Connect and link this GitHub repo (docs)
  2. Create 5 Build projects โ€” One for each worker, with the build commands above
  3. Configure branch & watch paths โ€” Set each project to deploy from main, and configure watch paths per the table above so only affected workers rebuild
  4. Set account_id โ€” Update account_id in each wrangler.toml to your Cloudflare account ID
  5. Generate router config โ€” Run bun run --filter @next-i18n/router generate-wrangler to regenerate apps/router/wrangler.toml with correct service bindings
  6. Custom domain (optional) โ€” Add a Custom Domain to the router worker

Manual deployment

You can also deploy manually using the Wrangler CLI:

# Deploy latest docs
bun run deploy:latest

# Deploy versioned docs
VERSION=13 bun run deploy:v
VERSION=14 bun run deploy:v
VERSION=15 bun run deploy:v

# Deploy router (regenerates wrangler.toml from nextjs-versions.json)
bun run deploy:router

Note: Deploy the version workers before the router, since the router's Service Bindings reference them.

Content pipeline

The build process for each Astro worker runs scripts/prepare-content.ts which:

  1. Strips numeric prefixes from directories (01-app โ†’ app)
  2. Resolves source references (Pages Router docs that share content with App Router)
  3. Maps locale directories to Starlight's i18n structure
  4. Strips MDX comments

CI/CD Workflows

Workflow Trigger Purpose
sync-docs.yml Manual / Schedule Syncs English docs from Next.js repo, creates PR
translate-docs.yml Manual Runs incremental translation pipeline on new/changed content
submit-sitemaps.yml Manual Submits sitemaps to Google Search Console

Push to main triggers automatic Cloudflare Builds for all workers.

License

ISC