Internationalization
Press supports multi-locale documentation via locale routing. Each locale has its own root URL prefix (/en/, /vi/, etc.) and its own themeConfig overrides.
Setup
Define locales in press.config.ts. Each key becomes the URL prefix; the key "/" is the root (default) locale:
import { defineConfig } from "@domphy/press"
export default defineConfig({
title: "My Docs",
locales: {
"/": {
label: "English",
lang: "en",
},
"/vi/": {
label: "Tiếng Việt",
lang: "vi",
title: "Tài liệu của tôi",
themeConfig: {
nav: [
{ text: "Hướng dẫn", link: "/vi/guide/" },
],
sidebar: {
"/vi/guide/": [
{ text: "Bắt đầu", link: "/vi/guide/" },
],
},
},
},
},
themeConfig: {
nav: [
{ text: "Guide", link: "/guide/" },
],
sidebar: {
"/guide/": [
{ text: "Getting Started", link: "/guide/" },
],
},
},
})File structure
Locale-specific Markdown lives in subdirectories matching the locale prefix:
docs/
guide/ ← default locale (/guide/...)
index.md
intro.md
vi/
guide/ ← /vi/guide/...
index.md
intro.mdLocaleConfig fields
interface LocaleConfig {
label: string // shown in the locale switcher
lang: string // HTML lang attribute, e.g. "en" or "vi"
title?: string // overrides site title for this locale
description?: string // overrides site description
themeConfig?: Partial<ThemeConfig> // nav/sidebar/etc. overrides for this locale
}Language switcher
Press renders a locale switcher in the nav automatically when locales is defined. It shows each locale's label and links to the corresponding route in the other locale.
RTL support
Set lang to an RTL language code (e.g. "ar", "he") to enable automatic dir="rtl" on the <html> element and mirrored layout.
Using @domphy/i18n for UI strings
For translating UI strings (button labels, placeholders, error messages) in custom slot components, use @domphy/i18n alongside Press locales:
import { createI18n } from "@domphy/i18n"
import en from "./locales/en.json"
import vi from "./locales/vi.json"
const i18n = createI18n<"en" | "vi", typeof en>({
globalKey: "__my_docs_i18n__",
namespace: "docs",
locales: { en, vi },
defaultLocale: "en",
})
// In a slot:
slots: {
footer: (ctx) => ({
footer: i18n.t("footer.copyright"),
// ...
}),
}See the @domphy/i18n package docs for the full API.