Pagic

Internationalization

Only support docs theme for now

Configuration§

The example is as follows:

export default {
  i18n: {
    languages: [
      { code: 'en', name: 'English', root: '/' },
      { code: 'zh-CN', name: 'Simplified Chinese', root: '/zh-CN/' },
    ],
    overrides: {
      'zh-CN': {
        sidebar: {
          '/zh-CN/docs/': [
            'zh-CN/docs/introduction.md',
            'zh-CN/docs/usage.md',
            'zh-CN/docs/config.md',
            'zh-CN/docs/content.md',
            'zh-CN/docs/layout.md',
            'zh-CN/docs/themes.md',
            'zh-CN/docs/plugins.md',
            'zh-CN/docs/blog.md',
            'zh-CN/docs/i18n.md',
            'zh-CN/docs/deployment.md',
            'zh-CN/docs/demos.md',
            'zh-CN/docs/limitations.md',
          ],
        },
        blog: {
          root: '/zh-CN/blog/',
        },
      },
    },
    resources: {
      'zh-CN': {
        translation: {
          'A static site generator powered by Deno + React': 'Deno + React driven static website generator',
          'Get Started': 'Get Started',
          Demos: 'Sample website',
          'Render <1>md/tsx</1> to static HTML page': 'Support rendering <1>md/tsx</1> files into static HTML page',
        },
      },
    },
  },
};

i18n.language§

i18n.language represents an array of language lists supported by your website. Each item in the array must match { code:string, name:string, root:string }, where:

  • code is the ISO Language Code, you can refer to this website
  • name is the option displayed in the language switch component
  • root is the root directory where the language is located, and its value should always start and end with a slash

Note that the first item of i18n.language is the default language of the website, and its root must be /.

i18n.overrides§

i18n.overrides is a special configuration item, which allows to override the fields in pagic.config.ts in a specific language. Its type is Record<string, PagicConfig>, where the key must be one of the code field in i18n.language, the value type is the type of the entire pagic.config.ts. When visiting a page in this language, pagic.config will be the result of the merge.

i18n.resources§

i18n.resources describes the translation of each language, t('Get Started') and <Trans>Render <code>md/tsx</code> to static HTML page</ Trans> in tsx file will use the translation resources configured here. For the specific syntax of t() and <Trans>, please refer to react-i18next.

props§

The i18n plugin will add the following items to the props of the page:

language§

language represents the language of the current page. It is taken from one of the items in i18n.languages in pagic.config.ts, so its type is as follows:

interface Language {
  code: string;
  name: string;
  root: string;
}