qwik-docs supports multilingual sites end to end: locale-prefixed URLs, per-locale content directories, right-to-left languages, fallback content, and a translated UI with a language picker. The routing and translation model is ported from Astro Starlight. This guide shows how to configure locales and how to use the routing and translation helpers directly.
Configure i18n
Declare your languages with locales and pick one as defaultLocale.
// qwik-docs.config.ts
import { defineConfig, collection, withPrefix } from '@qwik-docs/framework';
export default defineConfig({
title: 'My Docs',
// The default language. Its URL prefix is stripped by getLocaleFromPath.
defaultLocale: 'en',
locales: {
en: { label: 'English', lang: 'en' },
'zh-cn': { label: '简体中文', lang: 'zh-CN' },
ar: { label: 'العربية', lang: 'ar', dir: 'rtl' },
},
content: withPrefix('docs', collection({ directory: 'content' })),
});
Each locale entry takes:
| Field | Type | Meaning |
|---|---|---|
label | string | Name shown in the language picker. |
lang | string | BCP-47 tag written to <html lang>. |
dir | 'ltr' | 'rtl' | Text direction. Defaults to 'ltr'. |
The catch-all docs route derives the active locale from the request path with getLocaleFromPath, passes it to generateRouteData, and route data derives lang and dir from the matched locale config.
The defaultLocale is served without a URL prefix; every other locale is served under /<locale>/….
Per-locale content directories
Structure content one directory per locale under your collection root. The leading locale segment maps to the URL locale prefix and is stripped from the slug.
- content/
- en/
- index.mdx
- guides/
- getting-started.mdx
- zh-cn/
- index.mdx
- guides/
- getting-started.mdx
- ar/
- index.mdx
- en/
With the config above, content/zh-cn/guides/getting-started.mdx serves at /zh-cn/docs/guides/getting-started/, and the English page at content/en/guides/getting-started.mdx serves at /docs/guides/getting-started/ — no en prefix, because en is the default locale.
Root locale and monolingual sites
To serve one language without a URL prefix, mark it as the root locale with the root key.
This suits a monolingual site, or a site whose main language sits at the root while others are prefixed.
// qwik-docs.config.ts
export default defineConfig({
title: 'My Docs',
locales: {
root: { label: 'English', lang: 'en' },
'zh-cn': { label: '简体中文', lang: 'zh-CN' },
},
});
Content for the root locale lives directly under the collection root, not in a locale subdirectory.
getLocaleFromPath treats the root locale as unprefixed: a path whose first segment matches no configured locale resolves to the root locale.
Routing helpers
These functions are exported from @qwik-docs/framework.
They are pure and take the resolved config, so you can call them from a custom route or component.
import {
getLocaleFromPath,
stripLocale,
localizePathname,
getLanguageTag,
getLocales,
} from '@qwik-docs/framework';
getLocaleFromPath(pathname, config)
Returns the locale key when the first path segment matches a configured, non-default locale.
Returns undefined for the default locale or an unmatched path.
stripLocale(pathname, locale?)
Removes a leading /<locale> segment from a pathname.
localizePathname(pathname, locale?)
Adds a leading /<locale> segment to a pathname.
With no locale, it returns the pathname unchanged.
getLanguageTag(locale, config)
Returns the BCP-47 tag for a locale key, from locales[locale].lang.
Falls back to the locale key, then to 'en'.
getLocales(config)
Returns all configured locale keys.
Translate qwik-docs's UI
qwik-docs ships built-in UI strings and a translator, ported from Astro Starlight.
import { createTranslator, defaultTranslations } from '@qwik-docs/framework';
import type { UITranslations } from '@qwik-docs/framework';
createTranslator(locale, userTranslations?) returns a t(key) function.
It merges, in order: defaultTranslations, the built-in translations for locale, and your userTranslations[locale].
An unknown key falls back to the English default, then to the key itself.
The returned function also exposes t.all() for the merged object and t.locale.
Provide translations for a locale through the userTranslations argument, keyed by locale:
const t = createTranslator('zh-cn', {
'zh-cn': {
'search.label': '搜索',
'tableOfContents.onThisPage': '本页内容',
},
});
t('search.label'); // '搜索'
The header, table of contents, pagination, and other chrome resolve their strings through the translator for the active locale, so overrides you pass show up in the rendered site.
Translatable UI strings
These are the keys UITranslations defines, with their English defaults.
Pass overrides through createTranslator's second argument, keyed by locale.
| Key | Default |
|---|---|
skipLink.label | Skip to content |
search.label | Search |
search.ctrlKey | Ctrl |
search.cancelLabel | Cancel |
search.devWarning | Search is only available in production builds. |
themeSelect.accessibleLabel | Select theme |
themeSelect.dark | Dark |
themeSelect.light | Light |
themeSelect.auto | Auto |
languageSelect.accessibleLabel | Select language |
menuButton.accessibleLabel | Menu |
sidebarNav.accessibleLabel | Main |
tableOfContents.onThisPage | On this page |
page.editLink | Edit page |
page.lastUpdated | Last updated: |
page.previousLink | Previous |
page.nextLink | Next |
page.draft | This content is a draft and will not be included in production builds. |
notFound.title | Page not found |
notFound.text | Check the URL or try using the search bar. |
The set is fixed by the UITranslations interface.
Fallback content
When a page exists in the default locale but not in the active locale, qwik-docs serves the default-locale page in its place and marks it as a fallback.
Route data carries isFallback: true for that request, and the page renders a translation notice telling readers they are viewing untranslated content.
This lets you ship a partially translated site: pages you have not translated yet keep working in every locale, and translated pages replace the fallback as you add them.
Language picker
The header renders a LanguageSelect component when more than one locale is configured.
It lists every locale by its label, and selecting one navigates to the same page in that locale using localizePathname.
Its accessible label comes from the languageSelect.accessibleLabel UI string, so it is translated with the rest of the chrome.
Accessing the current locale
Route data carries a locale field, along with dir and lang, on the LocaleData shape.
interface LocaleData {
dir: 'ltr' | 'rtl';
lang: string;
locale?: string;
}
generateRouteData derives all three from the locale detected on the request path: locale is the matched key, lang is locales[locale].lang, and dir is locales[locale].dir (defaulting to 'ltr').
The <html> element receives lang and dir so right-to-left languages lay out correctly.
Read the resolved locale, lang, and dir from route data through the docs context.
See the Route Data guide for how to access it.