Internationalization #

KawaPress chooses a language from the URL. Keep the default language at the site root and put every other language in its own directory. Sites using the default nagi interface get a language menu automatically.

Add Pages for Each Language #

This site uses Chinese as its default language and also has English pages:

Text
.
├─ guide/
│  └─ getting-started.md
├─ en/
│  ├─ guide/
│  │  └─ getting-started.md
│  └─ index.md
└─ index.md

Use the same relative path for the same document in each language:

Markdown filePage URL
guide/getting-started.md/guide/getting-started
en/guide/getting-started.md/en/guide/getting-started

The root directory is the default language, so it has no language prefix. A directory such as en becomes the first URL segment.

Configure Languages #

List each language in kawapress.config.ts:

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  title: 'My Docs',
  locales: {
    root: {
      label: '简体中文',
      lang: 'zh-CN',
    },
    en: {
      label: 'English',
      lang: 'en',
    },
  },
})

root is the default language. Every other key becomes its language directory, so en maps to /en/.

FieldWhat it does
labelThe name shown in the language menu.
langThe page language, such as zh-CN or en. nagi uses it for its built-in Chinese and English interface text.
titleA site title for this language only.
descriptionThe summary of pages in this language that set no description; it comes before the site-wide description.
headExtra <head> tags for this language; see Add Head Tags.
linkThe address to open when this language is selected. It defaults to the language directory and can point to another site.
themeConfigInterface settings for this language only. They merge with site-wide settings, and matching fields are replaced here.
dirThe writing direction: ltr or rtl.

Switch Between Matching Pages #

The language menu tries to open the same document in the other language. It also keeps query parameters and heading anchors:

Text
/guide/getting-started?tab=install#first-step
→ /en/guide/getting-started?tab=install#first-step

Keep directory and file names the same for every language. KawaPress does not translate pages or look for a fallback when a matching page is missing. A missing file leads to the not-found page. Default site search also shows results for the current language only.

Default Language and Redirects #

/ is always the default-language home page. KawaPress does not redirect from a browser-language preference or remember a reader’s last choice. Readers can switch at any time from the language menu.

Localize the Sidebar #

Each language can have its own themeConfig. With nagi, defineLocalizedSidebars() lets you write one route structure:

TypeScript
// sidebar.ts
import { defineLocalizedSidebars } from 'kawapress/nagi'

export const sidebars = defineLocalizedSidebars({
  locales: {
    root: '',
    en: '/en',
  },
  items: [
    {
      text: {
        root: '指南',
        en: 'Guide',
      },
      items: [
        {
          text: {
            root: '快速开始',
            en: 'Getting Started',
          },
          link: '/guide/getting-started',
        },
      ],
    },
  ],
})

Use the matching sidebar in each language configuration:

TypeScript
// kawapress.config.ts
import { nagi } from 'kawapress/nagi'
import { sidebars } from './sidebar'

export default nagi({
  themeConfig: {
    sidebar: sidebars.root,
  },
  locales: {
    root: {
      label: '简体中文',
      lang: 'zh-CN',
    },
    en: {
      label: 'English',
      lang: 'en',
      themeConfig: {
        sidebar: sidebars.en,
      },
    },
  },
})

Write links with the default-language path. The helper adds /en for the English sidebar.

Top Navigation and Section Sidebars #

As a site grows, you can split it into sections, such as "Guide" and "Plugins". Put a link for each section at the top, and give each section its own sidebar.

Configure the top links with themeConfig.nav:

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  themeConfig: {
    nav: [
      { text: 'Guide', link: '/guide/getting-started', activeMatch: '/guide' },
      { text: 'Plugins', link: '/plugins/overview', activeMatch: '/plugins' },
    ],
  },
})

Each item has three fields:

FieldDescription
textThe text shown on the link.
linkThe page the link opens, as a site path such as /guide/getting-started.
activeMatchOptional. A path prefix. When the current page is below this prefix, the item is highlighted. Without it, the item is highlighted only on the page in link.

"Guide" above sets activeMatch: '/guide', so it stays highlighted on every page under /guide/, not only on "Getting Started".

On a narrow screen the links do not crowd the top bar. They appear in the area that opens with the menu button, above the language list.

sidebar can be an object that maps a path prefix to a sidebar. The sidebar for the prefix that contains the current page is shown:

