# Adding English to a personal site without changing a single Chinese URL: two root layouts in Next.js 16

> Chinese stays the default and no existing URL may change, but English visitors should find the site too. The official i18n example prefixes every language, so I used two root layouts instead.

- Date: 2026-12-01
- Topics: Next.js, Data
- Chinese original: https://kbs0830.com/blog/bilingual-two-root-layouts

This site has always been in Chinese (Traditional, the way it is written in Taiwan). Recently I wanted English speakers to be able to find it too: developers mostly read English, and more and more people just ask an AI. There were only two conditions: **Chinese stays the default**, and **no existing Chinese URL may change**.

## Why the official example does not fit

The i18n guide in the Next.js 16 docs puts every page under `app/[lang]/`, uses a proxy to redirect based on `Accept-Language`, and combines that with `next/root-params` (new in 16.3) so any Server Component can read the language directly.

The catch is that the example gives **every language a prefix** (`/en-US/…`, `/nl/…`). To keep Chinese without a prefix, the proxy would have to quietly rewrite `/about` to `/zh-Hant/about`. I weighed the cost:

- **typedRoutes gets weaker**: route types become `` `/${string}/resume` ``, and every existing two-segment URL like `/projects/xxx` would need an `as Route`
- **Every request runs through the proxy**: today only the site owner's admin pages do
- Rewrites combined with Partial Prefetching and Speculation Rules: I could not find anyone who had verified that combination

## Two root layouts instead

What I ended up with:

```text
src/app/
  (zh)/layout.tsx      ← <html lang="zh-Hant">, all existing pages moved in here
  (zh)/page.tsx, resume/, blog/, tools/…   ← parentheses do not appear in URLs, so no URL changed
  en/layout.tsx        ← <html lang="en">
  en/page.tsx, en/resume/, en/projects/[slug]/
  api/, sitemap.ts, llms.txt/…             ← route handlers need no layout, left in place
  global-not-found.tsx ← URLs that match no route
```

Both root layouts share one `SiteDocument` component (theme script, fonts, Speculation Rules, site-wide widgets); the only difference is `lang`.

The cost is that **moving across root layouts is a full page load**: switching language, or following a link from an English page to a page that only exists in Chinese, reloads the whole page. But pages already use Speculation Rules, and Chrome preloads a link in the background when you hover it, so in practice it is barely noticeable. Within one language, navigation is client-side as usual, and the View Transition from a project card to its page still works.

Why does `<html lang>` have to be right? Google says it ignores the lang attribute, but Bing uses it, and ChatGPT search, Copilot and DuckDuckGo use Bing's index. If JavaScript changes it after load, the raw HTML a crawler sees still says Chinese.

## No automatic redirect by browser language

Many sites send people to a matching language based on `Accept-Language`. I deliberately do not: Googlebot crawls from US IPs and **sends no `Accept-Language`**, so an automatic redirect would stop it from ever seeing the Chinese pages, and the Cloudflare cache would also have to be split by language.

Instead, hreflang lets search engines send English searchers to the English page, and the language switch lives only in the top-right menu and the footer. The header is untouched.

## hreflang grows out of canonical

Every page already has to write a canonical URL, and share cards all go through one `withShare()` helper. So I let it do one more thing: if the canonical starts with `/en`, it is an English page, and if that page has a counterpart in the other language, the alternates are added automatically:

```html
<link rel="alternate" hreflang="zh-Hant" href="https://kbs0830.com/resume">
<link rel="alternate" hreflang="en" href="https://kbs0830.com/en/resume">
<link rel="alternate" hreflang="x-default" href="https://kbs0830.com/en/resume">
```

Which pages have an English version is written in exactly one place (a set of URL rules). The sitemap, the menu, Ctrl+K, the footer's switch link and the English list in `/llms.txt` all read from it, so adding an English page means adding one rule. `x-default` points to English: for people whose language matches neither (Japanese or Korean, for example), English is easier to read than Traditional Chinese, and it does not affect `/` showing Chinese by default.

hreflang has to point **both ways**; if only one side links, the whole set is ignored. An E2E test guards that.

## No i18n package

Packages like next-intl mainly solve many languages, plural rules, ICU message format, and middleware redirects. Here there are two languages, almost no plurals, and deliberately no redirect.

UI strings follow the official guide's dictionary approach, but in TypeScript rather than JSON: **the English dictionary's type is taken from the Chinese one**, so a missing translation fails to compile. Page content keeps the site's existing habit of putting both languages in the same object (projects already had `title` and `titleZh`). The long content of the project pages lives in a separate file, and a unit test compares paragraph and item counts between the two languages, so adding a paragraph in Chinese without matching it in English is blocked.

## Four traps while moving the folders

I shipped the folder move on its own, and the acceptance criterion was that **the route type of every route in the build output (○ / ◐ / ƒ / ●) is identical, line by line, to before the move**. The route types did match, but I still hit four traps:

1. **The home page share image disappeared.** The root `app/opengraph-image.tsx` image itself was still there, but it is no longer attached automatically to the home page under `(zh)`. The test server showed `og:image` missing; the fix was to state it explicitly in metadata.
2. **Share image URLs inside route groups got a hash**: `/airports/opengraph-image` became `/airports/opengraph-image-26r5ai`. The `<meta>` tags follow automatically, but a full URL hard-coded in code or tests returns 404.
3. **After `next typegen`, tsc still said `/en` was not a valid route.** The generated type file clearly had `/en`; the cause was the incremental cache in `tsconfig.tsbuildinfo` not noticing. Delete it and rerun.
4. **The deploy script clears the Cloudflare cache based on the first-level folders of `src/app`**, and it already skipped folders starting with `(`. After moving the pages into `(zh)`, no page's cache would have been cleared. I changed it to list one level inside the group; before and after the move it clears the same 49 paths.

## English pages must not leak Chinese

Finally I added an E2E test: open an English page and scan every **visible** text node, failing on any Han character (excluding Japanese accents marked `lang="ja"` and the "Chinese" switch link marked `lang="zh-Hant"`).

The first run caught more than thirty. Most were in the hand-drawn illustrations on project cards: the text in those SVGs is Chinese, so the English version uses screenshots for now. Two English descriptions also had Chinese mixed in: names of competition categories and a course name, plus the project tag "data visualization" (a Chinese tag).

Another was the 320px width check: the "Kaohsiung ─ ✈ ─ Fukuoka" line under Contact grew by 6px with English city names. The English version uses the airport codes KHH and FUK instead, which also fits the plane motif used across the site.

## Where it stands

The English version has the home page, the resume and 16 project pages, and each has a Markdown version (`/en/index.md`, `/en/resume.md`). For the blog, I will pick a few posts that people search for internationally and translate them in full.

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/blog/bilingual-two-root-layouts
