Internationalization

Most of the internal documentation of alauda is bilingual in Chinese and English. Therefore, we by default support using en/zh subfolders to store documents in different languages. It is recommended to also store static resources under en/zh subfolders in the public directory, which facilitates the management of both documentation content and static resources.

TOC

i18n.json

For reusable components, if you need to support both Chinese and English within the same component, you first need to create an i18n.json file under the docs directory. Then, in the component, use useI18n to get the text for the current language, for example:

docs/i18n.json
{
  "title": {
    "zh": "标题",
    "en": "Title"
  },
  "description": {
    "zh": "描述",
    "en": "description"
  }
}

.ts/.tsx

import { useI18n } from '@rspress/core/runtime'

export const CommonContent = () => {
  const t = useI18n()
  return <h1>{t('title')}</h1>
}

.mdx

import { useI18n } from '@rspress/core/runtime'

# {useI18n()('title')}

{useI18n()('description')}