feat(inspirations): 灵感库 - 将内置英文提示词统一为中文 (#763)
* feat(inspirations): 灵感库 - 统一中文正文入口并校验译文版本 * feat(inspirations): 灵感库 - 发布完整中文提示词并阻止旧译文覆盖 统一 1319 条外部提示词和 329 条画廊引用,保留来源与模板参数;校验全部原文摘要,防止上游更新后误用过期中文。 验证:Bun 1.3.9 全量 2261 项测试通过,前端构建与 lint 通过,目录身份及媒体元数据对比无变化。
This commit is contained in:
1 parent
26dfb8d91b
commit
88de4ce422
12 files changed
+6673
-1705
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
/** 原文变更必须重新确认译文,不能只按 id 套用已过期的中文。 */
|
||||
export function localizeInspirationEntries(entries, translations) {
|
||||
return entries.map(({ promptZh, ...entry }) => {
|
||||
const translation = translations[entry.id];
|
||||
const sourceHash = createHash("sha256").update(entry.prompt).digest("hex");
|
||||
if (!translation || translation.sourceHash !== sourceHash) {
|
||||
throw new Error(`灵感缺少匹配当前原文的中文正文:${entry.id}。请更新 scripts/data/inspiration-prompts-zh.json 后再导入。`);
|
||||
}
|
||||
const prompt = translation.prompt?.trim();
|
||||
if (!prompt || !/[㐀-䶿一-鿿]/.test(prompt)) throw new Error(`灵感中文正文无效:${entry.id}`);
|
||||
return {
|
||||
...entry,
|
||||
...(translation?.title ? { title: translation.title } : {}),
|
||||
...(translation?.description ? { description: translation.description } : {}),
|
||||
prompt,
|
||||
};
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user