Language

Multilingual Sites and Text Direction

Language is decided only by the address, dir follows the language actually on screen, and the two current boundaries: spacing is not mirrored, and someone has to press publish once.

In theme development for a multilingual site, language and text direction are both things the theme does not decide. This page covers what a theme actually has to obey, how far that goes today, and which part is not done yet.

Language is decided by the address and never negotiated. The primary language owns the unprefixed address: with English as the primary language / is English and Chinese can live at /cn/; switch the primary language to Chinese and / belongs to Chinese while the original English moves to /en/. Detail pages follow the same shape (/about, /cn/about, /en/about). It is forbidden for Accept-Language, a cookie or an IP region to make one address return different languages — that is pinned by tests, together with the target of that one 301 for a redundant prefix: if the target varied with request headers, language would be handed back to negotiation through a side door. A redundant primary-language prefix collapses onto the bare address, ?lang= collapses into the path form, and a trailing slash collapses. A first visit redirects at most once, at /, and it must be a 302 — a 301 is cached permanently by the browser, so an English visitor clicking back to Chinese would be bounced away again and could not get out.

The public prefix and the internal language code are two layers. Chinese is cn on the outside while the internal code may be zh-CN; that mapping lives in exactly one place and is used consistently for routing, canonical, hreflang, sitemap and RSS. So the /cn/… you see on the page and the zh-CN that appears in the console and the API are not an inconsistency — they are two names for the same thing.

dir follows the language actually on screen, not the address. If, under an Arabic address, that piece of content has no Arabic translation, the server renders the source-language text honestly, and then dir should be ltr — "the address is a foreign language, so right-align it" is the wrong rule most easily written by reflex, and it would flip an entire left-aligned language. The direction value is computed in Go and handed over; the template only writes it into the attribute. The prefix/direction/bilingual-name set in the language catalog is a static table that never lands in the database, so a theme cannot change it and should not guess at it.

One dataset has two renderers, and the switcher label has two construction points too. The current built-in theme's template and the official default document template used when theme files are missing each have to write dir; the label on the language switcher also has two sources. An incident of "changed one side and everything stayed green" really happened, so the check runs on both sides. The conclusion for theme authors is: do not add your own direction logic inside your template, just consume the value handed to you.

On the page, "this entry is actually in the source language" has to be visible. Entries missing a translation carry a label (at list-item level and at page level), a title fallback is marked, and the site copy's <meta description> follows the version actually served. That is one half of "fall back honestly"; the other half is never presenting untranslated text as translated — when the body under a foreign-language address falls back, hreflang should not contain a self-reference for that language.

Two things are not done, stated up front. First, dir currently flips only writing direction: spacing written with left/right in the built-in theme is not mirrored, so under a right-aligned language some gaps look reversed. Second, a template change only takes effect as a new version, while a published snapshot still pins the old theme version — operations has to press "publish" once before the direction fix reaches existing visitors. Neither of these is "change it and it ships automatically", so do not accept them against that expectation.

One last note for anyone doing whole-site multilingual. A change to the language list (adding, enabling, changing the default) triggers one automatic advance, and that advance must carry the latest language version — otherwise you get "the new translation already shipped with the snapshot while the language list is still the old one", and then the /en/… route simply does not recognise en: the translation is stored and still invisible. That coupling is resolved in one place on the server side; the theme does not participate, but it is worth knowing: for "I translated it, why is the front end not showing it", sometimes nothing is missing from the translation — the list and the translation were simply never live at the same time.