Menu

Shipping a two-language static site without a translation API
📰

Shipping a two-language static site without a translation API

DEV Community: astro·Ayu GTA6·6 days ago
#ptdDn5E2
#devtoastro#devto#dev#default#version
Long article (316 words) — no AI summary yet.
Reading 0:00
15s threshold

The site I run about GTA6 is built with Astro and served as completely static HTML. It has an English version and a Chinese version, with every page existing in both. No server, no runtime translation, no CMS.

Here is what I learned doing it.

Prefix the default language too

My first version put English at the root and Chinese under /zh/ . It worked, but it made canonical tags and hreflang messy, and switching languages felt inconsistent. I switched to prefixDefaultLocale: true so that English lives at /en/ , Chinese at /zh/ , and the bare root just redirects.

A 301 on / to /en/ in a _redirects file is all it takes on Cloudflare Pages. Clean URLs, unambiguous canonicals, one x-default that actually points somewhere.

x-default is not optional

Google's docs mention hreflang="x-default" in passing, but for a site with two languages it is the tag that decides who lands where. I point it at /en/ because English is the wider audience.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.