i18n: {
defaultLocale: "zh-CN",
locales: ["en", "zh-CN"],
localeConfigs: {
en: {
label: "English",
},
"zh-CN": {
label: "简体中文",
},
},
}
执行
yarn
yarn run start --locale zh-CN
执行
yarn write-translations --locale zh-CN
翻译
i18n\zh-CN\code.json
JSON 用于翻译:
- React 代码:
src/pages
中的独立 React 页面或其他组件 - 通过
themeConfig
提供的布局标签:导航栏、页脚 - 通过插件选项提供的布局标签:文档侧边栏类别标签、博客侧边栏标题...
- 创建目录
mkdir -p i18n/zh-CN/docusaurus-plugin-content-docs/current
mkdir -p i18n/zh-CN/docusaurus-plugin-content-blog
- 复制文件
cp -r docs/** i18n/zh-CN/docusaurus-plugin-content-docs/current
cp -r blog/** i18n/zh-CN/docusaurus-plugin-content-blog
- 翻译json文件的内容
i18n\zh-CN\docusaurus-plugin-content-docs\current.json
i18n\zh-CN\code.json
- 翻译md, mdx文件
node .\i18n\translate-docs.js
i18n\zh-CN\docusaurus-plugin-content-docs\current\getting-started\advanced-topics\env-configuration.md , 文件比较大, 优先手动翻译
- 使用显式标题 ID(可选)
yarn write-heading-ids i18n/zh-CN/docusaurus-plugin-content-docs/current
- 增加搜索功能
- 参考 https://docusaurus.nodejs.cn/docs/search#algolia-no-search-results
- 参考 https://docusaurus.nodejs.cn/community/resources#search
- 参考 https://jdocs.wiki/docusaurus-site/site-creation-guide/docusaurus-lunr-search
添加依赖
yarn add docusaurus-lunr-search
yarn add @node-rs/jieba
构建
yarn add docusaurus-lunr-search
运行
serve build
This website is built using Docusaurus, a modern static website generator.
npm ci
npm start
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
npm run build
This command generates static content into the build
directory and can be served using any static contents hosting service.
Using SSH:
USE_SSH=true npm run deploy
Not using SSH:
GIT_USER=<Your GitHub username> npm run deploy
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the gh-pages
branch.