Improve multiple languages support

This commit is contained in:
Lunny Xiao
2023-04-04 11:14:25 +08:00
parent 588e50bc79
commit 1bfd1268e7
8 changed files with 429 additions and 13 deletions

4
.gitignore vendored
View File

@@ -18,3 +18,7 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.tmp/
docs/
versioned_docs/

View File

@@ -7,43 +7,76 @@ endif
.PHONY: all
all: build
.PHONY: prepare-latest
prepare-latest:
mkdir -p .tmp docs
.PHONY: create_dir
create_dir:
mkdir -p .tmp docs versioned_docs
.PHONY: clone_main
clone_main: create_dir
git clone --depth=1 --branch=main https://github.com/go-gitea/gitea.git .tmp/upstream-docs-latest
cur_path=`pwd`
cd .tmp/upstream-docs-latest/docs && make trans-copy
cd $(cur_path)
.PHONY: prepare-latest
prepare-latest: clone_main
cp -r .tmp/upstream-docs-latest/docs/static/* static/
rsync -avz --prune-empty-dirs --include '*/' --include='*.en-us.md' --exclude '*' .tmp/upstream-docs-latest/docs/content/doc/ docs/
cp .tmp/upstream-docs-latest/docs/content/page/index.en-us.md docs/intro.md
cp .tmp/upstream-docs-latest/templates/swagger/v1_json.tmpl static/latest-swagger.json
bash loop_docs.sh
rm docs/help/search.en-us.md
rm -rf .tmp/upstream-docs-latest
.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
cp .tmp/upstream-docs-latest/templates/swagger/v1_json.tmpl static/latest-swagger.json
bash loop_docs-zh-cn.sh
rm docs/zh-cn/help/search.zh-cn.md
.PHONY: clone_\#%
clone_\#%: create_dir
git clone --depth=1 --branch=release/v1.$* https://github.com/go-gitea/gitea.git .tmp/upstream-docs-$*
cur_path=`pwd`
cd .tmp/upstream-docs-$*/docs && make trans-copy
cd $(cur_path)
.PHONY: prepare\#%
prepare\#%:
mkdir -p versioned_docs
git clone --depth=1 --branch=release/v1.$* https://github.com/go-gitea/gitea.git .tmp/upstream-docs-$*
prepare\#%: clone_\#%
cp -r .tmp/upstream-docs-$*/docs/static/* static/
rsync -a --prune-empty-dirs --include '*/' --include='*.en-us.md' --exclude '*' .tmp/upstream-docs-$*/docs/content/doc/ versioned_docs/version-1.$*/
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
rm -rf .tmp/upstream-docs-$*
.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
cp .tmp/upstream-docs-19/templates/swagger/v1_json.tmpl static/$*-swagger.json
bash loop_docs-$*-zh-cn.sh
rm versioned_docs/version-1.$*/zh-cn/help/search.zh-cn.md
.PHONY: install
install:
npm install
.PHONY: build
build: prepare-latest prepare\#19
build: install prepare-latest prepare\#19 prepare-latest-zh-cn prepare-zh-cn\#19
npm ci
npm run build
.PHONY: serve
serve: prepare-latest
npm run serve
serve: install prepare-latest prepare\#19 prepare-latest-zh-cn prepare-zh-cn\#19
npm run start
.PHONY: clean
clean:
rm -rf .tmp
rm -rf node_modules
rm -rf docs
rm -rf versioned_docs/
rm -rf static/_*

View File

