---
title: I18n Locale Routing
category: product
entity_type: skill
price: $15
canonical: https://forgehouse.ai/skills/i18n-locale-routing/
lang: en
hreflang_alt: https://forgehouse.ai/tr/skiller/i18n-locale-routing/
last_updated: 2026-06-20
---

# I18n Locale Routing

> i18n locale routing setup

A battle-tested blueprint for deterministic multi-language routing in Next.js App Router and Astro, where the URL path is the single source of truth for locale. It generates reciprocal hreflang, keeps SSG and edge caches accurate, and hard-blocks the exact configuration combination that silently collapses Search Console indexing.

## Use cases
- Standing up a 2+ language site architecture in Next.js or Astro
- Fixing missing or one-way hreflang causing 'duplicate, alternates not selected' in Search Console
- Stopping stale cache that renders the wrong language after a locale switch
- Recovering from a force-static + detection-off + cookie-off crash that drops pages to 'crawled, not indexed'
- Spreading one route file across many locales automatically for programmatic SEO
- Building cookie-less locale detection for privacy compliance

## Benefits
- Avoid the silent indexing collapse that can take a month to recover from
- Ship eight languages with the maintenance cost of one through shared route files
- Keep edge cache hit rates high and locale switches under a fraction of a second
- Win correct international ranking with reciprocal hreflang and x-default fallback Google trusts

## What’s included
- Drop-in next-intl middleware and routing config with always-prefix locale paths
- Astro hybrid-output i18n setup with fallback chains and directory format
- Build-time guard that fails the build on the indexing-crash config combo
- Reciprocal hreflang generator plus a validator that counts tags per page
- Middleware whitelist with open-redirect and host protection
- Verification checklist covering hreflang, x-default, RTL dir, and invalid-locale handling

## Who it’s for
Front-end and SEO engineers building or repairing multi-locale Next.js and Astro sites where international indexing and cache correctness matter.

## How it runs
Three config flags once took a production site out of Google's index together. That guard runs before anything else, then routing locks to URL-as-truth and ships with reciprocal hreflang verified by live commands.
1. Runs the TRAP-3 triple-combo guard first: greps the codebase for force-static, localeDetection:false and localeCookie:false at the same time. If all three match, the build fails on the spot, because that exact combination took a production site's GSC indexing down.
2. Locks the routing config to URL-as-single-source-of-truth: a locale whitelist, localePrefix 'always' so the default locale is never URL-less, localeCookie false for cookie-free Edge-cache-friendly architecture, localeDetection true only as a first-visit Accept-Language fallback.
3. Hardens the middleware with two validation layers: a host whitelist against open redirects, then a locale regex whitelist that sends invalid locale paths to an x-default 308 redirect instead of a 404.
4. Applies the code-sharing pattern: one route file per page, generateStaticParams flattens locales x slugs into a cartesian build, so eight languages cost the maintenance of one.
5. Generates reciprocal hreflang in generateMetadata: every locale page lists every other locale plus itself plus x-default, because Google logs one-way hreflang as ignored.
6. Verifies with live commands: curl piped to a hreflang grep must return locales count plus one, build logs must show the N x M page count, and GSC gets a separate sitemap per locale to monitor indexing parity.

## FAQ
### We're on Astro, not Next.js. Does this still apply?
Yes. You get the next-intl middleware and routing config for Next.js App Router, and a separate Astro hybrid-output i18n setup with fallback chains and directory format. Both follow the same principle: the URL path is the single source of truth for locale.

### What is the silent indexing collapse it mentions, and how does this prevent it?
It's a specific configuration combination, force-static plus detection off plus cookie off, that drops pages to crawled-but-not-indexed and can take a month to recover from. The package includes a build-time guard that detects that combo and fails the build before it ever reaches production.

### Does it translate my content too?
No. This is the routing, reciprocal hreflang, and cache-correctness layer. Your translations come from your own workflow; the blueprint makes sure each one is served at the right URL, in the right language, with hreflang Google trusts.

## Price
$15, one-time, no subscription. VAT included.

Related guide: [AI code review and developer workflow](https://forgehouse.ai/guides/ai-code-review/)