TypeScript
export default nagi({
  themeConfig: {
    nav: [
      { text: 'Guide', link: '/guide/getting-started', activeMatch: '/guide' },
      { text: 'Plugins', link: '/plugins/overview', activeMatch: '/plugins' },
    ],
    sidebar: {
      '/guide/': [
        {
          text: 'Introduction',
          items: [{ text: 'Getting Started', link: '/guide/getting-started' }],
        },
      ],
      '/plugins/': [
        {
          text: 'Official Plugins',
          items: [{ text: 'Overview', link: '/plugins/overview' }],
        },
      ],
    },
  },
})

A page that matches no prefix falls back to the sidebar nagi generates from your directories. The home page uses layout: home, which never shows a sidebar.

Collapsible Sidebar Groups #

When a sidebar has many groups, add collapsed to let readers fold and unfold them:

  • Omitted: the group stays open and shows no toggle button.
  • collapsed: false: the group starts open and can be folded.
  • collapsed: true: the group starts closed and can be unfolded.
TypeScript
export default nagi({
  themeConfig: {
    sidebar: [
      {
        text: 'Guide',
        collapsed: false,
        items: [
          { text: 'Getting Started', link: '/guide/getting-started' },
        ],
      },
      {
        text: 'Advanced',
        collapsed: true,
        items: [
          { text: 'SSR Compatibility', link: '/guide/ssr-compatibility' },
        ],
      },
    ],
  },
})

For an automatic sidebar generated from directories, set collapsed on "type": "dir" entries in _meta.json (setting collapsed on a "file" entry or passing a non-boolean value fails the build):

JSON
[
  "getting-started",
  {
    "type": "dir",
    "name": "advanced",
    "label": "Advanced",
    "collapsed": true
  }
]

A group that contains the current page opens automatically regardless of its collapsed setting, both in the initial SSR HTML and when navigating into it. Folded child lists remain in the HTML so crawlers can still follow their links.

Use themeConfig.socialLinks to place repository or community icon links at the right end of the top navigation bar:

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  themeConfig: {
    socialLinks: [
      { icon: 'github', link: 'https://github.com/kawapress/kawapress' },
      { icon: 'discord', link: 'https://discord.gg/your-invite', ariaLabel: 'Join our Discord' },
      {
        icon: { svg: '<svg viewBox="0 0 24 24" aria-hidden="true">...</svg>' },
        link: 'https://example.com',
        ariaLabel: 'Website',
      },
    ],
  },
})
  • icon takes a Simple Icons name (such as 'github', 'discord', or 'x') or raw SVG markup as { svg: '<svg>…</svg>' }. Named icons are resolved to SVG at build time and only the icons in use are sent to the browser; an unknown icon name fails the build.
  • ariaLabel sets the accessible name of the link and defaults to the icon name when omitted.
  • Each language can override socialLinks in its own locales.<key>.themeConfig.

nagi includes local full-text search (@kawapress/plugin-search) by default. Pass search: false to nagi() when replacing it with another search plugin such as Algolia Search:

TypeScript
import algoliaSearchPlugin from '@kawapress/plugin-algolia-search'
import { nagi } from 'kawapress/nagi'

export default nagi({
  search: false,
  plugins: [
    algoliaSearchPlugin({
      appId: 'YOUR_APP_ID',
      apiKey: 'YOUR_SEARCH_API_KEY',
      indexName: 'your_index_name',
    }),
  ],
})

Write them for each language #

nav and sidebar are theme configuration, so each language can override them. Point the links at the pages of that language:

TypeScript
export default nagi({
  themeConfig: {
    nav: [
      { text: 'Guide', link: '/guide/getting-started', activeMatch: '/guide' },
    ],
  },
  locales: {
    root: { label: 'English', lang: 'en' },
    zh: {
      label: '简体中文',
      lang: 'zh-CN',
      themeConfig: {
        nav: [
          { text: '指南', link: '/zh/guide/getting-started', activeMatch: '/zh/guide' },
        ],
      },
    },
  },
})

The accessible name of the navigation area is "Main navigation" by default. Change it with navLinksLabel.

Right-to-Left Languages #

For a right-to-left language such as Arabic or Hebrew, set dir: 'rtl':

TypeScript
import { nagi } from 'kawapress/nagi'

export default nagi({
  locales: {
    ar: {
      label: 'العربية',
      lang: 'ar',
      dir: 'rtl',
    },
  },
})

KawaPress writes this direction to the page’s <html> element. It does not fully mirror an interface designed for left-to-right languages, so check and adjust your own styles as needed.

Edit this pageLast updated:

Comments