Skip to content
✨ Publier v1 is live — a polished docs platform built for the open web.
On this page

Localization

Serve a second language with Astro's i18n option, a localized docs tree and localized pages, and see what Publier does not translate or link for you.

Publier has one documentation route, /docs/[...slug], and no locale-aware routing of its own. A second language is a folder of pages plus Astro’s own i18n option. This page shows a setup that Publier’s own end-to-end tests build and check, and lists what you still have to do by hand.

The examples use English as the default language and Chinese (zh) as the second one. Other locale codes should work the same way, but the tests only ran with zh.

Set up a second language

1. Turn on Astro i18n

Add i18n to astro.config.ts. docsShell() stays where it is, first in the integration list:

astro.config.ts
import { defineConfig } from 'astro/config';
export default defineConfig({
i18n: { defaultLocale: 'en', locales: ['en', 'zh'] },
// integrations, site, and the rest of your config stay as they are
});

With Astro’s default routing, pages in the default locale keep their normal URLs (/, /docs/quick-start) and every other locale gets its code as a URL prefix (/zh/). The zh segment in /docs/zh/quick-start comes from the docs folder instead (step 3). Astro’s guide describes the other routing options; the tests only used the defaults above.

2. Put localized marketing pages under src/pages/<locale>/

Astro requires the folder name to match an entry in locales exactly. A page there uses BaseLayout like any other custom page:

src/pages/zh/index.astro
---
import BaseLayout from '@publier/shell/layouts/base-layout.astro';
---
<BaseLayout title="中文首页" description="第二语言首页">
<main><h1>中文首页</h1><p>这是第二语言页面。</p></main>
</BaseLayout>

BaseLayout sets <html lang> to its lang prop, and when you pass none, to Astro.currentLocale, and when that is empty, to en. With i18n on, /zh/ therefore renders <html lang="zh">. Astro’s own reference says Astro.currentLocale is “the locale computed from the current URL”, and that without a /[locale]/ prefix it defaults to i18n.defaultLocale.

Pass lang yourself when you want a more specific tag than the locale code. An explicit lang wins over the locale:

src/pages/zh/guide.astro
---
import BaseLayout from '@publier/shell/layouts/base-layout.astro';
---
<BaseLayout title="快速开始" lang="zh-CN" description="安装并运行 Publier 站点。">
<main id="main-content" data-pagefind-body>
<h1>快速开始</h1>
<p>安装并运行 Publier 站点。</p>
</main>
</BaseLayout>

data-pagefind-body puts the page in the search index; see Search.

3. Put the translated docs in docs/<locale>/ and give them a sidebar

The docs route serves every file under src/content/docs/, so a second-language tree is another folder:

src/content/docs/
├── index.mdx → /docs
├── quick-start.mdx → /docs/quick-start
└── zh/
├── index.mdx → /docs/zh
└── quick-start.mdx → /docs/zh/quick-start

Without more configuration, these pages share one sidebar with everything else. Add the folder to docs.tabSections so it gets its own:

publier.config.yaml
docs:
tabSections: [zh]

Give each section a landing page (zh/index.mdx above). The reader of /docs/zh/quick-start then sees only the zh tree in the sidebar, and the English sidebar no longer lists the zh pages. Global settings explains how tabSections chooses the owning section for a page, and what a section without a landing page loses.

With i18n on, /docs/zh/quick-start is rendered with <html lang="zh">. The docs route passes no lang of its own, so BaseLayout falls back to the page’s Astro locale. This was checked with the zh locale and a zh folder directly under docs/; a different folder layout was not tried.

Without Astro i18n

Astro i18n is optional, but the docs tree then cannot carry its own language tag:

  • Custom pages work if every one passes an explicit lang to BaseLayout. A page that omits it is labelled en, whatever its content.
  • A docs/<locale>/ tree is labelled en. The docs route has no lang prop to set, so it falls back to en. The sidebar still works through tabSections; only the language tag is wrong.

The tag also decides which search index a page lands in; see below.

Publier’s search is Pagefind. Per Pagefind’s multilingual docs, indexing “will look for a lang attribute on your html element” and then “run independently for each detected language”. A reader on a page tagged zh searches only pages tagged zh.

In practice:

  • A localized docs tree with the right lang (Astro i18n on) gets its own index. Without i18n, it is indexed together with the English pages.
  • Pages under /docs/ are indexed automatically. Your own .astro pages are indexed only if they carry data-pagefind-body, as in the example above. Search explains the rule.
  • A test build with one page tagged lang="zh-CN" produced Pagefind indexes for en and zh-cn.

What Publier does not do

  • Built-in labels stay English. The tests check the docs navigation’s accessible name on a docs/zh page; it is still Documentation navigation. The docs route always uses the docs navigation variant, so a translated docs tree shows the same header as the English one. Custom pages can choose a variant with the nav prop; see Navigation.
  • No hreflang alternates. Pages emit no hreflang links. Search engines are not told that /docs/zh/quick-start is the translation of /docs/quick-start.
  • No link between a page and its translation. There is no language switcher, and nothing maps a page to its counterpart. If you want one, link the pages yourself.
  • No locale-aware docs route. Each language’s docs tree is plain content under one route.

The @astrojs/sitemap integration has its own i18n option for localizing the sitemap. It was not tested with Publier; check Astro’s documentation before relying on it.

Requirements

BaseLayout’s locale handling and lang prop are part of the current release, and the behaviour described here was checked against its framework source.