translation-brief.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /**
  2. * Pure assembly of the minimal-update briefing for one out-of-sync
  3. * translation pair: the authored side's changes since the last confirmed
  4. * state at the narrowest safely mapped granularity (code-fence-only splice,
  5. * changed Markdown units, heading sections, whole document), the terminology
  6. * rows those changes touch, first-occurrence movement notes, and a digest of
  7. * the binding update rules. The unit mapping, mechanical code splice, and
  8. * first-occurrence tracking adopt the planner mechanics validated in the
  9. * incremental-pipeline work (PR #684). The CLI wrapper is
  10. * `scripts/gen-translation-brief.ts`; the workflow that consumes the
  11. * briefing is `.agents/skills/dsh-translate-docs/SKILL.md`.
  12. */
  13. import type { Nodes } from 'mdast'
  14. import { parseTranslationMarkdown } from './translation-pairing.ts'
  15. /** One block-level span of a Markdown document, in document order. */
  16. export interface MarkdownSpan {
  17. /** Position in the span list; briefing ids derive from it. */
  18. index: number
  19. /**
  20. * Structural kind compared for alignment, language-neutral: container path
  21. * plus node type for units (`root.3:tableRow`), depth for sections (`section:2`).
  22. */
  23. kind: string
  24. /** Reader-facing label: heading text for sections, node type for units. */
  25. label: string
  26. /** 1-based first source line. */
  27. startLine: number
  28. /** 1-based last source line. */
  29. endLine: number
  30. /** The span's text, trailing newline normalized to exactly one. */
  31. text: string
  32. }
  33. function linesOf(markdown: string): string[] {
  34. const lines = markdown.replaceAll('\r\n', '\n').split('\n')
  35. if (lines.at(-1) === '') lines.pop()
  36. return lines
  37. }
  38. function sliceLines(lines: string[], startLine: number, endLine: number): string {
  39. return `${lines.slice(startLine - 1, endLine).join('\n')}\n`
  40. }
  41. /**
  42. * List a document's translation units: the outermost block nodes a minimal
  43. * update can replace independently. Headings, paragraphs, code fences, table
  44. * rows, list items, block quotes, HTML blocks, thematic breaks, and link
  45. * definitions are units; the container path is part of the kind so kind
  46. * sequences only align when container membership also aligns.
  47. *
  48. * @param markdown - Document text.
  49. * @returns Units in document order.
  50. */
  51. export function markdownUnits(markdown: string): MarkdownSpan[] {
  52. const positions: Array<{ kind: string; label: string; startLine: number; endLine: number }> = []
  53. const visit = (node: Nodes, path: string): void => {
  54. let kind: string | undefined
  55. switch (node.type) {
  56. case 'heading':
  57. kind = `${path}:heading:${node.depth}`
  58. break
  59. case 'paragraph':
  60. case 'code':
  61. case 'tableRow':
  62. case 'listItem':
  63. case 'blockquote':
  64. case 'html':
  65. case 'thematicBreak':
  66. case 'definition':
  67. kind = `${path}:${node.type}`
  68. break
  69. default:
  70. break
  71. }
  72. if (kind !== undefined && node.position !== undefined) {
  73. positions.push({ kind, label: node.type, startLine: node.position.start.line, endLine: node.position.end.line })
  74. return
  75. }
  76. if ('children' in node) for (const [index, child] of node.children.entries()) visit(child, `${path}.${index}`)
  77. }
  78. visit(parseTranslationMarkdown(markdown), 'root')
  79. positions.sort((left, right) => left.startLine - right.startLine)
  80. const lines = linesOf(markdown)
  81. return positions.map((position, index) => ({
  82. index,
  83. ...position,
  84. text: sliceLines(lines, position.startLine, position.endLine),
  85. }))
  86. }
  87. /**
  88. * List a document's heading-delimited sections, including a leading
  89. * `preamble` span when content precedes the first heading.
  90. *
  91. * @param markdown - Document text.
  92. * @returns Sections in document order.
  93. */
  94. export function sectionSpans(markdown: string): MarkdownSpan[] {
  95. const headings: Array<{ depth: number; line: number; label: string }> = []
  96. const visit = (node: Nodes): void => {
  97. if (node.type === 'heading' && node.position !== undefined) {
  98. let label = ''
  99. const collect = (child: Nodes): void => {
  100. if ('value' in child && typeof child.value === 'string') label += child.value
  101. if ('children' in child) for (const grandchild of child.children) collect(grandchild)
  102. }
  103. for (const child of node.children) collect(child)
  104. headings.push({ depth: node.depth, line: node.position.start.line, label })
  105. }
  106. if ('children' in node) for (const child of node.children) visit(child)
  107. }
  108. visit(parseTranslationMarkdown(markdown))
  109. headings.sort((left, right) => left.line - right.line)
  110. const lines = linesOf(markdown)
  111. const spans: MarkdownSpan[] = []
  112. const firstHeadingLine = headings[0]?.line ?? lines.length + 1
  113. if (firstHeadingLine > 1) {
  114. spans.push({ index: 0, kind: 'preamble', label: '(preamble before the first heading)', startLine: 1, endLine: firstHeadingLine - 1, text: sliceLines(lines, 1, firstHeadingLine - 1) })
  115. }
  116. for (const [order, heading] of headings.entries()) {
  117. const endLine = (headings[order + 1]?.line ?? lines.length + 1) - 1
  118. spans.push({
  119. index: spans.length,
  120. // Depth only: heading TEXT is translated across a pair, so it cannot
  121. // participate in cross-language alignment.
  122. kind: `section:${heading.depth}`,
  123. label: heading.label === '' ? '(untitled section)' : heading.label,
  124. startLine: heading.line,
  125. endLine,
  126. text: sliceLines(lines, heading.line, endLine),
  127. })
  128. }
  129. return spans
  130. }
  131. /**
  132. * Whether two span lists map one to one: same non-zero length and the same
  133. * kind at every position.
  134. *
  135. * @param left - One document's spans.
  136. * @param right - The other document's spans.
  137. * @returns True when index-wise mapping is sound.
  138. */
  139. export function spansAligned(left: MarkdownSpan[], right: MarkdownSpan[]): boolean {
  140. return left.length > 0
  141. && left.length === right.length
  142. && left.every((span, index) => span.kind === right[index]?.kind)
  143. }
  144. /**
  145. * Indices whose text differs between two aligned span lists.
  146. *
  147. * @param before - Spans of the earlier state.
  148. * @param after - Spans of the later state, aligned with `before`.
  149. * @returns Ascending changed indices.
  150. */
  151. export function changedSpanIndices(before: MarkdownSpan[], after: MarkdownSpan[]): number[] {
  152. return before.filter((span, index) => span.text !== after[index]?.text).map(span => span.index)
  153. }
  154. function codeSpansOf(markdown: string): MarkdownSpan[] {
  155. return markdownUnits(markdown).filter(span => span.kind.endsWith(':code'))
  156. .map((span, index) => ({ ...span, index }))
  157. }
  158. function replaceSpanTexts(markdown: string, spans: MarkdownSpan[], replacements: Map<number, string>): string {
  159. const lines = linesOf(markdown)
  160. for (const [index, replacement] of [...replacements.entries()].sort((left, right) => right[0] - left[0])) {
  161. const span = spans[index]
  162. if (span === undefined) throw new Error(`translation brief: unknown replacement span ${index}`)
  163. lines.splice(span.startLine - 1, span.endLine - span.startLine + 1, ...linesOf(replacement))
  164. }
  165. return `${lines.join('\n')}\n`
  166. }
  167. function maskCodeSpans(markdown: string, spans: MarkdownSpan[]): string {
  168. return replaceSpanTexts(markdown, spans, new Map(spans.map(span => [span.index, `DSH_TRANSLATION_CODE_${span.index}\n`])))
  169. }
  170. /**
  171. * Compute the counterpart update for a change confined to fenced code
  172. * blocks. Fences are byte-identical across a pair, so when the source's
  173. * prose is untouched and the counterpart's fences match the last-confirmed
  174. * source, splicing the edited fences into the counterpart is the complete
  175. * update — no translation judgment is involved.
  176. *
  177. * @param confirmedSource - The changed side's last-confirmed text.
  178. * @param currentSource - The changed side's current text.
  179. * @param counterpart - The other side's current text.
  180. * @returns The updated counterpart, or undefined when the change is not code-only.
  181. */
  182. export function computeMechanicalUpdate(confirmedSource: string, currentSource: string, counterpart: string): string | undefined {
  183. const confirmed = codeSpansOf(confirmedSource)
  184. const current = codeSpansOf(currentSource)
  185. const target = codeSpansOf(counterpart)
  186. if (confirmed.length === 0 || confirmed.length !== current.length || confirmed.length !== target.length) return undefined
  187. if (maskCodeSpans(confirmedSource, confirmed) !== maskCodeSpans(currentSource, current)) return undefined
  188. if (confirmed.some((span, index) => span.text !== target[index]?.text)) return undefined
  189. const changed = current.filter((span, index) => span.text !== confirmed[index]?.text)
  190. if (changed.length === 0) return undefined
  191. return replaceSpanTexts(counterpart, target, new Map(changed.map(span => [span.index, span.text])))
  192. }
  193. /** One parsed terminology-table data row. */
  194. export interface TerminologyRow {
  195. english: string
  196. chinese: string
  197. /** The 首次出现 cell (first-occurrence rendering), possibly empty. */
  198. first: string
  199. /** The verbatim table row. */
  200. line: string
  201. }
  202. /** Strip Markdown emphasis and code markers from a terminology cell. */
  203. function plainTerm(cell: string): string {
  204. return cell.replaceAll('`', '').replaceAll('**', '').trim()
  205. }
  206. /**
  207. * Parse the data rows of the terminology table.
  208. *
  209. * @param terminology - Full `docs/i18n/terminology.md` contents.
  210. * @returns Rows in table order.
  211. */
  212. export function parseTerminologyRows(terminology: string): TerminologyRow[] {
  213. const rows: TerminologyRow[] = []
  214. for (const line of terminology.split('\n')) {
  215. if (!line.startsWith('|')) continue
  216. if (/^\|[\s:|-]+\|$/.test(line)) continue
  217. const cells = line.split('|').map(cell => cell.trim())
  218. const english = plainTerm(cells[1] ?? '')
  219. if (english === '' || english === 'English') continue
  220. rows.push({ english, chinese: plainTerm(cells[2] ?? ''), first: plainTerm(cells[3] ?? ''), line })
  221. }
  222. return rows
  223. }
  224. /**
  225. * Character offsets of a term's occurrences. English word-like terms match
  226. * on word boundaries and accept plural inflections (`agents`, `registries`);
  227. * other terms match as case-insensitive substrings.
  228. *
  229. * @param text - Text to search.
  230. * @param term - The term to find.
  231. * @param englishInflections - Whether to accept English plural forms.
  232. * @returns Ascending match offsets.
  233. */
  234. export function termOffsets(text: string, term: string, englishInflections = false): number[] {
  235. if (term === '') return []
  236. const escape = (value: string): string => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
  237. const wordLike = /^[A-Za-z0-9][A-Za-z0-9 ._-]*[A-Za-z0-9]$/.test(term)
  238. const inflected = englishInflections && wordLike
  239. ? /[^aeiou]y$/i.test(term)
  240. ? `${escape(term.slice(0, -1))}(?:y|ies)`
  241. : `${escape(term)}(?:s|es)?`
  242. : escape(term)
  243. const expression = new RegExp(wordLike ? `(?<![A-Za-z0-9_])${inflected}(?![A-Za-z0-9_])` : inflected, 'gi')
  244. return [...text.matchAll(expression)].map(match => match.index)
  245. }
  246. /** The two update directions a pair supports. */
  247. export type BriefDirection = 'en-to-zh' | 'zh-to-en'
  248. /** Whether a row's source-language term occurs in the given text. */
  249. function rowOccurs(row: TerminologyRow, direction: BriefDirection, text: string): boolean {
  250. const terms = direction === 'en-to-zh' ? [row.english] : [row.first, row.chinese].filter(term => /[一-鿿]/.test(term))
  251. return terms.some(term => termOffsets(text, term, direction === 'en-to-zh').length > 0)
  252. }
  253. /**
  254. * Select the terminology rows whose source-language term occurs in the
  255. * changed text (old and new states combined).
  256. *
  257. * @param terminology - Full `docs/i18n/terminology.md` contents.
  258. * @param direction - Update direction; decides which columns to match.
  259. * @param changedText - Concatenated old and new text of the changed spans.
  260. * @returns Matched rows in table order.
  261. */
  262. export function relevantTerminologyRows(terminology: string, direction: BriefDirection, changedText: string): TerminologyRow[] {
  263. return parseTerminologyRows(terminology).filter(row => rowOccurs(row, direction, changedText))
  264. }
  265. function lineAtOffset(text: string, offset: number): number {
  266. return text.slice(0, offset).split('\n').length
  267. }
  268. function spanIndexAtOffset(text: string, spans: MarkdownSpan[], offset: number | undefined): number | undefined {
  269. if (offset === undefined) return undefined
  270. const line = lineAtOffset(text, offset)
  271. return spans.find(span => line >= span.startLine && line <= span.endLine)?.index
  272. }
  273. /** First-occurrence guidance computed for a Chinese-target update. */
  274. export interface FirstOccurrenceContext {
  275. /** Human-readable notes for the briefing. */
  276. notes: string[]
  277. /** Unchanged span indices that must join the briefing because a first occurrence moved into or out of them. */
  278. extraSpanIndices: number[]
  279. }
  280. /**
  281. * Track document-wide first occurrences of the relevant English terms. The
  282. * 首次出现 rendering attaches to a term's first occurrence, so when an edit
  283. * moves that occurrence across spans, both the old and new spans need
  284. * counterpart edits even when only one of them changed.
  285. *
  286. * @param confirmedSource - Last-confirmed English text.
  287. * @param currentSource - Current English text.
  288. * @param confirmedSpans - Spans of the last-confirmed English text.
  289. * @param currentSpans - Spans of the current English text, aligned with `confirmedSpans`.
  290. * @param rows - The relevant terminology rows.
  291. * @param changed - Span indices already in the briefing.
  292. * @returns Notes and extra span indices to include.
  293. */
  294. export function firstOccurrenceContext(
  295. confirmedSource: string,
  296. currentSource: string,
  297. confirmedSpans: MarkdownSpan[],
  298. currentSpans: MarkdownSpan[],
  299. rows: TerminologyRow[],
  300. changed: Set<number>,
  301. ): FirstOccurrenceContext {
  302. const notes: string[] = []
  303. const extra = new Set<number>()
  304. for (const row of rows) {
  305. if (row.first === '') continue
  306. const oldIndex = spanIndexAtOffset(confirmedSource, confirmedSpans, termOffsets(confirmedSource, row.english, true)[0])
  307. const newIndex = spanIndexAtOffset(currentSource, currentSpans, termOffsets(currentSource, row.english, true)[0])
  308. if (oldIndex === newIndex) continue
  309. for (const index of [oldIndex, newIndex]) {
  310. if (index !== undefined && !changed.has(index)) extra.add(index)
  311. }
  312. notes.push(`${row.english}: the document-wide first occurrence moved from ${oldIndex === undefined ? 'absent' : `#${oldIndex}`} to ${newIndex === undefined ? 'absent' : `#${newIndex}`}; the ${row.first} form moves with it (later occurrences drop the annotation).`)
  313. }
  314. return { notes, extraSpanIndices: [...extra].sort((left, right) => left - right) }
  315. }
  316. /** Smallest fence of `mark` characters that safely wraps `body`. */
  317. function fenceFor(body: string, mark: '`' | '~'): string {
  318. let longest = 2
  319. for (const line of body.split('\n')) {
  320. const run = new RegExp(`^\\s*(${mark === '`' ? '`' : '~'}{3,})`).exec(line)
  321. if (run?.[1] !== undefined && run[1].length > longest) longest = run[1].length
  322. }
  323. return mark.repeat(longest + 1)
  324. }
  325. /** One changed (or first-occurrence) span with its three-way context. */
  326. export interface BriefBundle {
  327. /** Span index shared by the aligned documents. */
  328. index: number
  329. /** Human label: heading text or node type. */
  330. label: string
  331. /** Why the bundle is present when its source text did not change. */
  332. reason?: 'first-occurrence' | undefined
  333. confirmedSourceText: string
  334. currentSourceText: string
  335. counterpartText: string
  336. /** 1-based line the counterpart span starts on. */
  337. counterpartStartLine: number
  338. }
  339. /** The granularities a briefing can map the change at, narrowest first. */
  340. export type BriefScope =
  341. | { kind: 'mechanical' }
  342. | { kind: 'units'; bundles: BriefBundle[]; firstOccurrenceNotes: string[] }
  343. | { kind: 'sections'; bundles: BriefBundle[]; firstOccurrenceNotes: string[] }
  344. | { kind: 'document'; reason: string }
  345. /** Inputs for rendering one pair's briefing. */
  346. export interface TranslationBriefInput {
  347. /** Repo-relative path of the side that changed. */
  348. sourcePath: string
  349. /** Repo-relative path of the counterpart to update. */
  350. counterpartPath: string
  351. direction: BriefDirection
  352. /** Unified diff of the changed side, last-confirmed to current. */
  353. diff: string
  354. scope: BriefScope
  355. terminology: TerminologyRow[]
  356. }
  357. const ZH_TARGET_DIGEST = [
  358. '- Edit ONLY what the change requires; preserve the reviewed phrasing of everything unchanged.',
  359. '- Nothing added, nothing dropped: the Chinese must state exactly what the new English states.',
  360. '- Write natural institutional technical Chinese, not word-by-word gloss; terse stays terse.',
  361. '- Code fences byte-identical to the English side, comments included; inline code spans verbatim.',
  362. '- Relative links keep the `.md` target; only the switcher line links `.zh.md`.',
  363. '- Structure mirrors the counterpart: heading depths and order, list kinds and item counts, table rows and columns.',
  364. '- 首次出现 annotations attach to the document-wide first occurrence only; later occurrences use the bare form, and an empty 首次出现 cell means never gloss.',
  365. '- Typography: one half-width space between Chinese and Latin or digits; full-width punctuation in Chinese prose; 顿号 for enumerations; second person is 你.',
  366. '- One physical line per paragraph; exactly one trailing newline.',
  367. ]
  368. const EN_TARGET_DIGEST = [
  369. '- Edit ONLY what the change requires; preserve the reviewed phrasing of everything unchanged.',
  370. '- Nothing added, nothing dropped: the English must state exactly what the new Chinese states.',
  371. '- Write concise professional developer prose, not word-by-word gloss; terse stays terse.',
  372. '- Code fences byte-identical to the Chinese side, comments included; inline code spans verbatim.',
  373. '- Relative links keep the `.md` target; only the switcher line links `.zh.md`.',
  374. '- Structure mirrors the counterpart: heading depths and order, list kinds and item counts, table rows and columns.',
  375. '- One physical line per paragraph; exactly one trailing newline.',
  376. ]
  377. function renderBundles(out: string[], input: TranslationBriefInput, bundles: BriefBundle[], firstOccurrenceNotes: string[]): void {
  378. const sourceLanguage = input.direction === 'en-to-zh' ? 'English' : 'Chinese'
  379. const counterpartLanguage = input.direction === 'en-to-zh' ? 'Chinese' : 'English'
  380. for (const bundle of bundles) {
  381. out.push('')
  382. out.push(`### #${bundle.index} ${bundle.label}${bundle.reason === 'first-occurrence' ? ' — unchanged; included for a first-occurrence move' : ''} — counterpart at ${input.counterpartPath}:${bundle.counterpartStartLine}`)
  383. const fence = fenceFor([bundle.confirmedSourceText, bundle.currentSourceText, bundle.counterpartText].join('\n'), '~')
  384. if (bundle.confirmedSourceText !== bundle.currentSourceText) {
  385. out.push('')
  386. out.push(`Last-confirmed ${sourceLanguage}:`)
  387. out.push('')
  388. out.push(`${fence}markdown`)
  389. out.push(bundle.confirmedSourceText.trimEnd())
  390. out.push(fence)
  391. }
  392. out.push('')
  393. out.push(`Current ${sourceLanguage}:`)
  394. out.push('')
  395. out.push(`${fence}markdown`)
  396. out.push(bundle.currentSourceText.trimEnd())
  397. out.push(fence)
  398. out.push('')
  399. out.push(`Current ${counterpartLanguage} (bring this along):`)
  400. out.push('')
  401. out.push(`${fence}markdown`)
  402. out.push(bundle.counterpartText.trimEnd())
  403. out.push(fence)
  404. }
  405. if (firstOccurrenceNotes.length > 0) {
  406. out.push('')
  407. out.push('## First-occurrence notes')
  408. out.push('')
  409. for (const note of firstOccurrenceNotes) out.push(`- ${note}`)
  410. }
  411. }
  412. /**
  413. * Render the complete briefing for one out-of-sync pair.
  414. *
  415. * @param input - Diff, mapped scope, terminology, and pair identity.
  416. * @returns Markdown briefing text.
  417. */
  418. export function renderTranslationBrief(input: TranslationBriefInput): string {
  419. const sourceLanguage = input.direction === 'en-to-zh' ? 'English' : 'Chinese'
  420. const counterpartLanguage = input.direction === 'en-to-zh' ? 'Chinese' : 'English'
  421. const out: string[] = []
  422. out.push(`# Translation update briefing: ${input.sourcePath}`)
  423. out.push('')
  424. out.push(`The ${sourceLanguage} side changed; bring \`${input.counterpartPath}\` along with the smallest edit that covers the change.`)
  425. if (input.scope.kind === 'mechanical') {
  426. out.push('')
  427. out.push('## Mechanical update — no translation judgment involved')
  428. out.push('')
  429. out.push(`Every change since the last confirmed state is inside fenced code blocks, which are byte-identical across the pair. Run \`pnpm run gen-translation-brief --apply ${input.sourcePath}\` to splice the updated fences into the counterpart (the result is structure-validated before writing), then record per the Finish steps.`)
  430. }
  431. out.push('')
  432. out.push(`## ${sourceLanguage} diff (last-confirmed → current)`)
  433. out.push('')
  434. const diffFence = fenceFor(input.diff, '`')
  435. out.push(`${diffFence}diff`)
  436. out.push(input.diff.trimEnd())
  437. out.push(diffFence)
  438. switch (input.scope.kind) {
  439. case 'mechanical':
  440. break
  441. case 'units':
  442. out.push('')
  443. out.push(`## Changed units (last-confirmed ${sourceLanguage} → current ${sourceLanguage}, with the current ${counterpartLanguage})`)
  444. renderBundles(out, input, input.scope.bundles, input.scope.firstOccurrenceNotes)
  445. break
  446. case 'sections':
  447. out.push('')
  448. out.push('## Changed sections (fine-grained units do not align across the pair; whole heading sections shown)')
  449. renderBundles(out, input, input.scope.bundles, input.scope.firstOccurrenceNotes)
  450. break
  451. case 'document':
  452. out.push('')
  453. out.push('## Whole-document update required')
  454. out.push('')
  455. out.push(`${input.scope.reason} Open \`${input.counterpartPath}\` directly, locate the affected regions yourself, and reconcile under docs/i18n/translation-rules.md.`)
  456. break
  457. default:
  458. input.scope satisfies never
  459. }
  460. if (input.terminology.length > 0) {
  461. out.push('')
  462. out.push('## Binding terminology rows matching this change (docs/i18n/terminology.md)')
  463. out.push('')
  464. out.push('| English | 中文 | 首次出现 | 不要译作 | 备注 |')
  465. out.push('|---|---|---|---|---|')
  466. for (const row of input.terminology) out.push(row.line)
  467. out.push('')
  468. out.push('For any term you introduce that is not listed above, consult the full table before inventing a rendering.')
  469. }
  470. out.push('')
  471. out.push('## Rules digest (full rules: docs/i18n/translation-rules.md)')
  472. out.push('')
  473. out.push(...(input.direction === 'en-to-zh' ? ZH_TARGET_DIGEST : EN_TARGET_DIGEST))
  474. out.push('')
  475. out.push('## Finish')
  476. out.push('')
  477. out.push('1. Apply the smallest counterpart edit that covers the change, then verify the changed spans clause by clause against the source.')
  478. out.push(`2. \`pnpm run verify-translation-pairing --write ${input.sourcePath.replace(/\.zh\.md$/, '.md')}\``)
  479. out.push(`3. \`pnpm run verify-translation-pairing ${input.sourcePath.replace(/\.zh\.md$/, '.md')}\``)
  480. out.push('')
  481. return out.join('\n')
  482. }