Skip to content

Commit e1ef1a6

Browse files
feat: use English for all texts
1 parent ee79648 commit e1ef1a6

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

migrate/migrate-bot.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ ${html}
221221
console.log(`Normal HTML elements count: ${normalElementsCount}`);
222222

223223
if (normalElementsCount > 4) {
224-
throw new Error("生成的内容中包含过多原生HTML元素,可能转换失败。");
224+
throw new Error("The generated content contains too many native HTML elements, conversion may have failed.");
225225
}
226226

227227
return content;
@@ -231,7 +231,7 @@ ${html}
231231
function getRelativeMDXPath(url: string): string {
232232
const match = url.match(/https?:\/\/.*?cppreference\.com\/w\/(.+)\.html$/);
233233
if (!match) {
234-
throw new Error(`无法从URL解析路径: ${url}`);
234+
throw new Error(`Unable to parse path from URL: ${url}`);
235235
}
236236
const relative = match[1]; // "cpp/comments"
237237
return `src/content/docs/${relative}.mdx`;
@@ -240,7 +240,7 @@ function getRelativeMDXPath(url: string): string {
240240
function getRelativeHTMLPath(url: string): string {
241241
const match = url.match(/https?:\/\/.*?cppreference\.com\/w\/(.+)\.html$/);
242242
if (!match) {
243-
throw new Error(`无法从URL解析路径: ${url}`);
243+
throw new Error(`Unable to parse path from URL: ${url}`);
244244
}
245245
const relative = match[1]; // "cpp/comments"
246246
return `dist/${relative}/index.html`;
@@ -262,7 +262,7 @@ title: ${JSON.stringify(title)}
262262
description: Auto‑generated from cppreference
263263
---\n\n`;
264264
await fs.writeFile(filePath, frontmatter + content, "utf8");
265-
console.log(`写入 ${filePath}`);
265+
console.log(`Written to ${filePath}`);
266266
}
267267

268268
// curl --location --request POST "https://api.imgbb.com/1/upload?expiration=600&key=YOUR_CLIENT_API_KEY" --form "image=R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"
@@ -324,18 +324,18 @@ async function createPullRequest(
324324
const webp = visualizeTextDiff(originalInnerText, newInnerText);
325325
if (webp) {
326326
imageUrl = await uploadImageToImgBB(webp);
327-
console.log(`上传文本差异图像到 ImgBB: ${imageUrl}`);
327+
console.log(`Uploaded text diff image to ImgBB: ${imageUrl}`);
328328
}
329329
}
330330

331-
const prBody = `> ${MODEL_NAME} ${url} 自动迁移
331+
const prBody = `> Automatically migrated from ${url} by ${MODEL_NAME}
332332
>
333-
> 📝 [编辑此页面](https://github.com/cppdoc-cc/cppdoc/edit/${branchName}/${getRelativeMDXPath(url)})
333+
> 📝 [Edit this page](https://github.com/cppdoc-cc/cppdoc/edit/${branchName}/${getRelativeMDXPath(url)})
334334
335335
<small>Close #${issue.number}</small>
336336
337-
${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
338-
<small>绿色:迁移后词汇出现次数大于迁移前;红色:迁移后词汇出现次数小于迁移前。</small>
337+
${imageUrl ? `![Text Diff](${imageUrl})` : "(No text diff image)"}
338+
<small>Green: word count increased after migration; Red: word count decreased after migration.</small>
339339
`;
340340

341341
const { execSync } = await import("child_process");
@@ -350,7 +350,7 @@ ${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
350350
execSync(`git push origin ${branchName}`);
351351
} catch (error) {
352352
console.error(
353-
"Git操作失败:",
353+
"Git operation failed:",
354354
error instanceof Error ? error.message : String(error)
355355
);
356356
throw error;
@@ -365,7 +365,7 @@ ${imageUrl ? `![Text Diff](${imageUrl})` : "(无文本差异图像)"}
365365
base: "main",
366366
});
367367

368-
console.log(`创建PR #${pr.number}`);
368+
console.log(`Created PR #${pr.number}`);
369369
return pr.number;
370370
}
371371

@@ -388,7 +388,7 @@ async function updateIssue(
388388
owner: REPO_OWNER,
389389
repo: REPO_NAME,
390390
issue_number: issue.number,
391-
body: `迁移失败: ${message}\n\n已关闭issue。`,
391+
body: `Migration failed: ${message}\n\nIssue closed.`,
392392
});
393393
await octokit.issues.update({
394394
owner: REPO_OWNER,
@@ -401,13 +401,13 @@ async function updateIssue(
401401
owner: REPO_OWNER,
402402
repo: REPO_NAME,
403403
issue_number: issue.number,
404-
body: `迁移完成!已创建PR [#${prNumber}].`,
404+
body: `Migration completed! Created PR [#${prNumber}].`,
405405
});
406406
}
407407
}
408408

