Built using Docusaurus 3, a modern static website generator.
- How to develop
- Build
- Release a new version
- How to add a new language translation
- How to contribute
- License
pnpm i # install deps
pnpm startThis command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
By default, the start command will only preview documents in English. If you want to preview documents in other languages, such as Chinese, then add --locale after the command:
pnpm start --locale zhpnpm buildThis command generates static content into the build directory and can be served using any static contents hosting service.
pnpm docusaurus docs:version x.x.xThe doc versions are split into two parts, one is the latest (in docs/) and the others are versioned (in versioned_docs/). When releasing a new version, the current latest docs/ will be copied into versioned_docs/ (by running the command above).
After running the command, you need to do the following steps:
- Update
src/data/versions.js.
All translated docs won't be copied automatically. You have to handle them manually. For example, release 2.2.0:
-
Copy
i18n/zh/docusaurus-plugin-content-docs/current.jsonto the same folder and rename it toi18n/zh/docusaurus-plugin-content-docs/version-2.2.0.json(Newly Docusaurus versions will do this automatically). -
The replace
Nextandcurrentinversion-2.2.0.json, e.g.:"version.label": { "message": "Next", "description": "The label for version current" }
to:
"version.label": { "message": "2.2.0", "description": "The label for version 2.2.0" }
Don't forget test the new version build after you've done the above steps!
For patch versions, it's only needed to move some folders and change some text. For example, v2.1.3 to v2.1.4:
- Replace
2.1.3in versions.json with2.1.4. versioned_docs/version-2.1.3toversioned_docs/version-2.1.4.versioned_sidebars/version-2.1.3-sidebars.jsontoversioned_sidebars/version-2.1.4-sidebars.json.i18n/zh/docusaurus-plugin-content-docs/version-2.1.3toi18n/zh/docusaurus-plugin-content-docs/version-2.1.4.i18n/zh/docusaurus-plugin-content-docs/version-2.1.3.jsontoi18n/zh/docusaurus-plugin-content-docs/version-2.1.4.jsonand replace2.1.3with2.1.4in json.- Update
src/data/versions.js.
Don't forget test the new version build after you've done the above steps!
Please refer to https://docusaurus.io/docs/i18n/tutorial for the basic steps.
Below are some specific points:
-
Use Docusaurus translation APIs for all user-facing text in React pages and components:
- Use
<Translate>for JSX children. - Use
translate()for values that must be strings, such as page metadata,alt,aria-label, andplaceholderprops. - Keep default messages as hardcoded strings so that Docusaurus can extract them statically.
- Use
<Translate values={...}>for rich text. JSX elements such as styled text and links can be passed as placeholders, so do not branch oni18n.currentLocale.
For example, a homepage heading with translated, styled text should use JSX interpolation:
<Translate id="home.features.title" values={{ emphasis: ( <span className={styles.heroTitle}> <Translate id="home.features.title.emphasis">Cloud Native + Chaos Engineering</Translate> </span> ), }} > {'Make {emphasis} simple and straightforward'} </Translate>
- Use
-
After adding or changing translatable React text, extract the translation keys:
pnpm write-translations --locale zh
Translate the generated entries in
i18n/zh/code.json. Other locales use the samei18n/<locale>/code.jsonconvention. Review the generated diff before committing because the command can also refresh translation metadata from Docusaurus plugins. -
Preview and verify the translated site:
pnpm start --locale zh pnpm build
The production build must succeed for every locale configured in
docusaurus.config.js.
You usually only need to modify the content in the docs/ directory, but if some old versions also need to be updated, please update the related content in the versioned_docs/ directory.
Distributed under CC-BY-4.0.