Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,274 additions
and
1,184 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/docs/.vitepress/theme/components/TranslationStatus.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<div> | ||
<div v-if="label" class="translation_status"> | ||
{{ label }} | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import status from '../../translation-status.json' | ||
const i18nLabels: { | ||
[lang: string]: string | ||
} = { | ||
// An example of the English label: | ||
// 'root': 'The translation is synced to the docs on ${date} of which the commit hash is ${hash}.', | ||
'zh': '该翻译已同步到了 ${date} 的版本,其对应的 commit hash 是 ${hash}。', | ||
} | ||
</script> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { useData } from 'vitepress' | ||
const { site } = useData() | ||
const label = computed(() => { | ||
const localeIndex = site.value.localeIndex | ||
const { date, hash } = status[localeIndex] || { date: '', hash: '' } | ||
return (i18nLabels[localeIndex] || '') | ||
.replace('${date}', date) | ||
.replace('${hash}', hash) | ||
} | ||
) | ||
</script> | ||
|
||
<style scoped> | ||
.translation_status { | ||
padding: 1em 1.25em; | ||
font-size: small; | ||
text-align: right; | ||
color: var(--vp-c-text-2); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"zh": { | ||
"hash": "1a3a28f", | ||
"date": "2023-04-03" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const fs = require('fs') | ||
const simpleGit = require('simple-git') | ||
|
||
// Customize the checkpoint for your translation | ||
const locales = { | ||
zh: 'docs-sync-zh' | ||
} | ||
|
||
const getInfo = async (checkpoint) => { | ||
return new Promise((resolve, reject) => { | ||
const git = simpleGit() | ||
git.log(['-n', '1', '--pretty=format:"%H %cd"', '--date=short', 'origin/' + checkpoint || 'main'], (err, log) => { | ||
if (err) { | ||
reject(err) | ||
return | ||
} | ||
const [hash, date] = log.latest.hash.replace(/"/g, '').split(' ') | ||
resolve({ | ||
hash: hash.slice(0, 7), | ||
date | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
const main = async () => { | ||
const result = {} | ||
for (const lang in locales) { | ||
const checkpoint = locales[lang] | ||
result[lang] = await getInfo(checkpoint) | ||
} | ||
fs.writeFileSync('./.vitepress/translation-status.json', JSON.stringify(result, null, 2)) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.