@@ -16,7 +16,7 @@ const config = {
i18n: {
defaultLocale: 'en',
locales: ['en'/*, 'fr-fr', 'zh-cn', 'zh-tw'*/], // temporarily disable other locales
locales: ['en'/*, 'zh-cn', 'fr-fr', 'zh-tw'*/], // temporarily disable other locales
},
presets: [
@@ -94,6 +94,10 @@ const config = {
type: 'search',
position: 'right',
},
{
type: 'localeDropdown',
position: 'right',
},
{
type: 'docsVersionDropdown',
position: 'right',

68
loop_docs-19-zh-cn.sh Normal file
View File

@@ -0,0 +1,68 @@
#!/bin/bash
set -xe
if sed --version 2>/dev/null | grep -q GNU; then
SED_INPLACE="sed -i"
else
SED_INPLACE="sed -i ''"
fi
$SED_INPLACE 's/</<&#8288;/' versioned_docs/version-1.19/zh-cn/installation/with-docker.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' versioned_docs/version-1.19/zh-cn/installation/with-docker.zh-cn.md
$SED_INPLACE 's/</<&#8288;/' versioned_docs/version-1.19/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/</&#8288;/' versioned_docs/version-1.19/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' versioned_docs/version-1.19/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' versioned_docs/version-1.19/zh-cn/administration/config-cheat-sheet.zh-cn.md
$SED_INPLACE 's/^url:.*//' versioned_docs/version-1.19/zh-cn/intro.md
$SED_INPLACE 's/^title:.*/displayed_sidebar: mySidebar/' versioned_docs/version-1.19/zh-cn/intro.md
$SED_INPLACE 's/^slug:.*/slug: \/zh-cn\//' versioned_docs/version-1.19/zh-cn/intro.md
$SED_INPLACE 's/.\/guidelines-frontend.md/.\/guidelines-frontend/' versioned_docs/version-1.19/zh-cn/development/hacking-on-gitea.zh-cn.md
$SED_INPLACE 's/"version":.*/"version":"1.19.0"/' static/19-swagger.json
for file in `find ./versioned_docs/version-1.19/zh-cn/ -name "*.md"`; do
# note only works on linux, forget about it when attempting to run on macos
# hide hugo toc
$SED_INPLACE 's/{{< toc >}}//' $file
$SED_INPLACE 's/{{< version >}}/1.19.0/g' $file
$SED_INPLACE 's/{{< relref "doc/\/docs/g' $file
$SED_INPLACE 's/" >}}//g' $file
$SED_INPLACE 's/\*\*Table of Contents\*\*//' $file
done
for file in `find ./versioned_docs/version-1.19/zh-cn/usage/ -name "*.md"`; do
# note only works on linux, forget about it when attempting to run on macos
# hide hugo toc
$SED_INPLACE 's/title:.*//' $file
done
for file in versioned_docs/version-1.19/zh-cn/*; do
if [ -d $file ]; then
continue
fi
if [ "$file" == "versioned_docs/version-1.19/zh-cn/intro.md" ]; then
continue
fi
rm $file
done
# for file in `find ./versioned_docs/version-1.19/zh-cn/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/zh-tw/docusaurus-plugin-content-docs/version-1.19/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/fr-fr/docusaurus-plugin-content-docs/version-1.19/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/zh-cn/docusaurus-plugin-content-docs/version-1.19/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done

70
loop_docs-zh-cn.sh Normal file
View File

@@ -0,0 +1,70 @@
#!/bin/bash
set -xe
if sed --version 2>/dev/null | grep -q GNU; then
SED_INPLACE="sed -i"
else
SED_INPLACE="sed -i ''"
fi
$SED_INPLACE 's/</<&#8288;/' docs/zh-cn/installation/with-docker.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' docs/zh-cn/installation/with-docker.zh-cn.md
$SED_INPLACE 's/</<&#8288;/' docs/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/</&#8288;/' docs/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' docs/zh-cn/contributing/guidelines-backend.zh-cn.md
$SED_INPLACE 's/<empty/<&#8288;empty/' docs/zh-cn/administration/config-cheat-sheet.zh-cn.md
$SED_INPLACE 's/^url:.*//' docs/zh-cn/intro.md
$SED_INPLACE 's/^title:.*/displayed_sidebar: mySidebar/' docs/zh-cn/intro.md
$SED_INPLACE 's/^slug:.*/slug: \/zh-cn\//' docs/zh-cn/intro.md
$SED_INPLACE 's/.\/guidelines-frontend.md/.\/guidelines-frontend/' docs/zh-cn/development/hacking-on-gitea.zh-cn.md
$SED_INPLACE 's/"version":.*/"version":"1.20-dev"/' static/latest-swagger.json
for file in `find ./docs/zh-cn/ -name "*.md"`; do
# note only works on linux, forget about it when attempting to run on macos
# hide hugo toc
$SED_INPLACE 's/{{< toc >}}//' $file
$SED_INPLACE 's/{{< version >}}/1.18.2/g' $file
$SED_INPLACE 's/{{< relref "doc/\/docs/g' $file
$SED_INPLACE 's/" >}}//g' $file
$SED_INPLACE 's/\*\*Table of Contents\*\*//' $file
done
for file in `find ./docs/zh-cn/usage/ -name "*.md"`; do
# note only works on linux, forget about it when attempting to run on macos
# hide hugo toc
$SED_INPLACE 's/title:.*//' $file
done
for file in docs/zh-cn/*; do
if [ -d $file ]; then
continue
fi
if [ "$file" == "docs/zh-cn/intro.md" ]; then
continue
fi
rm $file
done
# for file in `find ./docs/zh-cn/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/zh-tw/docusaurus-plugin-content-docs/zh-cn/current/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/fr-fr/docusaurus-plugin-content-docs/zh-cn/current/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done
# for file in `find ./i18n/zh-cn/docusaurus-plugin-content-docs/zh-cn/current/ -name "*.md"`; do
# trimmed=$(echo $file | cut -f 2 -d '.')
# mv $file .$trimmed.md
# done

View File

@@ -0,0 +1,79 @@
{
"mySidebar": [
{
"type": "link",
"label": "What is Gitea?",
"href": "/"
},
{
"type": "category",
"label": "Installation",
"items": [
{
"type": "autogenerated",
"dirName": "installation"
}
]
},
{
"type": "category",
"label": "Administration",
"items": [
{
"type": "autogenerated",
"dirName": "administration"
}
]
},
{
"type": "category",
"label": "Usage",
"items": [
{
"type": "category",
"label": "Packages",
"items": [
{
"type": "autogenerated",
"dirName": "packages"
}
]
},
{
"type": "autogenerated",
"dirName": "usage"
}
]
},
{
"type": "category",
"label": "Development",
"items": [
{
"type": "autogenerated",
"dirName": "development"
}
]
},
{
"type": "category",
"label": "Contributing",
"items": [
{
"type": "autogenerated",
"dirName": "contributing"
}
]
},
{
"type": "category",
"label": "Help",
"items": [
{
"type": "autogenerated",
"dirName": "help"
}
]
}
]
}

View File

@@ -0,0 +1,79 @@
{
"mySidebar": [
{
"type": "link",
"label": "What is Gitea?",
"href": "/"
},
{
"type": "category",
"label": "Installation",
"items": [
{
"type": "autogenerated",
"dirName": "installation"
}
]
},
{
"type": "category",
"label": "Administration",
"items": [
{
"type": "autogenerated",
"dirName": "administration"
}
]
},
{
"type": "category",
"label": "Usage",
"items": [
{
"type": "category",
"label": "Packages",
"items": [
{
"type": "autogenerated",
"dirName": "packages"
}
]
},
{
"type": "autogenerated",
"dirName": "usage"
}
]
},
{
"type": "category",
"label": "Development",
"items": [
{
"type": "autogenerated",
"dirName": "development"
}
]
},
{
"type": "category",
"label": "Contributing",
"items": [
{
"type": "autogenerated",
"dirName": "contributing"
}
]
},
{
"type": "category",
"label": "Help",
"items": [
{
"type": "autogenerated",
"dirName": "help"
}
]
}
]
}

View File

@@ -0,0 +1,79 @@
{
"mySidebar": [
{
"type": "link",
"label": "What is Gitea?",
"href": "/"
},
{
"type": "category",
"label": "Installation",
"items": [
{
"type": "autogenerated",
"dirName": "installation"
}
]
},
{
"type": "category",
"label": "Administration",
"items": [
{
"type": "autogenerated",
"dirName": "administration"
}
]
},
{
"type": "category",
"label": "Usage",
"items": [
{
"type": "category",
"label": "Packages",
"items": [
{
"type": "autogenerated",
"dirName": "packages"
}
]
},
{
"type": "autogenerated",
"dirName": "usage"
}
]
},
{
"type": "category",
"label": "Development",
"items": [
{
"type": "autogenerated",
"dirName": "development"
}
]
},
{
"type": "category",
"label": "Contributing",
"items": [
{
"type": "autogenerated",
"dirName": "contributing"
}
]
},
{
"type": "category",
"label": "Help",
"items": [
{
"type": "autogenerated",
"dirName": "help"
}
]
}
]
}