|
| 1 | +# Next.js Markdoc Localization Example |
| 2 | + |
| 3 | +Demonstrates automated localization for a Next.js App Router site that authors long-form content in [Markdoc](https://markdoc.dev) and UI strings in JSON, using [Lingo.dev](https://lingo.dev) CLI and GitHub Actions. |
| 4 | + |
| 5 | +> **Full walkthrough:** [lingo.dev/en/guides/markdoc-nextjs-localization](https://lingo.dev/en/guides/markdoc-nextjs-localization) |
| 6 | +
|
| 7 | +## What's inside |
| 8 | + |
| 9 | +- `src/app/[lang]/` – Next.js App Router, locale-scoped routes |
| 10 | +- `src/content/en/pages/*.md`, `src/content/en/blog/*.md` – source Markdoc content (English) |
| 11 | +- `src/content/en/ui.json` – source UI-string catalog |
| 12 | +- `src/markdoc.schema.ts` – custom Markdoc tag schema wired to React components |
| 13 | +- `src/proxy.ts` – middleware that redirects bare paths to the visitor's best-matching locale |
| 14 | +- `i18n.json` – Lingo.dev CLI configuration (two buckets: `markdoc`, `json`) |
| 15 | +- `.github/workflows/translate.yml` – GitHub Actions workflow |
| 16 | + |
| 17 | +## Quick start |
| 18 | + |
| 19 | +1. Fork this repo |
| 20 | +2. Add `LINGODOTDEV_API_KEY` to **Settings > Secrets and variables > Actions** |
| 21 | +3. Push a change to any file under `src/content/en/` |
| 22 | +4. Translations appear automatically via commit to main |
| 23 | + |
| 24 | +## How it works |
| 25 | + |
| 26 | +The Lingo.dev CLI reads the source Markdoc files and `ui.json`, identifies new or changed entries using a lockfile, translates the delta through a configured localization engine, and writes per-locale files into `src/content/[locale]/`. Frontmatter, Markdoc custom tags, and JSON shape are preserved – only translatable text changes. The GitHub Actions workflow runs this on every push to main. |
| 27 | + |
| 28 | +Next.js routes under `src/app/[lang]/` load the matching locale's files at request time. A middleware inspects the `Accept-Language` header and redirects bare paths like `/` or `/blog/hello-markdoc` to the best-matching locale. |
| 29 | + |
| 30 | +## Locales |
| 31 | + |
| 32 | +- **Source:** `en` |
| 33 | +- **Targets:** `es`, `fr`, `de` |
| 34 | + |
| 35 | +## Running locally |
| 36 | + |
| 37 | +```bash |
| 38 | +pnpm install |
| 39 | +pnpm dev |
| 40 | +``` |
| 41 | + |
| 42 | +Open `http://localhost:3000` – you'll be redirected to `/en`, `/es`, `/fr`, or `/de` based on your browser's `Accept-Language`. |
| 43 | + |
| 44 | +To translate locally: |
| 45 | + |
| 46 | +```bash |
| 47 | +pnpm lingo |
| 48 | +``` |
| 49 | + |
| 50 | +## Links |
| 51 | + |
| 52 | +- [Guide: Next.js App Router Localization with Markdoc](https://lingo.dev/en/guides/markdoc-nextjs-localization) |
| 53 | +- [Lingo.dev CLI docs](https://lingo.dev/en/docs/cli) |
| 54 | +- [GitHub Actions integration](https://lingo.dev/en/docs/integrations/github) |
| 55 | +- [Create a free account](https://lingo.dev) |
0 commit comments