Skip to content

Commit ad65dc2

Browse files
Jinjiangposva
andauthored
refactor: replace translation scripts and ui with vitepress-translation-helper (#2109)
* refactor: replace translation scripts and ui with vitepress-translation-helper * chore: remove old translation scripts * chore: bump vitepress-translation-helper * chore: bump vitepress-translation-helper * Update index.ts --------- Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
1 parent 6a69696 commit ad65dc2

File tree

7 files changed

+137
-118
lines changed

7 files changed

+137
-118
lines changed

.github/contributing.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ If you want to start translating the docs in a _new_ language:
126126
1. Create the corresponding `<lang>` sub-folder for your translation.
127127
2. Modify the i18n configuration in the `.vitepress` sub-folder.
128128
3. Translate the docs and run the doc site to self-test locally.
129-
4. Create a checkpoint for your language by running `pnpm run docs:translation-status <lang> [<commit>]`. A checkpoint is the hash and date of the latest commit when you do the translation. The checkpoint information is stored in the status file `packages/docs/.vitepress/translation-status.json`. _It's crucial for long-term maintenance since all the further translation sync-ups are based on their previous checkpoints._ Usually, you can skip the commit argument because the default value is `main`.
129+
4. Create a checkpoint for your language by running `pnpm run docs:translation:update <lang> [<commit>]`. A checkpoint is the hash and date of the latest commit when you do the translation. The checkpoint information is stored in the status file `packages/docs/.vitepress/translation-status.json`. _It's crucial for long-term maintenance since all the further translation sync-ups are based on their previous checkpoints._ Usually, you can skip the commit argument because the default value is `main`.
130130
5. Commit all the changes and create a pull request to our GitHub repo.
131131

132132
We will have a paragraph at the top of each translation page that shows the translation status. That way, users can quickly determine if the translation is up-to-date or lags behind the English version.
@@ -135,9 +135,9 @@ Speaking of the up-to-date translation, we also need good long-term maintenance
135135

136136
1. See what translation you need to sync up with the original docs. There are two popular ways:
137137
1. Via the [GitHub Compare](https://github.com/vuejs/router/compare/) page, only see the changes in `packages/docs/*` from the checkpoint hash to `main` branch. You can find the checkpoint hash for your language via the translation status file `packages/docs/.vitepress/translation-status.json`. The compare page can be directly opened with the hash as part of the URL, e.g. https://github.com/vuejs/router/compare/e008551...main
138-
2. Via a local command: `pnpm run docs:compare-to-translate <lang> [<commit>]`.
138+
2. Via a local command: `pnpm run docs:translation:compare <lang> [<commit>]`.
139139
2. Create your own branch and start the translation update, following the previous comparison.
140-
3. Create a checkpoint for your language by running `pnpm run docs:translation-status <lang> [<commit>]`.
140+
3. Create a checkpoint for your language by running `pnpm run docs:translation:update <lang> [<commit>]`.
141141
4. Commit all the changes and create a pull request to our GitHub repo.
142142

143143
<!-- TODO: add an example once we have got one -->
@@ -149,18 +149,18 @@ You can also host the translation on your own. To create one, fork our GitHub re
149149
- Ensure you maintain the _checkpoint_ properly. Also, ensure the _translation status_ is well-displayed on the top of each translation page.
150150
- Utilize the diff result between the latest official repository and your own checkpoint to guide your translation.
151151

152-
Tip: you can add the official repo as a remote to your forked repo. This way, you can still run `pnpm run docs:translation-status <lang> [<commit>]` and `npm run docs:compare-to-translate <lang> [<commit>]` to get the checkpoint and diff result:
152+
Tip: you can add the official repo as a remote to your forked repo. This way, you can still run `pnpm run docs:translation:update <lang> [<commit>]` and `npm run docs:translation:compare <lang> [<commit>]` to get the checkpoint and diff result:
153153

154154
```bash
155155
# prepare the upstream remote
156156
git remote add upstream git@github.com:vuejs/router.git
157157
git fetch upstream main
158158

159159
# set the checkpoint
160-
pnpm run docs:translation-status <lang> upstream/main
160+
pnpm run docs:translation:update <lang> upstream/main
161161

162162
# get the diff result
163-
pnpm run docs:compare-to-translate <lang> upstream/main
163+
pnpm run docs:translation:compare <lang> upstream/main
164164
```
165165

166166
<!-- TODO: add an example once we have got one -->

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"build:dts": "pnpm run -r build:dts",
1616
"docs": "pnpm run --filter ./packages/docs -r docs",
1717
"docs:api": "pnpm run --filter ./packages/docs -r docs:api",
18-
"docs:compare-to-translate": "pnpm run --filter ./packages/docs -r docs:compare-to-translate",
19-
"docs:translation-status": "pnpm run --filter ./packages/docs -r docs:translation-status",
18+
"docs:translation:compare": "pnpm run --filter ./packages/docs -r docs:translation:compare",
19+
"docs:translation:update": "pnpm run --filter ./packages/docs -r docs:translation:update",
20+
"docs:translation:status": "pnpm run --filter ./packages/docs -r docs:translation:status",
2021
"docs:build": "pnpm run docs:api && pnpm run --filter ./packages/docs -r docs:build",
2122
"docs:preview": "pnpm run --filter ./packages/docs -r docs:preview",
2223
"play": "pnpm run -r play",

packages/docs/.vitepress/theme/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ import { Theme } from 'vitepress'
33
import DefaultTheme from 'vitepress/theme'
44
import AsideSponsors from './components/AsideSponsors.vue'
55
// import HomeSponsors from './components/HomeSponsors.vue'
6-
import TranslationStatus from './components/TranslationStatus.vue'
6+
import TranslationStatus from 'vitepress-translation-helper/ui/TranslationStatus.vue'
77
import './styles/vars.css'
88
import './styles/sponsors.css'
99
import VueSchoolLink from './components/VueSchoolLink.vue'
1010
import VueMasteryLogoLink from './components/VueMasteryLogoLink.vue'
11+
import status from '../translation-status.json'
12+
13+
const i18nLabels = {
14+
zh: '该翻译已同步到了 ${date} 的版本,其对应的 commit hash 是 <code>${hash}</code>。',
15+
}
1116

1217
const theme: Theme = {
1318
...DefaultTheme,
1419
Layout() {
1520
return h(DefaultTheme.Layout, null, {
1621
// 'home-features-after': () => h(HomeSponsors),
1722
'aside-ads-before': () => h(AsideSponsors),
18-
'doc-before': () => h(TranslationStatus),
23+
'doc-before': () => h(TranslationStatus, { status, i18nLabels }),
1924
})
2025
},
2126

packages/docs/compare-to-translate.mjs

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/docs/generate-translation-status.mjs

Lines changed: 0 additions & 60 deletions
This file was deleted.

packages/docs/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
"scripts": {
77
"docs": "vitepress dev .",
88
"docs:api": "node run-typedoc.mjs",
9-
"docs:compare-to-translate": "node compare-to-translate.mjs",
10-
"docs:translation-status": "node generate-translation-status.mjs",
9+
"docs:translation:compare": "v-translation compare",
10+
"docs:translation:update": "v-translation update",
11+
"docs:translation:status": "v-translation status",
1112
"docs:build": "vitepress build .",
1213
"docs:preview": "vitepress preview ."
1314
},
1415
"dependencies": {
1516
"simple-git": "^3.18.0",
1617
"vitepress": "1.0.0-rc.35",
18+
"vitepress-translation-helper": "^0.1.3",
1719
"vue-router": "workspace:*"
1820
}
1921
}

0 commit comments

Comments
 (0)