@alauda/doom 0.14.10 → 0.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli/index.js +3 -1
- package/lib/cli/translate.js +10 -9
- package/package.json +5 -5
package/lib/cli/index.js
CHANGED
|
@@ -30,7 +30,9 @@ program
|
|
|
30
30
|
.option('-v <version>', 'Specify the version of the documentation')
|
|
31
31
|
.option('-b, --base <base>', 'Override the base of the documentation')
|
|
32
32
|
.option('-p, --prefix <prefix>', 'Specify the prefix of the documentation base')
|
|
33
|
-
.option('-f, --force [boolean]',
|
|
33
|
+
.option('-f, --force [boolean]', `Force to
|
|
34
|
+
1. fetch latest reference remotes or scaffolding templates, otherwise use local cache
|
|
35
|
+
2. translate ignore hash equality check and original text`, (value) => !!value && value !== 'false', false)
|
|
34
36
|
.option('-i, --ignore [boolean]', 'Ignore internal routes', (value) => !!value && value !== 'false', false)
|
|
35
37
|
.option('-d, --download [boolean]', 'Display download pdf link on nav bar', (value) => !!value && value !== 'false', false)
|
|
36
38
|
.command('dev', { isDefault: true })
|
package/lib/cli/translate.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { removeLeadingSlash } from '@rspress/shared';
|
|
4
5
|
import { logger } from '@rspress/shared/logger';
|
|
5
6
|
import { Command } from 'commander';
|
|
6
7
|
import { render } from 'ejs';
|
|
@@ -22,7 +23,7 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
22
23
|
你是一位专业的技术文档工程师,擅长写作高质量的<%= targetLang %>技术分档。请你帮我准确地将以下<%= sourceLang %>翻译成<%= targetLang %>,风格与<%= targetLang %>技术文档保持一致。
|
|
23
24
|
|
|
24
25
|
## 规则
|
|
25
|
-
- 第一条消息为需要翻译的最新<%= sourceLang
|
|
26
|
+
- 第一条消息为需要翻译的最新<%= sourceLang %>文档,第二条消息为之前翻译过的但内容可能过期的<%= targetLang %>文档,如果没有翻译过则为空
|
|
26
27
|
- 输入格式为 MDX 格式,输出格式也必须保留原始 MDX 格式,且不要额外包装在不必要的代码块中
|
|
27
28
|
- 文档中的资源链接不要翻译和替换
|
|
28
29
|
- MDX 组件中包含的内容需要翻译,MDX 组件参数的值不需要翻译,但以下这些特殊的 MDX 组件参数值需要翻译
|
|
@@ -34,14 +35,14 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
34
35
|
- 翻译过程中务必保留原文中的 \\< 转义字符不要做任何转义变更
|
|
35
36
|
|
|
36
37
|
## 策略
|
|
37
|
-
|
|
38
|
-
1. 根据<%= sourceLang
|
|
39
|
-
2.
|
|
38
|
+
分四步进行翻译工作:
|
|
39
|
+
1. 根据<%= sourceLang %>文档直译成<%= targetLang %>,保持原有格式,不要遗漏任何信息
|
|
40
|
+
2. 根据第一步直译的结果,指出其中存在的具体问题,要准确描述,不宜笼统的表示,也不要增加原文不存在的内容或格式,包括不仅限于
|
|
40
41
|
- 不符合<%= targetLang %>表达习惯,明确指出不符合的地方
|
|
41
42
|
- 语句不通顺,指出位置,不需要给出修改意见,意译时修复
|
|
42
43
|
- 晦涩难懂,模棱两可,不易理解,可以尝试给出解释
|
|
43
44
|
3. 根据第一步直译的结果和第二步指出的问题,重新进行意译,保证内容的原意的基础上,使其更易于理解,更符合<%= targetLang %>技术文档的表达习惯,同时保持原有的格式不变
|
|
44
|
-
4.
|
|
45
|
+
4. 当存在之前翻译过的<%= targetLang %>文档时,将第三步的结果分段与之前的<%= targetLang %>文档细致地比较,不要遗漏任何新的分段(包括文本、资源链接等),如果分段内翻译结果意思相近,仅仅表达方式不同的,且没有新增任何内容时,则该分段只需要保持之前翻译过的内容即可,不需要重复翻译
|
|
45
46
|
|
|
46
47
|
最终只需要输出最后一步的结果,不需要输出之前步骤的结果。
|
|
47
48
|
|
|
@@ -95,7 +96,7 @@ export const translateCommand = new Command('translate')
|
|
|
95
96
|
.requiredOption('-g, --glob <path...>', 'Glob patterns for source dirs/files')
|
|
96
97
|
.option('-C, --copy [boolean]', 'Wether to copy relative assets to the target directory instead of following links', (value) => !!value && value !== 'false', false)
|
|
97
98
|
.action(async function (root) {
|
|
98
|
-
const { source, target, glob: globs, copy, ...globalOptions } = this.optsWithGlobals();
|
|
99
|
+
const { source, target, glob: globs, copy, force, ...globalOptions } = this.optsWithGlobals();
|
|
99
100
|
if (!Object.hasOwn(LANGUAGE_CODES, source) ||
|
|
100
101
|
!Object.hasOwn(LANGUAGE_CODES, target) ||
|
|
101
102
|
source === target) {
|
|
@@ -112,7 +113,7 @@ export const translateCommand = new Command('translate')
|
|
|
112
113
|
process.exitCode = 1;
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
|
-
const matched = await glob(globs, {
|
|
116
|
+
const matched = await glob(globs.map(removeLeadingSlash), {
|
|
116
117
|
absolute: true,
|
|
117
118
|
cwd: sourceDir,
|
|
118
119
|
onlyFiles: false,
|
|
@@ -147,7 +148,7 @@ export const translateCommand = new Command('translate')
|
|
|
147
148
|
targetContent = await fs.readFile(targetFilePath, 'utf-8');
|
|
148
149
|
targetFrontmatter = matter(targetContent).data;
|
|
149
150
|
if (targetFrontmatter.i18n?.disableAutoTranslation ||
|
|
150
|
-
targetFrontmatter.sourceSHA === sourceSHA) {
|
|
151
|
+
(!force && targetFrontmatter.sourceSHA === sourceSHA)) {
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
153
154
|
}
|
|
@@ -171,7 +172,7 @@ export const translateCommand = new Command('translate')
|
|
|
171
172
|
children: ast.children.map((it) => normalizeImgSrc(it, normalizeImgSrcOptions)),
|
|
172
173
|
}),
|
|
173
174
|
target,
|
|
174
|
-
targetContent,
|
|
175
|
+
targetContent: force ? '' : targetContent,
|
|
175
176
|
additionalPrompts: targetFrontmatter?.i18n?.additionalPrompts ??
|
|
176
177
|
sourceFrontmatter.i18n?.additionalPrompts,
|
|
177
178
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@inquirer/prompts": "^7.3.3",
|
|
47
47
|
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
48
|
-
"@playwright/browser-chromium": "^1.
|
|
49
|
-
"@rspress/core": "1.43.
|
|
48
|
+
"@playwright/browser-chromium": "^1.51.0",
|
|
49
|
+
"@rspress/core": "1.43.2",
|
|
50
50
|
"@shikijs/transformers": "^3.1.0",
|
|
51
51
|
"chokidar": "^4.0.3",
|
|
52
52
|
"cli-progress": "^3.12.0",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"pdf-lib": "^1.17.1",
|
|
64
64
|
"pdf-merger-js": "^5.1.2",
|
|
65
65
|
"picomatch": "^4.0.2",
|
|
66
|
-
"playwright": "^1.
|
|
66
|
+
"playwright": "^1.51.0",
|
|
67
67
|
"react-markdown": "^8.0.7",
|
|
68
68
|
"rehype-raw": "^6.1.1",
|
|
69
69
|
"remark-directive": "^2.0.1",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"prettier-plugin-pkg": "^0.18.1",
|
|
98
98
|
"simple-git-hooks": "^2.11.1",
|
|
99
99
|
"typescript": "^5.8.2",
|
|
100
|
-
"typescript-eslint": "^8.26.
|
|
100
|
+
"typescript-eslint": "^8.26.1"
|
|
101
101
|
},
|
|
102
102
|
"publishConfig": {
|
|
103
103
|
"access": "public"
|