Internationalization

Site Level i18n Config

To take advantage of multi-language support in KduPress, you first need to use the following file and directory structure:

docs
├─ README.md
├─ foo.md
├─ nested
│  └─ README.md
└─ vi
   ├─ README.md
   ├─ foo.md
   └─ nested
      └─ README.md

Then, specify the locales option in .kdupress/config.js:

module.exports = {
  locales: {
    // The key is the path for the locale to be nested under.
    // As a special case, the default locale can use '/' as its path.
    '/': {
      lang: 'en-US', // this will be set as the lang attribute on <html>
      title: 'KduPress',
      description: 'Kdu-powered Static Site Generator'
    },
    '/vi/': {
      lang: 'vi-VN',
      title: 'KduPress',
      description: 'Trình tạo trang tĩnh do Kdu cung cấp'
    }
  }
}

If a locale does not have a title or description, KduPress will fallback to the root-level values. You can omit the root level title and description as long as they are provided in each locale.

Default Theme i18n Config

The default theme also has built-in i18n support via themeConfig.locales, using the same { path: config } format. Each locale can have its own nav and sidebar config, along with some other text values used across the site:

module.exports = {
  locales: { /* ... */ },
  themeConfig: {
    locales: {
      '/': {
        // text for the language dropdown
        selectText: 'Languages',
        // label for this locale in the language dropdown
        label: 'English',
        // Aria Label for locale in the dropdown
        ariaLabel: 'Languages',
        // text for the edit-on-github link
        editLinkText: 'Edit this page on GitHub',
        // config for Service Worker
        serviceWorker: {
          updatePopup: {
            message: "New content is available.",
            buttonText: "Refresh"
          }
        },
        // algolia docsearch options for current locale
        algolia: {},
        nav: [
          { text: 'Nested', link: '/nested/' , ariaLabel: 'Nested' }
        ],
        sidebar: {
          '/': [/* ... */],
          '/nested/': [/* ... */]
        }
      },
      '/vi/': {
        selectText: 'Ngôn ngữ',
        label: 'Tiếng Việt',
        editLinkText: 'Sửa trang này trên GitHub',
        serviceWorker: {
          updatePopup: {
            message: "Nội dung mới hiện có sẵn.",
            buttonText: "Làm mới"
          }
        },
        nav: [
          { text: 'Lồng nhau', link: '/vi/nested/' }
        ],
        algolia: {},
        sidebar: {
          '/vi/': [/* ... */],
          '/vi/nested/': [/* ... */]
        }
      }
    }
  }
}