|
1 | | -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). |
| 1 | +# Next.js Markdoc Localization Example |
2 | 2 |
|
3 | | -## Getting Started |
| 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 | 4 |
|
5 | | -First, run the development server: |
| 5 | +> **Full walkthrough:** [lingo.dev/en/guides/markdoc-nextjs-localization](https://lingo.dev/en/guides/markdoc-nextjs-localization) |
6 | 6 |
|
7 | | -```bash |
8 | | -npm run dev |
9 | | -# or |
10 | | -yarn dev |
11 | | -# or |
12 | | -pnpm dev |
13 | | -# or |
14 | | -bun dev |
15 | | -``` |
| 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 | 16 |
|
17 | | -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 17 | +## Quick start |
18 | 18 |
|
19 | | -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. |
| 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 |
20 | 23 |
|
21 | | -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. |
| 24 | +## How it works |
22 | 25 |
|
23 | | -## Learn More |
| 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. |
24 | 27 |
|
25 | | -To learn more about Next.js, take a look at the following resources: |
| 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. |
26 | 29 |
|
27 | | -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. |
28 | | -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. |
| 30 | +## Locales |
29 | 31 |
|
30 | | -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! |
| 32 | +- **Source:** `en` |
| 33 | +- **Targets:** `es`, `fr`, `de` |
31 | 34 |
|
32 | | -## Deploy on Vercel |
| 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 | +``` |
33 | 49 |
|
34 | | -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. |
| 50 | +## Links |
35 | 51 |
|
36 | | -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
| 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