@intlayer/cli 9.0.0-canary.0 → 9.0.0-canary.1
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/dist/cjs/cli.cjs +7 -3
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDoc.cjs +38 -11
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +54 -37
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
- package/dist/cjs/reviewDoc/reviewDocLog.cjs +48 -0
- package/dist/cjs/reviewDoc/reviewDocLog.cjs.map +1 -0
- package/dist/cjs/utils/formatLineRanges.cjs +44 -0
- package/dist/cjs/utils/formatLineRanges.cjs.map +1 -0
- package/dist/esm/cli.mjs +7 -3
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDoc.mjs +38 -11
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +54 -37
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
- package/dist/esm/reviewDoc/reviewDocLog.mjs +46 -0
- package/dist/esm/reviewDoc/reviewDocLog.mjs.map +1 -0
- package/dist/esm/utils/formatLineRanges.mjs +42 -0
- package/dist/esm/utils/formatLineRanges.mjs.map +1 -0
- package/dist/types/reviewDoc/reviewDoc.d.ts +8 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +8 -6
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
- package/dist/types/reviewDoc/reviewDocLog.d.ts +25 -0
- package/dist/types/reviewDoc/reviewDocLog.d.ts.map +1 -0
- package/dist/types/utils/formatLineRanges.d.ts +21 -0
- package/dist/types/utils/formatLineRanges.d.ts.map +1 -0
- package/package.json +13 -13
- package/dist/cjs/translation-alignment/alignBlocks.cjs +0 -68
- package/dist/cjs/translation-alignment/alignBlocks.cjs.map +0 -1
- package/dist/cjs/translation-alignment/computeSimilarity.cjs +0 -26
- package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +0 -1
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs +0 -24
- package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +0 -1
- package/dist/cjs/translation-alignment/index.cjs +0 -22
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +0 -19
- package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +0 -1
- package/dist/cjs/translation-alignment/normalizeBlock.cjs +0 -23
- package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +0 -1
- package/dist/cjs/translation-alignment/pipeline.cjs +0 -38
- package/dist/cjs/translation-alignment/pipeline.cjs.map +0 -1
- package/dist/cjs/translation-alignment/planActions.cjs +0 -47
- package/dist/cjs/translation-alignment/planActions.cjs.map +0 -1
- package/dist/cjs/translation-alignment/rebuildDocument.cjs +0 -50
- package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +0 -1
- package/dist/cjs/translation-alignment/segmentDocument.cjs +0 -67
- package/dist/cjs/translation-alignment/segmentDocument.cjs.map +0 -1
- package/dist/cjs/translation-alignment/types.cjs +0 -0
- package/dist/esm/translation-alignment/alignBlocks.mjs +0 -67
- package/dist/esm/translation-alignment/alignBlocks.mjs.map +0 -1
- package/dist/esm/translation-alignment/computeSimilarity.mjs +0 -23
- package/dist/esm/translation-alignment/computeSimilarity.mjs.map +0 -1
- package/dist/esm/translation-alignment/fingerprintBlock.mjs +0 -21
- package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +0 -1
- package/dist/esm/translation-alignment/index.mjs +0 -11
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +0 -17
- package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +0 -1
- package/dist/esm/translation-alignment/normalizeBlock.mjs +0 -21
- package/dist/esm/translation-alignment/normalizeBlock.mjs.map +0 -1
- package/dist/esm/translation-alignment/pipeline.mjs +0 -36
- package/dist/esm/translation-alignment/pipeline.mjs.map +0 -1
- package/dist/esm/translation-alignment/planActions.mjs +0 -45
- package/dist/esm/translation-alignment/planActions.mjs.map +0 -1
- package/dist/esm/translation-alignment/rebuildDocument.mjs +0 -47
- package/dist/esm/translation-alignment/rebuildDocument.mjs.map +0 -1
- package/dist/esm/translation-alignment/segmentDocument.mjs +0 -65
- package/dist/esm/translation-alignment/segmentDocument.mjs.map +0 -1
- package/dist/esm/translation-alignment/types.mjs +0 -0
- package/dist/types/translation-alignment/alignBlocks.d.ts +0 -7
- package/dist/types/translation-alignment/alignBlocks.d.ts.map +0 -1
- package/dist/types/translation-alignment/computeSimilarity.d.ts +0 -6
- package/dist/types/translation-alignment/computeSimilarity.d.ts.map +0 -1
- package/dist/types/translation-alignment/fingerprintBlock.d.ts +0 -7
- package/dist/types/translation-alignment/fingerprintBlock.d.ts.map +0 -1
- package/dist/types/translation-alignment/index.d.ts +0 -11
- package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts +0 -7
- package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts.map +0 -1
- package/dist/types/translation-alignment/normalizeBlock.d.ts +0 -7
- package/dist/types/translation-alignment/normalizeBlock.d.ts.map +0 -1
- package/dist/types/translation-alignment/pipeline.d.ts +0 -25
- package/dist/types/translation-alignment/pipeline.d.ts.map +0 -1
- package/dist/types/translation-alignment/planActions.d.ts +0 -7
- package/dist/types/translation-alignment/planActions.d.ts.map +0 -1
- package/dist/types/translation-alignment/rebuildDocument.d.ts +0 -32
- package/dist/types/translation-alignment/rebuildDocument.d.ts.map +0 -1
- package/dist/types/translation-alignment/segmentDocument.d.ts +0 -7
- package/dist/types/translation-alignment/segmentDocument.d.ts.map +0 -1
- package/dist/types/translation-alignment/types.d.ts +0 -49
- package/dist/types/translation-alignment/types.d.ts.map +0 -1
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//#region src/translation-alignment/planActions.ts
|
|
2
|
-
const planAlignmentActions = (alignment, changedEnglishBlockIndexes) => {
|
|
3
|
-
const actions = [];
|
|
4
|
-
const seenFrench = /* @__PURE__ */ new Set();
|
|
5
|
-
alignment.forEach((pair) => {
|
|
6
|
-
const englishIndex = pair.englishIndex;
|
|
7
|
-
const frenchIndex = pair.frenchIndex;
|
|
8
|
-
if (englishIndex === -1 && frenchIndex !== null) {
|
|
9
|
-
if (!seenFrench.has(frenchIndex)) {
|
|
10
|
-
actions.push({
|
|
11
|
-
kind: "delete",
|
|
12
|
-
frenchIndex
|
|
13
|
-
});
|
|
14
|
-
seenFrench.add(frenchIndex);
|
|
15
|
-
}
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (englishIndex >= 0 && frenchIndex === null) {
|
|
19
|
-
actions.push({
|
|
20
|
-
kind: "insert_new",
|
|
21
|
-
englishIndex
|
|
22
|
-
});
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (englishIndex >= 0 && frenchIndex !== null) {
|
|
26
|
-
if (!changedEnglishBlockIndexes.has(englishIndex)) actions.push({
|
|
27
|
-
kind: "reuse",
|
|
28
|
-
englishIndex,
|
|
29
|
-
frenchIndex
|
|
30
|
-
});
|
|
31
|
-
else actions.push({
|
|
32
|
-
kind: "review",
|
|
33
|
-
englishIndex,
|
|
34
|
-
frenchIndex
|
|
35
|
-
});
|
|
36
|
-
seenFrench.add(frenchIndex);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return { actions };
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { planAlignmentActions };
|
|
45
|
-
//# sourceMappingURL=planActions.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"planActions.mjs","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"sourcesContent":["import type { AlignmentPair, AlignmentPlan, PlannedAction } from './types';\n\nexport const planAlignmentActions = (\n alignment: AlignmentPair[],\n changedEnglishBlockIndexes: Set<number>\n): AlignmentPlan => {\n const actions: PlannedAction[] = [];\n const seenFrench = new Set<number>();\n\n alignment.forEach((pair) => {\n const englishIndex = pair.englishIndex;\n const frenchIndex = pair.frenchIndex;\n\n // Case 1: Deletion (Exists in FR, not in EN)\n if (englishIndex === -1 && frenchIndex !== null) {\n if (!seenFrench.has(frenchIndex)) {\n actions.push({ kind: 'delete', frenchIndex });\n seenFrench.add(frenchIndex);\n }\n return;\n }\n\n // Case 2: New Insertion (Exists in EN, not in FR)\n if (englishIndex >= 0 && frenchIndex === null) {\n actions.push({ kind: 'insert_new', englishIndex });\n return;\n }\n\n // Case 3: Alignment (Exists in both)\n if (englishIndex >= 0 && frenchIndex !== null) {\n const isChanged = changedEnglishBlockIndexes.has(englishIndex);\n\n // If the block is NOT marked as changed by Git, we REUSE it.\n // We assume the existing translation is correct because the source hasn't been touched.\n // We ignore 'similarityScore' here because EN vs UK text will always have low similarity.\n if (!isChanged) {\n actions.push({ kind: 'reuse', englishIndex, frenchIndex });\n } else {\n // If the block IS changed, we normally Review.\n // OPTIONAL: You could add a check here for 'similarityScore > 0.99'\n // to detect whitespace-only changes, but generally, if Git says changed, we Review.\n actions.push({ kind: 'review', englishIndex, frenchIndex });\n }\n\n seenFrench.add(frenchIndex);\n return;\n }\n });\n\n return { actions };\n};\n"],"mappings":";AAEA,MAAa,wBACX,WACA,+BACkB;CAClB,MAAM,UAA2B,EAAE;CACnC,MAAM,6BAAa,IAAI,KAAa;AAEpC,WAAU,SAAS,SAAS;EAC1B,MAAM,eAAe,KAAK;EAC1B,MAAM,cAAc,KAAK;AAGzB,MAAI,iBAAiB,MAAM,gBAAgB,MAAM;AAC/C,OAAI,CAAC,WAAW,IAAI,YAAY,EAAE;AAChC,YAAQ,KAAK;KAAE,MAAM;KAAU;KAAa,CAAC;AAC7C,eAAW,IAAI,YAAY;;AAE7B;;AAIF,MAAI,gBAAgB,KAAK,gBAAgB,MAAM;AAC7C,WAAQ,KAAK;IAAE,MAAM;IAAc;IAAc,CAAC;AAClD;;AAIF,MAAI,gBAAgB,KAAK,gBAAgB,MAAM;AAM7C,OAAI,CALc,2BAA2B,IAAI,aAKnC,CACZ,SAAQ,KAAK;IAAE,MAAM;IAAS;IAAc;IAAa,CAAC;OAK1D,SAAQ,KAAK;IAAE,MAAM;IAAU;IAAc;IAAa,CAAC;AAG7D,cAAW,IAAI,YAAY;AAC3B;;GAEF;AAEF,QAAO,EAAE,SAAS"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
//#region src/translation-alignment/rebuildDocument.ts
|
|
2
|
-
/**
|
|
3
|
-
* Analyzes the alignment plan and returns only the segments that need review/translation.
|
|
4
|
-
* Does not generate output text - that's done by mergeReviewedSegments after translation.
|
|
5
|
-
*/
|
|
6
|
-
const identifySegmentsToReview = ({ englishBlocks, frenchBlocks, plan }) => {
|
|
7
|
-
const segmentsToReview = [];
|
|
8
|
-
plan.actions.forEach((action, actionIndex) => {
|
|
9
|
-
if (action.kind === "review") {
|
|
10
|
-
const englishBlock = englishBlocks[action.englishIndex];
|
|
11
|
-
const frenchBlockText = action.frenchIndex !== null ? frenchBlocks[action.frenchIndex].content : null;
|
|
12
|
-
segmentsToReview.push({
|
|
13
|
-
englishBlock,
|
|
14
|
-
frenchBlockText,
|
|
15
|
-
actionIndex
|
|
16
|
-
});
|
|
17
|
-
} else if (action.kind === "insert_new") {
|
|
18
|
-
const englishBlock = englishBlocks[action.englishIndex];
|
|
19
|
-
segmentsToReview.push({
|
|
20
|
-
englishBlock,
|
|
21
|
-
frenchBlockText: null,
|
|
22
|
-
actionIndex
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return { segmentsToReview };
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Merges reviewed translations back into the final document following the alignment plan.
|
|
30
|
-
*/
|
|
31
|
-
const mergeReviewedSegments = (plan, frenchBlocks, reviewedSegments) => {
|
|
32
|
-
const outputParts = [];
|
|
33
|
-
plan.actions.forEach((action, actionIndex) => {
|
|
34
|
-
if (action.kind === "reuse") outputParts.push(frenchBlocks[action.frenchIndex].content);
|
|
35
|
-
else if (action.kind === "review" || action.kind === "insert_new") {
|
|
36
|
-
const reviewedContent = reviewedSegments.get(actionIndex);
|
|
37
|
-
if (reviewedContent !== void 0) outputParts.push(reviewedContent);
|
|
38
|
-
else if (action.kind === "review" && action.frenchIndex !== null) outputParts.push(frenchBlocks[action.frenchIndex].content);
|
|
39
|
-
else outputParts.push("\n");
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return outputParts.join("");
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
export { identifySegmentsToReview, mergeReviewedSegments };
|
|
47
|
-
//# sourceMappingURL=rebuildDocument.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rebuildDocument.mjs","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"sourcesContent":["import type { AlignmentPlan, FingerprintedBlock } from './types';\n\nexport type SegmentToReview = {\n englishBlock: FingerprintedBlock;\n frenchBlockText: string | null;\n actionIndex: number;\n};\n\nexport type RebuildInput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n};\n\nexport type RebuildResult = {\n segmentsToReview: SegmentToReview[];\n};\n\n/**\n * Analyzes the alignment plan and returns only the segments that need review/translation.\n * Does not generate output text - that's done by mergeReviewedSegments after translation.\n */\nexport const identifySegmentsToReview = ({\n englishBlocks,\n frenchBlocks,\n plan,\n}: RebuildInput): RebuildResult => {\n const segmentsToReview: SegmentToReview[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'review') {\n const englishBlock = englishBlocks[action.englishIndex];\n const frenchBlockText =\n action.frenchIndex !== null\n ? frenchBlocks[action.frenchIndex].content\n : null;\n\n segmentsToReview.push({ englishBlock, frenchBlockText, actionIndex });\n } else if (action.kind === 'insert_new') {\n const englishBlock = englishBlocks[action.englishIndex];\n\n segmentsToReview.push({\n englishBlock,\n frenchBlockText: null,\n actionIndex,\n });\n }\n });\n\n return { segmentsToReview };\n};\n\n/**\n * Merges reviewed translations back into the final document following the alignment plan.\n */\nexport const mergeReviewedSegments = (\n plan: AlignmentPlan,\n frenchBlocks: FingerprintedBlock[],\n reviewedSegments: Map<number, string>\n): string => {\n const outputParts: string[] = [];\n\n plan.actions.forEach((action, actionIndex) => {\n if (action.kind === 'reuse') {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else if (action.kind === 'review' || action.kind === 'insert_new') {\n const reviewedContent = reviewedSegments.get(actionIndex);\n\n if (reviewedContent !== undefined) {\n outputParts.push(reviewedContent);\n } else {\n // Fallback: if review failed, use existing or blank\n if (action.kind === 'review' && action.frenchIndex !== null) {\n outputParts.push(frenchBlocks[action.frenchIndex].content);\n } else {\n outputParts.push('\\n');\n }\n }\n }\n // \"delete\" actions are simply skipped - no output\n });\n\n return outputParts.join('');\n};\n"],"mappings":";;;;;AAsBA,MAAa,4BAA4B,EACvC,eACA,cACA,WACiC;CACjC,MAAM,mBAAsC,EAAE;AAE9C,MAAK,QAAQ,SAAS,QAAQ,gBAAgB;AAC5C,MAAI,OAAO,SAAS,UAAU;GAC5B,MAAM,eAAe,cAAc,OAAO;GAC1C,MAAM,kBACJ,OAAO,gBAAgB,OACnB,aAAa,OAAO,aAAa,UACjC;AAEN,oBAAiB,KAAK;IAAE;IAAc;IAAiB;IAAa,CAAC;aAC5D,OAAO,SAAS,cAAc;GACvC,MAAM,eAAe,cAAc,OAAO;AAE1C,oBAAiB,KAAK;IACpB;IACA,iBAAiB;IACjB;IACD,CAAC;;GAEJ;AAEF,QAAO,EAAE,kBAAkB;;;;;AAM7B,MAAa,yBACX,MACA,cACA,qBACW;CACX,MAAM,cAAwB,EAAE;AAEhC,MAAK,QAAQ,SAAS,QAAQ,gBAAgB;AAC5C,MAAI,OAAO,SAAS,QAClB,aAAY,KAAK,aAAa,OAAO,aAAa,QAAQ;WACjD,OAAO,SAAS,YAAY,OAAO,SAAS,cAAc;GACnE,MAAM,kBAAkB,iBAAiB,IAAI,YAAY;AAEzD,OAAI,oBAAoB,OACtB,aAAY,KAAK,gBAAgB;YAG7B,OAAO,SAAS,YAAY,OAAO,gBAAgB,KACrD,aAAY,KAAK,aAAa,OAAO,aAAa,QAAQ;OAE1D,aAAY,KAAK,KAAK;;GAK5B;AAEF,QAAO,YAAY,KAAK,GAAG"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
//#region src/translation-alignment/segmentDocument.ts
|
|
2
|
-
const isBlankLine = (line) => line.trim().length === 0;
|
|
3
|
-
const isFencedCodeDelimiter = (line) => /^\s*```/.test(line);
|
|
4
|
-
const isHeading = (line) => /^\s*#{1,6}\s+/.test(line);
|
|
5
|
-
const isFrontmatterDelimiter = (line) => /^\s*---\s*$/.test(line);
|
|
6
|
-
const trimTrailingNewlines = (text) => text.replace(/\n+$/g, "\n");
|
|
7
|
-
const segmentDocument = (text) => {
|
|
8
|
-
const lines = text.split("\n");
|
|
9
|
-
const blocks = [];
|
|
10
|
-
let index = 0;
|
|
11
|
-
let insideCodeBlock = false;
|
|
12
|
-
let currentSectionLines = [];
|
|
13
|
-
let currentSectionStartLine = 1;
|
|
14
|
-
const flushCurrentSection = (endIndex) => {
|
|
15
|
-
if (currentSectionLines.length > 0) {
|
|
16
|
-
const rawContent = currentSectionLines.join("\n");
|
|
17
|
-
if (rawContent.trim().length > 0) blocks.push({
|
|
18
|
-
type: "paragraph",
|
|
19
|
-
content: `${trimTrailingNewlines(rawContent)}\n`,
|
|
20
|
-
lineStart: currentSectionStartLine,
|
|
21
|
-
lineEnd: endIndex
|
|
22
|
-
});
|
|
23
|
-
currentSectionLines = [];
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
while (index < lines.length) {
|
|
27
|
-
const currentLine = lines[index];
|
|
28
|
-
if (blocks.length === 0 && isFrontmatterDelimiter(currentLine)) {
|
|
29
|
-
const startLine = index + 1;
|
|
30
|
-
const contentLines = [currentLine];
|
|
31
|
-
index++;
|
|
32
|
-
while (index < lines.length && !isFrontmatterDelimiter(lines[index])) {
|
|
33
|
-
contentLines.push(lines[index]);
|
|
34
|
-
index++;
|
|
35
|
-
}
|
|
36
|
-
if (index < lines.length && isFrontmatterDelimiter(lines[index])) {
|
|
37
|
-
contentLines.push(lines[index]);
|
|
38
|
-
index++;
|
|
39
|
-
}
|
|
40
|
-
blocks.push({
|
|
41
|
-
type: "paragraph",
|
|
42
|
-
content: `${trimTrailingNewlines(contentLines.join("\n"))}\n`,
|
|
43
|
-
lineStart: startLine,
|
|
44
|
-
lineEnd: index
|
|
45
|
-
});
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (isFencedCodeDelimiter(currentLine)) insideCodeBlock = !insideCodeBlock;
|
|
49
|
-
if (!insideCodeBlock && isHeading(currentLine)) {
|
|
50
|
-
if (currentSectionLines.length > 0) flushCurrentSection(index);
|
|
51
|
-
currentSectionStartLine = index + 1;
|
|
52
|
-
currentSectionLines = [currentLine];
|
|
53
|
-
} else {
|
|
54
|
-
if (currentSectionLines.length === 0 && !isBlankLine(currentLine)) currentSectionStartLine = index + 1;
|
|
55
|
-
currentSectionLines.push(currentLine);
|
|
56
|
-
}
|
|
57
|
-
index++;
|
|
58
|
-
}
|
|
59
|
-
flushCurrentSection(index);
|
|
60
|
-
return blocks;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { segmentDocument };
|
|
65
|
-
//# sourceMappingURL=segmentDocument.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"segmentDocument.mjs","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"sourcesContent":["import type { Block } from './types';\n\nconst isBlankLine = (line: string): boolean => line.trim().length === 0;\nconst isFencedCodeDelimiter = (line: string): boolean => /^\\s*```/.test(line);\nconst isHeading = (line: string): boolean => /^\\s*#{1,6}\\s+/.test(line);\nconst isFrontmatterDelimiter = (line: string): boolean =>\n /^\\s*---\\s*$/.test(line);\nconst trimTrailingNewlines = (text: string): string =>\n text.replace(/\\n+$/g, '\\n');\n\nexport const segmentDocument = (text: string): Block[] => {\n const lines = text.split('\\n');\n const blocks: Block[] = [];\n\n let index = 0;\n let insideCodeBlock = false;\n\n // Buffers\n let currentSectionLines: string[] = [];\n let currentSectionStartLine = 1;\n\n const flushCurrentSection = (endIndex: number) => {\n if (currentSectionLines.length > 0) {\n // Filter out leading blank lines from the block content to keep it clean,\n // but strictly speaking, we just want to ensure non-empty content.\n const rawContent = currentSectionLines.join('\\n');\n\n if (rawContent.trim().length > 0) {\n blocks.push({\n type: 'paragraph', // Generic type\n content: `${trimTrailingNewlines(rawContent)}\\n`,\n lineStart: currentSectionStartLine,\n lineEnd: endIndex,\n });\n }\n currentSectionLines = [];\n }\n };\n\n while (index < lines.length) {\n const currentLine = lines[index];\n\n // 1. Handle Frontmatter (Must be at start of file)\n if (blocks.length === 0 && isFrontmatterDelimiter(currentLine)) {\n const startLine = index + 1;\n const contentLines: string[] = [currentLine];\n index++;\n\n while (index < lines.length && !isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n if (index < lines.length && isFrontmatterDelimiter(lines[index])) {\n contentLines.push(lines[index]);\n index++;\n }\n\n blocks.push({\n type: 'paragraph',\n content: `${trimTrailingNewlines(contentLines.join('\\n'))}\\n`,\n lineStart: startLine,\n lineEnd: index,\n });\n continue;\n }\n\n // 2. Track Code Blocks (Headers inside code blocks are ignored)\n if (isFencedCodeDelimiter(currentLine)) {\n insideCodeBlock = !insideCodeBlock;\n }\n\n const isHeader = !insideCodeBlock && isHeading(currentLine);\n\n // 3. Split on Headers\n if (isHeader) {\n // If we have accumulated content, flush it as the previous block\n if (currentSectionLines.length > 0) {\n flushCurrentSection(index);\n }\n // Start a new section with this header\n currentSectionStartLine = index + 1;\n currentSectionLines = [currentLine];\n } else {\n // Accumulate content\n if (currentSectionLines.length === 0 && !isBlankLine(currentLine)) {\n currentSectionStartLine = index + 1;\n }\n currentSectionLines.push(currentLine);\n }\n\n index++;\n }\n\n // Flush remaining content\n flushCurrentSection(index);\n\n return blocks;\n};\n"],"mappings":";AAEA,MAAM,eAAe,SAA0B,KAAK,MAAM,CAAC,WAAW;AACtE,MAAM,yBAAyB,SAA0B,UAAU,KAAK,KAAK;AAC7E,MAAM,aAAa,SAA0B,gBAAgB,KAAK,KAAK;AACvE,MAAM,0BAA0B,SAC9B,cAAc,KAAK,KAAK;AAC1B,MAAM,wBAAwB,SAC5B,KAAK,QAAQ,SAAS,KAAK;AAE7B,MAAa,mBAAmB,SAA0B;CACxD,MAAM,QAAQ,KAAK,MAAM,KAAK;CAC9B,MAAM,SAAkB,EAAE;CAE1B,IAAI,QAAQ;CACZ,IAAI,kBAAkB;CAGtB,IAAI,sBAAgC,EAAE;CACtC,IAAI,0BAA0B;CAE9B,MAAM,uBAAuB,aAAqB;AAChD,MAAI,oBAAoB,SAAS,GAAG;GAGlC,MAAM,aAAa,oBAAoB,KAAK,KAAK;AAEjD,OAAI,WAAW,MAAM,CAAC,SAAS,EAC7B,QAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,WAAW,CAAC;IAC7C,WAAW;IACX,SAAS;IACV,CAAC;AAEJ,yBAAsB,EAAE;;;AAI5B,QAAO,QAAQ,MAAM,QAAQ;EAC3B,MAAM,cAAc,MAAM;AAG1B,MAAI,OAAO,WAAW,KAAK,uBAAuB,YAAY,EAAE;GAC9D,MAAM,YAAY,QAAQ;GAC1B,MAAM,eAAyB,CAAC,YAAY;AAC5C;AAEA,UAAO,QAAQ,MAAM,UAAU,CAAC,uBAAuB,MAAM,OAAO,EAAE;AACpE,iBAAa,KAAK,MAAM,OAAO;AAC/B;;AAGF,OAAI,QAAQ,MAAM,UAAU,uBAAuB,MAAM,OAAO,EAAE;AAChE,iBAAa,KAAK,MAAM,OAAO;AAC/B;;AAGF,UAAO,KAAK;IACV,MAAM;IACN,SAAS,GAAG,qBAAqB,aAAa,KAAK,KAAK,CAAC,CAAC;IAC1D,WAAW;IACX,SAAS;IACV,CAAC;AACF;;AAIF,MAAI,sBAAsB,YAAY,CACpC,mBAAkB,CAAC;AAMrB,MAHiB,CAAC,mBAAmB,UAAU,YAAY,EAG7C;AAEZ,OAAI,oBAAoB,SAAS,EAC/B,qBAAoB,MAAM;AAG5B,6BAA0B,QAAQ;AAClC,yBAAsB,CAAC,YAAY;SAC9B;AAEL,OAAI,oBAAoB,WAAW,KAAK,CAAC,YAAY,YAAY,CAC/D,2BAA0B,QAAQ;AAEpC,uBAAoB,KAAK,YAAY;;AAGvC;;AAIF,qBAAoB,MAAM;AAE1B,QAAO"}
|
|
File without changes
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AlignmentPair, FingerprintedBlock } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/alignBlocks.d.ts
|
|
4
|
-
declare const alignEnglishAndFrenchBlocks: (defaultBlocks: FingerprintedBlock[], secondaryBlocks: FingerprintedBlock[]) => AlignmentPair[];
|
|
5
|
-
//#endregion
|
|
6
|
-
export { alignEnglishAndFrenchBlocks };
|
|
7
|
-
//# sourceMappingURL=alignBlocks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"alignBlocks.d.ts","names":[],"sources":["../../../src/translation-alignment/alignBlocks.ts"],"mappings":";;;cAGa,2BAAA,GACX,aAAA,EAAe,kBAAA,IACf,eAAA,EAAiB,kBAAA,OAChB,aAAA"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/translation-alignment/computeSimilarity.d.ts
|
|
2
|
-
declare const generateCharacterShingles: (text: string, shingleLength: number) => Set<string>;
|
|
3
|
-
declare const computeJaccardSimilarity: (a: string, b: string, shingleLength?: number) => number;
|
|
4
|
-
//#endregion
|
|
5
|
-
export { computeJaccardSimilarity, generateCharacterShingles };
|
|
6
|
-
//# sourceMappingURL=computeSimilarity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"computeSimilarity.d.ts","names":[],"sources":["../../../src/translation-alignment/computeSimilarity.ts"],"mappings":";cACa,yBAAA,GACX,IAAA,UACA,aAAA,aACC,GAAA;AAAA,cAeU,wBAAA,GACX,CAAA,UACA,CAAA,UACA,aAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FingerprintedBlock, NormalizedBlock } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/fingerprintBlock.d.ts
|
|
4
|
-
declare const fingerprintBlock: (block: NormalizedBlock, previousBlock: NormalizedBlock | null, nextBlock: NormalizedBlock | null) => FingerprintedBlock;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { fingerprintBlock };
|
|
7
|
-
//# sourceMappingURL=fingerprintBlock.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprintBlock.d.ts","names":[],"sources":["../../../src/translation-alignment/fingerprintBlock.ts"],"mappings":";;;cAMa,gBAAA,GACX,KAAA,EAAO,eAAA,EACP,aAAA,EAAe,eAAA,SACf,SAAA,EAAW,eAAA,YACV,kBAAA"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AlignmentPair, AlignmentPlan, Block, BlockType, FingerprintedBlock, LineChange, NormalizedBlock, PlannedAction, SimilarityOptions } from "./types.js";
|
|
2
|
-
import { alignEnglishAndFrenchBlocks } from "./alignBlocks.js";
|
|
3
|
-
import { computeJaccardSimilarity, generateCharacterShingles } from "./computeSimilarity.js";
|
|
4
|
-
import { fingerprintBlock } from "./fingerprintBlock.js";
|
|
5
|
-
import { mapChangedLinesToBlocks } from "./mapChangedLinesToBlocks.js";
|
|
6
|
-
import { normalizeBlock } from "./normalizeBlock.js";
|
|
7
|
-
import { SegmentToReview, identifySegmentsToReview, mergeReviewedSegments } from "./rebuildDocument.js";
|
|
8
|
-
import { BuildAlignmentPlanInput, BuildAlignmentPlanOutput, buildAlignmentPlan } from "./pipeline.js";
|
|
9
|
-
import { planAlignmentActions } from "./planActions.js";
|
|
10
|
-
import { segmentDocument } from "./segmentDocument.js";
|
|
11
|
-
export { type AlignmentPair, type AlignmentPlan, type Block, type BlockType, type BuildAlignmentPlanInput, type BuildAlignmentPlanOutput, type FingerprintedBlock, type LineChange, type NormalizedBlock, type PlannedAction, type SegmentToReview, type SimilarityOptions, alignEnglishAndFrenchBlocks, buildAlignmentPlan, computeJaccardSimilarity, fingerprintBlock, generateCharacterShingles, identifySegmentsToReview, mapChangedLinesToBlocks, mergeReviewedSegments, normalizeBlock, planAlignmentActions, segmentDocument };
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Block, LineChange } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/mapChangedLinesToBlocks.d.ts
|
|
4
|
-
declare const mapChangedLinesToBlocks: (blocks: Block[], changedLines: LineChange[]) => Set<number>;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { mapChangedLinesToBlocks };
|
|
7
|
-
//# sourceMappingURL=mapChangedLinesToBlocks.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapChangedLinesToBlocks.d.ts","names":[],"sources":["../../../src/translation-alignment/mapChangedLinesToBlocks.ts"],"mappings":";;;cAEa,uBAAA,GACX,MAAA,EAAQ,KAAA,IACR,YAAA,EAAc,UAAA,OACb,GAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Block, NormalizedBlock } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/normalizeBlock.d.ts
|
|
4
|
-
declare const normalizeBlock: (block: Block) => NormalizedBlock;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { normalizeBlock };
|
|
7
|
-
//# sourceMappingURL=normalizeBlock.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeBlock.d.ts","names":[],"sources":["../../../src/translation-alignment/normalizeBlock.ts"],"mappings":";;;cAwBa,cAAA,GAAkB,KAAA,EAAO,KAAA,KAAQ,eAAA"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { AlignmentPlan, FingerprintedBlock, SimilarityOptions } from "./types.js";
|
|
2
|
-
import { SegmentToReview, mergeReviewedSegments } from "./rebuildDocument.js";
|
|
3
|
-
|
|
4
|
-
//#region src/translation-alignment/pipeline.d.ts
|
|
5
|
-
type BuildAlignmentPlanInput = {
|
|
6
|
-
englishText: string;
|
|
7
|
-
frenchText: string;
|
|
8
|
-
changedLines: number[] | undefined;
|
|
9
|
-
similarityOptions?: Partial<SimilarityOptions>;
|
|
10
|
-
};
|
|
11
|
-
type BuildAlignmentPlanOutput = {
|
|
12
|
-
englishBlocks: FingerprintedBlock[];
|
|
13
|
-
frenchBlocks: FingerprintedBlock[];
|
|
14
|
-
plan: AlignmentPlan;
|
|
15
|
-
segmentsToReview: SegmentToReview[];
|
|
16
|
-
};
|
|
17
|
-
declare const buildAlignmentPlan: ({
|
|
18
|
-
englishText,
|
|
19
|
-
frenchText,
|
|
20
|
-
changedLines,
|
|
21
|
-
similarityOptions
|
|
22
|
-
}: BuildAlignmentPlanInput) => BuildAlignmentPlanOutput;
|
|
23
|
-
//#endregion
|
|
24
|
-
export { BuildAlignmentPlanInput, BuildAlignmentPlanOutput, type SegmentToReview, buildAlignmentPlan, mergeReviewedSegments };
|
|
25
|
-
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","names":[],"sources":["../../../src/translation-alignment/pipeline.ts"],"mappings":";;;;KAiBY,uBAAA;EACV,WAAA;EACA,UAAA;EACA,YAAA;EACA,iBAAA,GAAoB,OAAA,CAAQ,iBAAA;AAAA;AAAA,KAGlB,wBAAA;EACV,aAAA,EAAe,kBAAA;EACf,YAAA,EAAc,kBAAA;EACd,IAAA,EAAM,aAAA;EACN,gBAAA,EAAkB,eAAA;AAAA;AAAA,cAGP,kBAAA;EAAsB,WAAA;EAAA,UAAA;EAAA,YAAA;EAAA;AAAA,GAKhC,uBAAA,KAA0B,wBAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AlignmentPair, AlignmentPlan } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/planActions.d.ts
|
|
4
|
-
declare const planAlignmentActions: (alignment: AlignmentPair[], changedEnglishBlockIndexes: Set<number>) => AlignmentPlan;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { planAlignmentActions };
|
|
7
|
-
//# sourceMappingURL=planActions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"planActions.d.ts","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"mappings":";;;cAEa,oBAAA,GACX,SAAA,EAAW,aAAA,IACX,0BAAA,EAA4B,GAAA,aAC3B,aAAA"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { AlignmentPlan, FingerprintedBlock } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/translation-alignment/rebuildDocument.d.ts
|
|
4
|
-
type SegmentToReview = {
|
|
5
|
-
englishBlock: FingerprintedBlock;
|
|
6
|
-
frenchBlockText: string | null;
|
|
7
|
-
actionIndex: number;
|
|
8
|
-
};
|
|
9
|
-
type RebuildInput = {
|
|
10
|
-
englishBlocks: FingerprintedBlock[];
|
|
11
|
-
frenchBlocks: FingerprintedBlock[];
|
|
12
|
-
plan: AlignmentPlan;
|
|
13
|
-
};
|
|
14
|
-
type RebuildResult = {
|
|
15
|
-
segmentsToReview: SegmentToReview[];
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Analyzes the alignment plan and returns only the segments that need review/translation.
|
|
19
|
-
* Does not generate output text - that's done by mergeReviewedSegments after translation.
|
|
20
|
-
*/
|
|
21
|
-
declare const identifySegmentsToReview: ({
|
|
22
|
-
englishBlocks,
|
|
23
|
-
frenchBlocks,
|
|
24
|
-
plan
|
|
25
|
-
}: RebuildInput) => RebuildResult;
|
|
26
|
-
/**
|
|
27
|
-
* Merges reviewed translations back into the final document following the alignment plan.
|
|
28
|
-
*/
|
|
29
|
-
declare const mergeReviewedSegments: (plan: AlignmentPlan, frenchBlocks: FingerprintedBlock[], reviewedSegments: Map<number, string>) => string;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { RebuildInput, RebuildResult, SegmentToReview, identifySegmentsToReview, mergeReviewedSegments };
|
|
32
|
-
//# sourceMappingURL=rebuildDocument.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rebuildDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"mappings":";;;KAEY,eAAA;EACV,YAAA,EAAc,kBAAA;EACd,eAAA;EACA,WAAA;AAAA;AAAA,KAGU,YAAA;EACV,aAAA,EAAe,kBAAA;EACf,YAAA,EAAc,kBAAA;EACd,IAAA,EAAM,aAAA;AAAA;AAAA,KAGI,aAAA;EACV,gBAAA,EAAkB,eAAA;AAAA;;;;;cAOP,wBAAA;EAA4B,aAAA;EAAA,YAAA;EAAA;AAAA,GAItC,YAAA,KAAe,aAAA;;;;cA6BL,qBAAA,GACX,IAAA,EAAM,aAAA,EACN,YAAA,EAAc,kBAAA,IACd,gBAAA,EAAkB,GAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"segmentDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"mappings":";;;cAUa,eAAA,GAAmB,IAAA,aAAe,KAAA"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//#region src/translation-alignment/types.d.ts
|
|
2
|
-
type BlockType = 'heading' | 'paragraph' | 'list_item' | 'code_block' | 'blockquote' | 'table' | 'horizontal_rule' | 'html' | 'unknown';
|
|
3
|
-
type Block = {
|
|
4
|
-
type: BlockType;
|
|
5
|
-
content: string;
|
|
6
|
-
lineStart: number;
|
|
7
|
-
lineEnd: number;
|
|
8
|
-
};
|
|
9
|
-
type NormalizedBlock = Block & {
|
|
10
|
-
semanticText: string;
|
|
11
|
-
anchorText: string;
|
|
12
|
-
};
|
|
13
|
-
type FingerprintedBlock = NormalizedBlock & {
|
|
14
|
-
semanticDigest: string;
|
|
15
|
-
anchorDigest: string;
|
|
16
|
-
compositeKey: string;
|
|
17
|
-
contextKey?: string;
|
|
18
|
-
};
|
|
19
|
-
type AlignmentPair = {
|
|
20
|
-
englishIndex: number;
|
|
21
|
-
frenchIndex: number | null;
|
|
22
|
-
similarityScore: number;
|
|
23
|
-
};
|
|
24
|
-
type PlannedAction = {
|
|
25
|
-
kind: 'reuse';
|
|
26
|
-
englishIndex: number;
|
|
27
|
-
frenchIndex: number;
|
|
28
|
-
} | {
|
|
29
|
-
kind: 'review';
|
|
30
|
-
englishIndex: number;
|
|
31
|
-
frenchIndex: number | null;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'insert_new';
|
|
34
|
-
englishIndex: number;
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'delete';
|
|
37
|
-
frenchIndex: number;
|
|
38
|
-
};
|
|
39
|
-
type AlignmentPlan = {
|
|
40
|
-
actions: PlannedAction[];
|
|
41
|
-
};
|
|
42
|
-
type LineChange = number;
|
|
43
|
-
type SimilarityOptions = {
|
|
44
|
-
minimumMatchForReuse: number;
|
|
45
|
-
minimumMatchForNearDuplicate: number;
|
|
46
|
-
};
|
|
47
|
-
//#endregion
|
|
48
|
-
export { AlignmentPair, AlignmentPlan, Block, BlockType, FingerprintedBlock, LineChange, NormalizedBlock, PlannedAction, SimilarityOptions };
|
|
49
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/translation-alignment/types.ts"],"mappings":";KAAY,SAAA;AAAA,KAWA,KAAA;EACV,IAAA,EAAM,SAAA;EACN,OAAA;EACA,SAAA;EACA,OAAA;AAAA;AAAA,KAGU,eAAA,GAAkB,KAAA;EAC5B,YAAA;EACA,UAAA;AAAA;AAAA,KAGU,kBAAA,GAAqB,eAAA;EAC/B,cAAA;EACA,YAAA;EACA,YAAA;EACA,UAAA;AAAA;AAAA,KAGU,aAAA;EACV,YAAA;EACA,WAAA;EACA,eAAA;AAAA;AAAA,KAGU,aAAA;EACN,IAAA;EAAe,YAAA;EAAsB,WAAA;AAAA;EACrC,IAAA;EAAgB,YAAA;EAAsB,WAAA;AAAA;EACtC,IAAA;EAAoB,YAAA;AAAA;EACpB,IAAA;EAAgB,WAAA;AAAA;AAAA,KAEV,aAAA;EACV,OAAA,EAAS,aAAA;AAAA;AAAA,KAGC,UAAA;AAAA,KAEA,iBAAA;EACV,oBAAA;EACA,4BAAA;AAAA"}
|