From 20c970682bb7043c096e3fb0a09add3b341abc08 Mon Sep 17 00:00:00 2001 From: HesterG Date: Fri, 26 May 2023 14:30:13 +0800 Subject: [PATCH] Add Chinese support (#13) # Main changes and Some notices - Chines Docs should be put into corresponding versions' folders under `i18n/zh-cn/docusaurus-plugin-content-docs`. See [translate-markdown-files](https://docusaurus.io/docs/i18n/tutorial#translate-markdown-files) for reference. And also [srs-docs](https://github.com/ossrs/srs-docs) is a project that can be used as a reference. So changed the related paths in `loop_docs*` scripts. - The markdown files under `docs/` and `i18n/zh-cn/docusaurus-plugin-content-docs/` must have the same name to be referred as translated. Files inside docs are corresponding to `current` version. For example, `docs/administration/mail-templates.md` and `i18n/zh-cn/docusaurus-plugin-content-docs/current/administration/mail-templates.md`. Filename of `mail-templates.md` must be the same (cannot be `mail-templates.zh-cn.md` and `mail-templates.us-en.md`) So trim the `.en-us.md` and `.zh-cn.md` to `.md` to ensure the same names inside `loop_docs*` scripts. - Used `npx docusaurus write-translations --locale zh-cn` to do sidebar, footer, and header translations, so no need to keep `sideBarCN` anymore. [reference](https://docusaurus.io/docs/cli#docusaurus-write-translations-sitedir) - Local Tests for `en` and `zh-cn` are separeted, run the following on local respectly to test them ```bash # test en version npm run start # test zh-cn version npm run start -- --locale zh-cn ``` - If wants to test `en` and `zh-cn` both at the same time, run build and serve ``` npm run build npm run serve ``` - Added some indexed page, for example: ![Screen Shot 2023-05-26 at 13.49.34](/attachments/9eeb3d38-c309-457d-9015-053b9c5ca8d6) ![Screen Shot 2023-05-26 at 13.49.49](/attachments/fc348d17-ce4c-4c4d-9240-b69add4ef06e) Reviewed-on: https://gitea.com/gitea/gitea-docusaurus/pulls/13 Co-authored-by: HesterG Co-committed-by: HesterG --- .gitea/workflows/build-and-publish.yaml | 4 +- .gitignore | 4 +- Makefile | 25 ++-- README.md | 25 ++++ docusaurus.config.js | 17 ++- .../current.json | 29 ++++ .../version-1.19.json | 26 ++++ .../docusaurus-theme-classic/footer.json | 34 +++++ .../docusaurus-theme-classic/navbar.json | 14 ++ loop_docs-19-zh-cn.sh | 33 +++-- loop_docs-19.sh | 7 +- loop_docs-zh-cn.sh | 32 +++-- loop_docs.sh | 7 +- sidebars.js | 131 +++++------------- versioned_sidebars/version-1.19-sidebars.json | 26 +++- 15 files changed, 263 insertions(+), 151 deletions(-) create mode 100644 i18n/zh-cn/docusaurus-plugin-content-docs/current.json create mode 100644 i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19.json create mode 100644 i18n/zh-cn/docusaurus-theme-classic/footer.json create mode 100644 i18n/zh-cn/docusaurus-theme-classic/navbar.json diff --git a/.gitea/workflows/build-and-publish.yaml b/.gitea/workflows/build-and-publish.yaml index 785a4d44..2a756d06 100644 --- a/.gitea/workflows/build-and-publish.yaml +++ b/.gitea/workflows/build-and-publish.yaml @@ -21,11 +21,11 @@ jobs: - name: prepare nightly docs run: | make prepare-latest - #prepare-latest-zh-cn + make prepare-latest-zh-cn - name: prepare 1.19 docs run: | make prepare\#19 - #prepare-zh-cn\#19 + make prepare-zh-cn\#19 - name: cleanup before build run: | rm static/_* diff --git a/.gitignore b/.gitignore index 17361fa9..8f85ba80 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,6 @@ versioned_docs/ static/_headers static/_redirects static/latest-swagger.json -static/19-swagger.json \ No newline at end of file +static/19-swagger.json +i18n/zh-cn/docusaurus-plugin-content-docs/current +i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19 diff --git a/Makefile b/Makefile index e8055300..4fb67813 100644 --- a/Makefile +++ b/Makefile @@ -27,12 +27,13 @@ prepare-latest: clone_main bash loop_docs.sh .PHONY: prepare-latest-zh-cn -prepare-latest-zh-cn: clone_main - cp -r .tmp/upstream-docs-latest/docs/static/* static/ - rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-latest/docs/content/doc/ docs/zh-cn/ - cp .tmp/upstream-docs-latest/docs/content/page/index.zh-cn.md docs/zh-cn/intro.md +prepare-latest-zh-cn: + # clone_main + # cp -r .tmp/upstream-docs-latest/docs/static/* static/ + mkdir -p i18n/zh-cn/docusaurus-plugin-content-docs/current + rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-latest/docs/content/doc/ i18n/zh-cn/docusaurus-plugin-content-docs/current/ + cp .tmp/upstream-docs-latest/docs/content/page/index.zh-cn.md i18n/zh-cn/docusaurus-plugin-content-docs/current/intro.md bash loop_docs-zh-cn.sh - rm docs/zh-cn/help/search.zh-cn.md || true .PHONY: clone_\#% clone_\#%: create_dir @@ -48,15 +49,17 @@ prepare\#%: clone_\#% cp .tmp/upstream-docs-$*/docs/content/page/index.en-us.md versioned_docs/version-1.$*/intro.md cp .tmp/upstream-docs-$*/templates/swagger/v1_json.tmpl static/$*-swagger.json bash loop_docs-$*.sh - rm versioned_docs/version-1.$*/help/search.en-us.md || true + rm versioned_docs/version-1.$*/help/search.md || true .PHONY: prepare-zh-cn\#% -prepare-zh-cn\#%: clone_\#% - cp -r .tmp/upstream-docs-$*/docs/static/* static/ - rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-$*/docs/content/doc/ versioned_docs/version-1.$*/zh-cn/ - cp .tmp/upstream-docs-19/docs/content/page/index.zh-cn.md versioned_docs/version-1.$*/zh-cn/intro.md +prepare-zh-cn\#%: + # clone_\#% + # cp -r .tmp/upstream-docs-$*/docs/static/* static/ + mkdir -p i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$* + rsync -avz --prune-empty-dirs --include '*/' --include='*.zh-cn.md' --exclude '*' .tmp/upstream-docs-$*/docs/content/doc/ i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/ + cp .tmp/upstream-docs-19/docs/content/page/index.zh-cn.md i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/intro.md bash loop_docs-$*-zh-cn.sh - rm versioned_docs/version-1.$*/zh-cn/help/search.zh-cn.md || true + rm i18n/zh-cn/docusaurus-plugin-content-docs/version-1.$*/help/search.md || true .PHONY: install install: diff --git a/README.md b/README.md index a20106a6..a921bfd6 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,28 @@ make build make clean make serve ``` + +## Test en version + +``` +npm run start +``` + +## Test zh-cn version + +``` +npm run start -- --locale zh-cn +``` + +## Translate presets for zh-cn version + +``` +npx docusaurus write-translations --locale zh-cn +``` + +## Test both zh-cn and en versions + +``` +npm run build +npm run serve +``` diff --git a/docusaurus.config.js b/docusaurus.config.js index 9be017d8..095b1570 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -25,7 +25,16 @@ const config = { i18n: { defaultLocale: 'en', - locales: ['en'/*, 'zh-cn', 'fr-fr', 'zh-tw'*/], // temporarily disable other locales + locales: ['en', 'zh-cn'/*, 'fr-fr', 'zh-tw'*/], // temporarily disable other locales + localeConfigs: { + 'en': { + label: 'English', + htmlLang: 'en-US', + }, + 'zh-cn': { + label: '中文', + }, + }, }, presets: [ @@ -71,7 +80,7 @@ const config = { "@easyops-cn/docusaurus-search-local", { hashed: false, - language: ["en"], + language: ["en", "zh"], highlightSearchTermsOnTargetPage: true, explicitSearchResultPath: true, indexBlog: false, @@ -113,10 +122,10 @@ const config = { type: 'search', position: 'right', }, - /* { + { type: 'localeDropdown', position: 'right', - },*/ + }, { type: 'docsVersionDropdown', position: 'right', diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/current.json b/i18n/zh-cn/docusaurus-plugin-content-docs/current.json new file mode 100644 index 00000000..a3739122 --- /dev/null +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/current.json @@ -0,0 +1,29 @@ +{ + "sidebar.docs.category.Installation": { + "message": "安装" + }, + "sidebar.docs.category.Administration": { + "message": "管理" + }, + "sidebar.docs.category.Usage": { + "message": "使用" + }, + "sidebar.docs.category.actions": { + "message": "Actions" + }, + "sidebar.docs.category.packages": { + "message": "软件包" + }, + "sidebar.docs.category.Development": { + "message": "开发" + }, + "sidebar.docs.category.Contributing": { + "message": "贡献" + }, + "sidebar.docs.category.Help": { + "message": "帮助" + }, + "sidebar.docs.doc.What is Gitea?": { + "message": "Gitea是什么?" + } +} diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19.json b/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19.json new file mode 100644 index 00000000..bb4d50b1 --- /dev/null +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19.json @@ -0,0 +1,26 @@ +{ + "sidebar.docs.category.Installation": { + "message": "安装" + }, + "sidebar.docs.category.Administration": { + "message": "管理" + }, + "sidebar.docs.category.Usage": { + "message": "使用" + }, + "sidebar.docs.category.Packages": { + "message": "软件包" + }, + "sidebar.docs.category.Development": { + "message": "开发" + }, + "sidebar.docs.category.Contributing": { + "message": "贡献" + }, + "sidebar.docs.category.Help": { + "message": "帮助" + }, + "sidebar.docs.doc.What is Gitea?": { + "message": "Gitea是什么?" + } +} diff --git a/i18n/zh-cn/docusaurus-theme-classic/footer.json b/i18n/zh-cn/docusaurus-theme-classic/footer.json new file mode 100644 index 00000000..d6798db1 --- /dev/null +++ b/i18n/zh-cn/docusaurus-theme-classic/footer.json @@ -0,0 +1,34 @@ +{ + "link.title.Docs": { + "message": "文档", + "description": "The title of the footer links column with title=Docs in the footer" + }, + "link.title.Community": { + "message": "社区", + "description": "The title of the footer links column with title=Community in the footer" + }, + "link.title.More": { + "message": "更多", + "description": "The title of the footer links column with title=More in the footer" + }, + "link.item.label.Tutorial": { + "message": "教程", + "description": "The label of footer link with label=Tutorial linking to /" + }, + "link.item.label.Code": { + "message": "开源代码", + "description": "The label of footer link with label=Code linking to https://github.com/go-gitea/gitea" + }, + "link.item.label.Stack Overflow": { + "message": "Stack Overflow", + "description": "The label of footer link with label=Stack Overflow linking to https://stackoverflow.com/questions/tagged/gitea" + }, + "link.item.label.Discord": { + "message": "Discord", + "description": "The label of footer link with label=Discord linking to https://discord.gg/gitea" + }, + "link.item.label.Twitter": { + "message": "Twitter", + "description": "The label of footer link with label=Twitter linking to https://twitter.com/giteaio" + } +} diff --git a/i18n/zh-cn/docusaurus-theme-classic/navbar.json b/i18n/zh-cn/docusaurus-theme-classic/navbar.json new file mode 100644 index 00000000..4e34b1b4 --- /dev/null +++ b/i18n/zh-cn/docusaurus-theme-classic/navbar.json @@ -0,0 +1,14 @@ +{ + "title": { + "message": "Gitea" + }, + "item.label.Docs": { + "message": "开源文档" + }, + "item.label.Code": { + "message": "代码" + }, + "item.label.Support": { + "message": "支持" + } +} diff --git a/loop_docs-19-zh-cn.sh b/loop_docs-19-zh-cn.sh index 8f410edc..d2c72084 100644 --- a/loop_docs-19-zh-cn.sh +++ b/loop_docs-19-zh-cn.sh @@ -8,44 +8,47 @@ else SED_INPLACE="sed -i ''" fi -$SED_INPLACE 's/}}//' $file $SED_INPLACE 's/{{< version >}}/1.19.0/g' $file - $SED_INPLACE 's/{{< relref "doc/\/docs\/zh-cn/g' $file + $SED_INPLACE 's/{{< relref "doc/i18n\/zh-cn\/docusaurus-plugin-content-docs\/version-1.19/g' $file $SED_INPLACE 's/" >}}//g' $file $SED_INPLACE 's/\*\*Table of Contents\*\*//' $file $SED_INPLACE 's/weight:/sidebar_position:/g' $file done -for file in versioned_docs/version-1.19/zh-cn/*; do +for file in i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19/*; do if [ -d $file ]; then continue fi - if [ "$file" == "versioned_docs/version-1.19/zh-cn/intro.md" ]; then + if [ "$file" == "i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19/intro.md" ]; then continue fi rm $file done -# for file in `find ./versioned_docs/version-1.19/zh-cn/ -name "*.md"`; do +for file in `find ./i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19/ -name "*.zh-cn.md"`; do + mv "${file}" "${file/.zh-cn/}" +done + +# for file in `find ./version ed_docs/version-1.19/zh-cn/ -name "*.md"`; do # trimmed=$(echo $file | cut -f 2 -d '.') # mv $file .$trimmed.md # done diff --git a/loop_docs-19.sh b/loop_docs-19.sh index c43bae4c..756d3a24 100644 --- a/loop_docs-19.sh +++ b/loop_docs-19.sh @@ -10,7 +10,6 @@ fi $SED_INPLACE 's/}}//' $file $SED_INPLACE 's/{{< version >}}/1.19.3/g' $file - $SED_INPLACE 's/{{< relref "doc/\/docs/g' $file + $SED_INPLACE 's/{{< relref "doc/versioned_docs\/version-1.19/g' $file $SED_INPLACE 's/" >}}//g' $file $SED_INPLACE 's/\*\*Table of Contents\*\*//' $file $SED_INPLACE 's/weight:/sidebar_position:/g' $file @@ -38,3 +37,7 @@ for file in versioned_docs/version-1.19/*; do fi rm $file done + +for file in `find ./versioned_docs/version-1.19/ -name "*.en-us.md"`; do + mv "${file}" "${file/.en-us/}" +done diff --git a/loop_docs-zh-cn.sh b/loop_docs-zh-cn.sh index bbca373f..9878be81 100644 --- a/loop_docs-zh-cn.sh +++ b/loop_docs-zh-cn.sh @@ -8,45 +8,47 @@ else SED_INPLACE="sed -i ''" fi -$SED_INPLACE 's/}}//' $file $SED_INPLACE 's/{{< version >}}/1.18.2/g' $file - $SED_INPLACE 's/{{< relref "doc/\/docs\/zh-cn/g' $file + $SED_INPLACE 's/{{< relref "doc/i18n\/zh-cn\/docusaurus-plugin-content-docs\/current/g' $file $SED_INPLACE 's/" >}}//g' $file $SED_INPLACE 's/\*\*Table of Contents\*\*//' $file $SED_INPLACE 's/weight:/sidebar_position:/g' $file done -for file in docs/zh-cn/*; do +for file in i18n/zh-cn/docusaurus-plugin-content-docs/current/*; do if [ -d $file ]; then continue fi - if [ "$file" == "docs/zh-cn/intro.md" ]; then + if [ "$file" == "i18n/zh-cn/docusaurus-plugin-content-docs/current/intro.md" ]; then continue fi rm $file done +for file in `find ./i18n/zh-cn/docusaurus-plugin-content-docs/current/ -name "*.zh-cn.md"`; do + mv "${file}" "${file/.zh-cn/}" +done -# for file in `find ./docs/zh-cn/ -name "*.md"`; do +# for file in `find ./i18n/zh-cn/docusaurus-plugin-content-docs/current/ -name "*.md"`; do # trimmed=$(echo $file | cut -f 2 -d '.') # mv $file .$trimmed.md # done diff --git a/loop_docs.sh b/loop_docs.sh index b9696e22..35d71279 100644 --- a/loop_docs.sh +++ b/loop_docs.sh @@ -13,7 +13,6 @@ $SED_INPLACE 's/}}//' $file $SED_INPLACE 's/{{< version >}}/main-nightly/g' $file - $SED_INPLACE 's/{{< relref "doc/\/docs/g' $file + $SED_INPLACE 's/{{< relref "doc/i18n\/en\/docusaurus-plugin-content-docs\/current/g' $file $SED_INPLACE 's/" >}}//g' $file $SED_INPLACE 's/\*\*Table of Contents\*\*//' $file $SED_INPLACE 's/weight:/sidebar_position:/g' $file @@ -39,3 +38,7 @@ for file in docs/*; do fi rm $file || true done + +for file in `find ./docs/ -name "*.en-us.md"`; do + mv "${file}" "${file/.en-us/}" +done diff --git a/sidebars.js b/sidebars.js index 94da70f7..66dd1be2 100644 --- a/sidebars.js +++ b/sidebars.js @@ -1,146 +1,87 @@ module.exports = { - defaultSidebar: [ + docs: [ { - type: 'link', + type: 'doc', + id: 'intro', label: 'What is Gitea?', - href: '/next/' }, { type: 'category', label: 'Installation', + link: { + "type": "generated-index" + }, items: [ - { + { type: 'autogenerated', dirName: 'installation', - } + } ] }, { type: 'category', label: 'Administration', + link: { + "type": "generated-index" + }, items: [ - { + { type: 'autogenerated', dirName: 'administration', - } + } ] }, { type: 'category', label: 'Usage', + link: { + "type": "generated-index" + }, items: [ - { - type: 'autogenerated', - dirName: 'usage', - } + { + type: 'autogenerated', + dirName: 'usage', + } ] }, { type: 'category', label: 'Development', + link: { + "type": "generated-index" + }, items: [ - { + { type: 'autogenerated', dirName: 'development', - } + } ] }, { type: 'category', label: 'Contributing', + link: { + "type": "generated-index" + }, items: [ - { + { type: 'autogenerated', dirName: 'contributing', - } + } ] }, { type: 'category', label: 'Help', + link: { + "type": "generated-index" + }, items: [ - { + { type: 'autogenerated', dirName: 'help', - } + } ] }, - ]/*, - siderBarCN: [ - { - type: 'link', - label: 'Gitea是什么?', - href: 'zh-cn/next/' - }, - { - type: 'category', - label: '安装', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/installation', - } - ] - }, - { - type: 'category', - label: '管理', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/administration', - } - ] - }, - { - type: 'category', - label: '使用', - items: [ - { - type: 'category', - label: '软件包管理', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/usage/packages', - } - ] - }, - { - type: 'autogenerated', - dirName: 'zh-cn/usage', - } - ] - }, - { - type: 'category', - label: '开发', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/development', - } - ] - }, - { - type: 'category', - label: '贡献', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/contributing', - } - ] - }, - { - type: 'category', - label: '帮助', - items: [ - { - type: 'autogenerated', - dirName: 'zh-cn/help', - } - ] - }, - ],*/ + ] }; \ No newline at end of file diff --git a/versioned_sidebars/version-1.19-sidebars.json b/versioned_sidebars/version-1.19-sidebars.json index 48d1881c..af983c3f 100644 --- a/versioned_sidebars/version-1.19-sidebars.json +++ b/versioned_sidebars/version-1.19-sidebars.json @@ -1,13 +1,16 @@ { - "defaultSidebar": [ + "docs": [ { - "type": "link", - "label": "What is Gitea?", - "href": "/" + "type": "doc", + "id": "intro", + "label": "What is Gitea?" }, { "type": "category", "label": "Installation", + "link": { + "type": "generated-index" + }, "items": [ { "type": "autogenerated", @@ -18,6 +21,9 @@ { "type": "category", "label": "Administration", + "link": { + "type": "generated-index" + }, "items": [ { "type": "autogenerated", @@ -28,6 +34,9 @@ { "type": "category", "label": "Usage", + "link": { + "type": "generated-index" + }, "items": [ { "type": "category", @@ -48,6 +57,9 @@ { "type": "category", "label": "Development", + "link": { + "type": "generated-index" + }, "items": [ { "type": "autogenerated", @@ -58,6 +70,9 @@ { "type": "category", "label": "Contributing", + "link": { + "type": "generated-index" + }, "items": [ { "type": "autogenerated", @@ -68,6 +83,9 @@ { "type": "category", "label": "Help", + "link": { + "type": "generated-index" + }, "items": [ { "type": "autogenerated",