409409
async function main() {
410-
console.log("获取带有标签", LABEL, "的issue...");
410+
console.log("Fetching issues with label", LABEL, "...");
411411
const { data: issues } = await octokit.issues.listForRepo({
412412
owner: REPO_OWNER,
413413
repo: REPO_NAME,
@@ -416,48 +416,48 @@ async function main() {
416416
per_page: 50,
417417
});
418418

419-
console.log(`找到 ${issues.length} 个issue`);
419+
console.log(`Found ${issues.length} issues`);
420420

421421
for (const issue of issues) {
422-
console.log(`处理issue #${issue.number}: ${issue.title}`);
422+
console.log(`Processing issue #${issue.number}: ${issue.title}`);
423423
try {
424424
if (hasPRReference(issue.title)) {
425425
continue;
426426
}
427427

428428
const url = extractLink(issue.title);
429429
if (!url) {
430-
throw new Error("标题中未找到有效的cppreference链接");
430+
throw new Error("No valid cppreference link found in title");
431431
}
432432

433-
console.log(` 获取 ${url}`);
433+
console.log(` Fetching ${url}`);
434434
const { html, title, innerText } = await retry(
435435
() => fetchPageContent(url),
436436
3,
437437
2000
438438
);
439439

440-
console.log(` 转换HTML为MDX...`);
440+
console.log(` Converting HTML to MDX...`);
441441
const mdx = await retry(() => convertToMDX(html, title, url), 3, 2000);
442442

443443
const filePath = getLocalMDXPath(url);
444-
console.log(` 写入 ${filePath}`);
444+
console.log(` Writing to ${filePath}`);
445445
await writeMDXFile(filePath, mdx, title);
446446

447-
console.log(` 重新格式化...`);
447+
console.log(` Re-formatting...`);
448448
spawnSync(`npm`, ["run", "format"], {
449449
stdio: "inherit",
450450
shell: true,
451451
});
452452

453-
console.log(` 构建...`);
453+
console.log(` Building...`);
454454
const res = spawnSync(`npm`, ["run", "build"], {
455455
stdio: "inherit",
456456
shell: true,
457457
});
458458
if (res.status !== 0) {
459459
throw new Error(
460-
"构建失败,可能生成的MDX有问题:" +
460+
"Build failed, possibly due to issues with the generated MDX:" +
461461
res.stderr?.toString() +
462462
res.stdout?.toString() +
463463
res.error?.toString() +
@@ -466,20 +466,20 @@ async function main() {
466466
);
467467
}
468468

469-
console.log(` 创建PR...`);
469+
console.log(` Creating PR...`);
470470
const prNumber = await createPullRequest(issue, filePath, url, innerText);
471471

472-
console.log(` 更新issue...`);
472+
console.log(` Updating issue...`);
473473
await updateIssue(issue, prNumber);
474474

475-
console.log(` issue #${issue.number} 完成`);
475+
console.log(` Issue #${issue.number} completed`);
476476
} catch (error) {
477-
console.error(` issue #${issue.number} 出错:`, error);
477+
console.error(` Issue #${issue.number} error:`, error);
478478
await updateIssue(issue, null, error);
479479
}
480480
}
481481

482-
console.log("全部完成");
482+
console.log("All completed");
483483
}
484484

485485
main().catch((err) => {

0 commit comments

Comments
 (0)