@intlayer/cli 7.0.7 → 7.0.8

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.
Files changed (150) hide show
  1. package/dist/assets/translation-alignment/ARCHITECTURE.md +518 -0
  2. package/dist/assets/translation-alignment/IMPROVEMENTS.md +550 -0
  3. package/dist/assets/translation-alignment/INTEGRATION_EXAMPLE.md +682 -0
  4. package/dist/assets/translation-alignment/QUICK_START.md +494 -0
  5. package/dist/assets/translation-alignment/README.md +485 -0
  6. package/dist/assets/translation-alignment/SUMMARY.md +440 -0
  7. package/dist/cjs/IntlayerEventListener.cjs +0 -3
  8. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  9. package/dist/cjs/_virtual/_utils_asset.cjs +0 -3
  10. package/dist/cjs/build.cjs +0 -2
  11. package/dist/cjs/build.cjs.map +1 -1
  12. package/dist/cjs/cli.cjs +6 -7
  13. package/dist/cjs/cli.cjs.map +1 -1
  14. package/dist/cjs/config.cjs +0 -1
  15. package/dist/cjs/config.cjs.map +1 -1
  16. package/dist/cjs/editor.cjs +0 -4
  17. package/dist/cjs/editor.cjs.map +1 -1
  18. package/dist/cjs/fill/fill.cjs +0 -3
  19. package/dist/cjs/fill/fill.cjs.map +1 -1
  20. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +0 -1
  21. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  22. package/dist/cjs/fill/listTranslationsTasks.cjs +0 -6
  23. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  24. package/dist/cjs/fill/translateDictionary.cjs +0 -6
  25. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  26. package/dist/cjs/fill/writeFill.cjs +0 -4
  27. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  28. package/dist/cjs/getTargetDictionary.cjs +0 -4
  29. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  30. package/dist/cjs/index.cjs +0 -1
  31. package/dist/cjs/listContentDeclaration.cjs +0 -4
  32. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  33. package/dist/cjs/liveSync.cjs +0 -6
  34. package/dist/cjs/liveSync.cjs.map +1 -1
  35. package/dist/cjs/pull.cjs +0 -5
  36. package/dist/cjs/pull.cjs.map +1 -1
  37. package/dist/cjs/push/pullLog.cjs +0 -1
  38. package/dist/cjs/push/pullLog.cjs.map +1 -1
  39. package/dist/cjs/push/push.cjs +0 -5
  40. package/dist/cjs/push/push.cjs.map +1 -1
  41. package/dist/cjs/pushConfig.cjs +0 -2
  42. package/dist/cjs/pushConfig.cjs.map +1 -1
  43. package/dist/cjs/pushLog.cjs +0 -1
  44. package/dist/cjs/pushLog.cjs.map +1 -1
  45. package/dist/cjs/reviewDoc.cjs +8 -131
  46. package/dist/cjs/reviewDoc.cjs.map +1 -1
  47. package/dist/cjs/reviewDocBlockAware.cjs +90 -0
  48. package/dist/cjs/reviewDocBlockAware.cjs.map +1 -0
  49. package/dist/cjs/test/index.cjs +0 -2
  50. package/dist/cjs/test/index.cjs.map +1 -1
  51. package/dist/cjs/test/listMissingTranslations.cjs +0 -4
  52. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  53. package/dist/cjs/translateDoc.cjs +8 -8
  54. package/dist/cjs/translateDoc.cjs.map +1 -1
  55. package/dist/cjs/translation-alignment/alignBlocks.cjs +67 -0
  56. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -0
  57. package/dist/cjs/translation-alignment/computeSimilarity.cjs +25 -0
  58. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -0
  59. package/dist/cjs/translation-alignment/fingerprintBlock.cjs +23 -0
  60. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -0
  61. package/dist/cjs/translation-alignment/index.cjs +21 -0
  62. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +18 -0
  63. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -0
  64. package/dist/cjs/translation-alignment/normalizeBlock.cjs +22 -0
  65. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -0
  66. package/dist/cjs/translation-alignment/pipeline.cjs +37 -0
  67. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -0
  68. package/dist/cjs/translation-alignment/planActions.cjs +48 -0
  69. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -0
  70. package/dist/cjs/translation-alignment/rebuildDocument.cjs +49 -0
  71. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -0
  72. package/dist/cjs/translation-alignment/segmentDocument.cjs +132 -0
  73. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -0
  74. package/dist/cjs/translation-alignment/types.cjs +0 -0
  75. package/dist/cjs/utils/calculateChunks.cjs +0 -1
  76. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  77. package/dist/cjs/utils/checkAccess.cjs +0 -2
  78. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  79. package/dist/cjs/utils/checkLastUpdateTime.cjs +0 -1
  80. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  81. package/dist/cjs/utils/chunkInference.cjs +0 -2
  82. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  83. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +0 -1
  84. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  85. package/dist/cjs/utils/getParentPackageJSON.cjs +0 -2
  86. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  87. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +0 -1
  88. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  89. package/dist/cjs/watch.cjs +0 -2
  90. package/dist/cjs/watch.cjs.map +1 -1
  91. package/dist/esm/cli.mjs +6 -3
  92. package/dist/esm/cli.mjs.map +1 -1
  93. package/dist/esm/index.mjs +2 -2
  94. package/dist/esm/reviewDoc.mjs +13 -128
  95. package/dist/esm/reviewDoc.mjs.map +1 -1
  96. package/dist/esm/reviewDocBlockAware.mjs +89 -0
  97. package/dist/esm/reviewDocBlockAware.mjs.map +1 -0
  98. package/dist/esm/translateDoc.mjs +8 -3
  99. package/dist/esm/translateDoc.mjs.map +1 -1
  100. package/dist/esm/translation-alignment/alignBlocks.mjs +67 -0
  101. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -0
  102. package/dist/esm/translation-alignment/computeSimilarity.mjs +23 -0
  103. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -0
  104. package/dist/esm/translation-alignment/fingerprintBlock.mjs +21 -0
  105. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -0
  106. package/dist/esm/translation-alignment/index.mjs +11 -0
  107. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +17 -0
  108. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -0
  109. package/dist/esm/translation-alignment/normalizeBlock.mjs +21 -0
  110. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -0
  111. package/dist/esm/translation-alignment/pipeline.mjs +36 -0
  112. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -0
  113. package/dist/esm/translation-alignment/planActions.mjs +47 -0
  114. package/dist/esm/translation-alignment/planActions.mjs.map +1 -0
  115. package/dist/esm/translation-alignment/rebuildDocument.mjs +47 -0
  116. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -0
  117. package/dist/esm/translation-alignment/segmentDocument.mjs +131 -0
  118. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -0
  119. package/dist/esm/translation-alignment/types.mjs +0 -0
  120. package/dist/types/cli.d.ts.map +1 -1
  121. package/dist/types/index.d.ts +2 -2
  122. package/dist/types/pull.d.ts.map +1 -1
  123. package/dist/types/reviewDoc.d.ts +3 -6
  124. package/dist/types/reviewDoc.d.ts.map +1 -1
  125. package/dist/types/reviewDocBlockAware.d.ts +19 -0
  126. package/dist/types/reviewDocBlockAware.d.ts.map +1 -0
  127. package/dist/types/translateDoc.d.ts +2 -0
  128. package/dist/types/translateDoc.d.ts.map +1 -1
  129. package/dist/types/translation-alignment/alignBlocks.d.ts +7 -0
  130. package/dist/types/translation-alignment/alignBlocks.d.ts.map +1 -0
  131. package/dist/types/translation-alignment/computeSimilarity.d.ts +6 -0
  132. package/dist/types/translation-alignment/computeSimilarity.d.ts.map +1 -0
  133. package/dist/types/translation-alignment/fingerprintBlock.d.ts +7 -0
  134. package/dist/types/translation-alignment/fingerprintBlock.d.ts.map +1 -0
  135. package/dist/types/translation-alignment/index.d.ts +11 -0
  136. package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts +7 -0
  137. package/dist/types/translation-alignment/mapChangedLinesToBlocks.d.ts.map +1 -0
  138. package/dist/types/translation-alignment/normalizeBlock.d.ts +7 -0
  139. package/dist/types/translation-alignment/normalizeBlock.d.ts.map +1 -0
  140. package/dist/types/translation-alignment/pipeline.d.ts +25 -0
  141. package/dist/types/translation-alignment/pipeline.d.ts.map +1 -0
  142. package/dist/types/translation-alignment/planActions.d.ts +7 -0
  143. package/dist/types/translation-alignment/planActions.d.ts.map +1 -0
  144. package/dist/types/translation-alignment/rebuildDocument.d.ts +32 -0
  145. package/dist/types/translation-alignment/rebuildDocument.d.ts.map +1 -0
  146. package/dist/types/translation-alignment/segmentDocument.d.ts +7 -0
  147. package/dist/types/translation-alignment/segmentDocument.d.ts.map +1 -0
  148. package/dist/types/translation-alignment/types.d.ts +49 -0
  149. package/dist/types/translation-alignment/types.d.ts.map +1 -0
  150. package/package.json +23 -23
@@ -0,0 +1,90 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require__utils_asset = require('./_virtual/_utils_asset.cjs');
3
+ const require_translation_alignment_rebuildDocument = require('./translation-alignment/rebuildDocument.cjs');
4
+ const require_translation_alignment_pipeline = require('./translation-alignment/pipeline.cjs');
5
+ const require_utils_chunkInference = require('./utils/chunkInference.cjs');
6
+ const require_utils_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
7
+ let __intlayer_chokidar = require("@intlayer/chokidar");
8
+ let __intlayer_config = require("@intlayer/config");
9
+ let node_path = require("node:path");
10
+ let __intlayer_core = require("@intlayer/core");
11
+ let node_fs = require("node:fs");
12
+ let node_fs_promises = require("node:fs/promises");
13
+ let __intlayer_types = require("@intlayer/types");
14
+
15
+ //#region src/reviewDocBlockAware.ts
16
+ /**
17
+ * Review a file using block-aware alignment.
18
+ * This approach:
19
+ * 1. Segments both English and French documents into semantic blocks
20
+ * 2. Aligns blocks using structure (special chars, numbers) and context
21
+ * 3. Detects which blocks changed, were added, or deleted
22
+ * 4. Only sends changed/new blocks to AI for translation
23
+ * 5. Handles reordering automatically
24
+ */
25
+ const reviewFileBlockAware = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines) => {
26
+ const configuration = (0, __intlayer_config.getConfiguration)(configOptions);
27
+ const applicationLogger = (0, __intlayer_config.getAppLogger)(configuration);
28
+ const englishText = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
29
+ const frenchText = await (0, node_fs_promises.readFile)(outputFilePath, "utf-8").catch(() => "");
30
+ const basePrompt = require__utils_asset.readAsset("./prompts/REVIEW_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, __intlayer_chokidar.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, __intlayer_chokidar.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
31
+ const filePrefix = [(0, __intlayer_config.colon)(`${__intlayer_config.ANSIColors.GREY_DARK}[${(0, __intlayer_chokidar.formatPath)(baseFilePath)}${__intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${__intlayer_config.ANSIColors.RESET}`].join("");
32
+ const prefix = [(0, __intlayer_config.colon)(`${__intlayer_config.ANSIColors.GREY_DARK}[${(0, __intlayer_chokidar.formatPath)(baseFilePath)}${__intlayer_config.ANSIColors.GREY_DARK}][${(0, __intlayer_chokidar.formatLocale)(locale)}${__intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${__intlayer_config.ANSIColors.RESET}`].join("");
33
+ const { englishBlocks, frenchBlocks, plan, segmentsToReview } = require_translation_alignment_pipeline.buildAlignmentPlan({
34
+ englishText,
35
+ frenchText,
36
+ changedLines
37
+ });
38
+ applicationLogger(`${filePrefix}Block-aware alignment complete. Total blocks: EN=${(0, __intlayer_config.colorizeNumber)(englishBlocks.length)}, FR=${(0, __intlayer_config.colorizeNumber)(frenchBlocks.length)}`);
39
+ applicationLogger(`${filePrefix}Actions: reuse=${(0, __intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "reuse").length)}, review=${(0, __intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "review").length)}, new=${(0, __intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "insert_new").length)}, delete=${(0, __intlayer_config.colorizeNumber)(plan.actions.filter((a) => a.kind === "delete").length)}`);
40
+ if (segmentsToReview.length === 0) {
41
+ applicationLogger(`${filePrefix}No segments need review, reusing existing translation`);
42
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
43
+ (0, node_fs.writeFileSync)(outputFilePath, require_translation_alignment_rebuildDocument.mergeReviewedSegments(plan, frenchBlocks, /* @__PURE__ */ new Map()));
44
+ applicationLogger(`${(0, __intlayer_config.colorize)("✔", __intlayer_config.ANSIColors.GREEN)} File ${(0, __intlayer_chokidar.formatPath)(outputFilePath)} updated successfully (no changes needed).`);
45
+ return;
46
+ }
47
+ applicationLogger(`${filePrefix}Segments to review: ${(0, __intlayer_config.colorizeNumber)(segmentsToReview.length)}`);
48
+ const reviewedSegmentsMap = /* @__PURE__ */ new Map();
49
+ for (const segment of segmentsToReview) {
50
+ const segmentNumber = segmentsToReview.indexOf(segment) + 1;
51
+ const englishBlock = segment.englishBlock;
52
+ const getBaseChunkContextPrompt = () => `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${(0, __intlayer_chokidar.formatLocale)(baseLocale, false)} as reference.\n///chunksStart///\n` + englishBlock.content + `///chunksEnd///`;
53
+ const getFrenchChunkPrompt = () => `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${(0, __intlayer_chokidar.formatLocale)(locale, false)}.\n///chunksStart///\n` + (segment.frenchBlockText ?? "") + `///chunksEnd///`;
54
+ const reviewedChunkResult = await (0, __intlayer_config.retryManager)(async () => {
55
+ const result = await require_utils_chunkInference.chunkInference([
56
+ {
57
+ role: "system",
58
+ content: basePrompt
59
+ },
60
+ {
61
+ role: "system",
62
+ content: getBaseChunkContextPrompt()
63
+ },
64
+ {
65
+ role: "system",
66
+ content: getFrenchChunkPrompt()
67
+ },
68
+ {
69
+ role: "system",
70
+ content: `The next user message will be the **BLOCK ${(0, __intlayer_config.colorizeNumber)(segmentNumber)} of ${(0, __intlayer_config.colorizeNumber)(segmentsToReview.length)}** that should be translated in ${(0, __intlayer_core.getLocaleName)(locale, __intlayer_types.Locales.ENGLISH)} (${locale}).`
71
+ },
72
+ {
73
+ role: "user",
74
+ content: englishBlock.content
75
+ }
76
+ ], aiOptions, configuration);
77
+ applicationLogger(`${prefix}${(0, __intlayer_config.colorizeNumber)(result.tokenUsed)} tokens used - Block ${(0, __intlayer_config.colorizeNumber)(segmentNumber)} of ${(0, __intlayer_config.colorizeNumber)(segmentsToReview.length)}`);
78
+ return require_utils_fixChunkStartEndChars.fixChunkStartEndChars(result?.fileContent, englishBlock.content);
79
+ })();
80
+ reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);
81
+ }
82
+ const finalFrenchOutput = require_translation_alignment_rebuildDocument.mergeReviewedSegments(plan, frenchBlocks, reviewedSegmentsMap);
83
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
84
+ (0, node_fs.writeFileSync)(outputFilePath, finalFrenchOutput);
85
+ applicationLogger(`${(0, __intlayer_config.colorize)("✔", __intlayer_config.ANSIColors.GREEN)} File ${(0, __intlayer_chokidar.formatPath)(outputFilePath)} created/updated successfully.`);
86
+ };
87
+
88
+ //#endregion
89
+ exports.reviewFileBlockAware = reviewFileBlockAware;
90
+ //# sourceMappingURL=reviewDocBlockAware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","buildAlignmentPlan","mergeReviewedSegments","chunkInference","Locales","fixChunkStartEndChars"],"sources":["../../src/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIOptions } from '@intlayer/api';\nimport { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from './translation-alignment/pipeline';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\n\n/**\n * Review a file using block-aware alignment.\n * This approach:\n * 1. Segments both English and French documents into semantic blocks\n * 2. Aligns blocks using structure (special chars, numbers) and context\n * 3. Detects which blocks changed, were added, or deleted\n * 4. Only sends changed/new blocks to AI for translation\n * 5. Handles reordering automatically\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[]\n) => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger(configuration);\n\n const englishText = await readFile(baseFilePath, 'utf-8');\n const frenchText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { englishBlocks, frenchBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n englishText,\n frenchText,\n changedLines,\n });\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: EN=${colorizeNumber(englishBlocks.length)}, FR=${colorizeNumber(frenchBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(plan.actions.filter((a) => a.kind === 'reuse').length)}, review=${colorizeNumber(plan.actions.filter((a) => a.kind === 'review').length)}, new=${colorizeNumber(plan.actions.filter((a) => a.kind === 'insert_new').length)}, delete=${colorizeNumber(plan.actions.filter((a) => a.kind === 'delete').length)}`\n );\n\n if (segmentsToReview.length === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(\n outputFilePath,\n mergeReviewedSegments(plan, frenchBlocks, new Map())\n );\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no changes needed).`\n );\n return;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Review segments that need AI translation\n const reviewedSegmentsMap = new Map<number, string>();\n\n for (const segment of segmentsToReview) {\n const segmentNumber = segmentsToReview.indexOf(segment) + 1;\n const englishBlock = segment.englishBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n englishBlock.content +\n `///chunksEnd///`;\n\n const getFrenchChunkPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.frenchBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getFrenchChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: englishBlock.content },\n ],\n aiOptions,\n configuration\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n const fixed = fixChunkStartEndChars(\n result?.fileContent,\n englishBlock.content\n );\n return fixed;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n }\n\n // Merge reviewed segments back into final document\n const finalFrenchOutput = mergeReviewedSegments(\n plan,\n frenchBlocks,\n reviewedSegmentsMap\n );\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, finalFrenchOutput);\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n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,aAAa,QACd;IAED,EAAE;AAEJ,sBAAoB,IAAI,QAAQ,aAAa,oBAAoB;;CAInE,MAAM,oBAAoBH,oEACxB,MACA,cACA,oBACD;AAED,+CAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,4BAAc,gBAAgB,kBAAkB;AAEhD,mBACE,mCAAY,KAAKF,6BAAW,MAAM,CAAC,4CAAmB,eAAe,CAAC,gCACvE"}
@@ -1,9 +1,7 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
3
3
  let __intlayer_chokidar = require("@intlayer/chokidar");
4
- __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
5
4
  let __intlayer_config = require("@intlayer/config");
6
- __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
7
5
 
8
6
  //#region src/test/index.ts
9
7
  const testMissingTranslations = async (options) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath, prepareIntlayer } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":";;;;;;;;AAoBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,iDAA0B,SAAS,cAAc;CACvD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,gDAAyB,QAAQ,EACrC,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;AAEF,KAAI,SAAS,U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D,WACE,yEACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,6BAAW;EAChB,OAAOA,6BAAW;EAClB,MAAMA,6BAAW;EAClB,CACF,GACF"}
1
+ {"version":3,"file":"index.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath, prepareIntlayer } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n\n translation.filePath ? ` - ${formatPath(translation.filePath)}` : '',\n translation.id ? ' - remote' : '',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":";;;;;;AAoBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,iDAA0B,SAAS,cAAc;CACvD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,gDAAyB,QAAQ,EACrC,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;AAEF,KAAI,SAAS,UAAU,KACrB,gDAAsB,QAAQ,EAAE,UAAU,MAAM,CAAC;UACxC,OAAO,SAAS,UAAU,YACnC,gDAAsB,OAAO;CAG/B,MAAM,SAASA,6DAAwB,SAAS,cAAc;CAE9D,MAAM,gBAAgB,OAAO,oBAC1B,KAAK,MAAM,MAAM,EAAE,MAAM,CACzB,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CACjD,MAAM,oBAAoB,OAAO,oBAC9B,KAAK,4CAAmB,EAAE,SAAS,MAAM,CAAC,CAC1C,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CAEjD,MAAM,+BAA+B,OAAO,oBAAoB,KAC7D,gBACC;+BACQ,yCAAkB,YAAY,IAAI,IAAI;GAC1C,SAAS;GACT,SAAS;GACV,CAAC;EACF;qEACmB,YAAY,SAASC,6BAAW,IAAI,EAAE;GACvD,SAAS;GACT,SAAS;GACV,CAAC;EAEF,YAAY,WAAW,0CAAiB,YAAY,SAAS,KAAK;EAClE,YAAY,KAAK,cAAc;EAChC,CAAC,KAAK,GAAG,CACb;AAED,WAAU,yBAAyB,EACjC,OAAO,QACR,CAAC;AAEF,8BAA6B,SAAS,MAAM;AAC1C,YAAU,GAAG,EACX,OAAO,QACR,CAAC;GACF;AAEF,WAAU,kDAAyB,QAAQ,GAAG;AAC9C,WAAU,2DAAkC,mBAAmB,QAAQ,GAAG;AAC1E,WACE,oBAAoB,OAAO,eAAe,WAAW,oCAAa,KAAKA,6BAAW,MAAM,yCAAgB,OAAO,gBAAgBA,6BAAW,IAAI,GAC/I;AAED,WACE,6BAA6B,OAAO,uBAAuB,WAAW,oCAAa,KAAKA,6BAAW,MAAM,yCAAgB,OAAO,wBAAwBA,6BAAW,IAAI,GACxK;AACD,WACE,gEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,6BAAW;EAChB,OAAOA,6BAAW;EAClB,MAAMA,6BAAW;EAClB,CAAC,GACH;AACD,WACE,yEACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,6BAAW;EAChB,OAAOA,6BAAW;EAClB,MAAMA,6BAAW;EAClB,CACF,GACF"}
@@ -1,12 +1,8 @@
1
1
  const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
2
  let __intlayer_config = require("@intlayer/config");
3
- __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
4
3
  let __intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
5
- __intlayer_unmerged_dictionaries_entry = require_rolldown_runtime.__toESM(__intlayer_unmerged_dictionaries_entry);
6
4
  let __intlayer_core = require("@intlayer/core");
7
- __intlayer_core = require_rolldown_runtime.__toESM(__intlayer_core);
8
5
  let __intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
9
- __intlayer_dictionaries_entry = require_rolldown_runtime.__toESM(__intlayer_dictionaries_entry);
10
6
 
11
7
  //#region src/test/listMissingTranslations.ts
12
8
  const listMissingTranslations = (configurationOptions) => {
@@ -1 +1 @@
1
- {"version":3,"file":"listMissingTranslations.cjs","names":["missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[]","dictionaries: Dictionary[]","multilingualDictionary: Dictionary[]","missingLocales"],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n const dictionariesKeys = Object.keys(unmergedDictionariesRecord);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // 2 - Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":";;;;;;;;;;;AASA,MAAa,2BACX,yBACG;CACH,MAAM,wDAAiC,qBAAqB;CAC5D,MAAM,iGAAqD,cAAc;CACzE,MAAM,wEAAqC,cAAc;CAEzD,MAAMA,sBAKA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAEnD,MAAM,mBAAmB,OAAO,KAAK,2BAA2B;AAEhE,MAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAMC,eACJ,2BAA2B;EAE7B,MAAMC,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,OAC7B;AAGD,OAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAMC,+EACJ,YACA,QACD;AAED,OAAIA,iBAAe,SAAS,EAC1B,qBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAASA;IACV,CAAC;;AAQN,MAJ0C,aAAa,QACpD,eAAe,WAAW,OAC5B,CAEuB,WAAW,EACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAMA,+EACJ,kBACA,QACD;AAED,MAAIA,iBAAe,SAAS,EAC1B,qBAAoB,KAAK;GACvB,KAAK;GACL,SAASA;GACV,CAAC;;CAIN,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SAAS,MAAM,EAAE,QAAQ,CAC9C;CACD,MAAM,iBAAiB,MAAM,KAAK,kBAAkB;AAMpD,QAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,SAAS,SAAS,OAAO,CAC9C;EAEqE"}
1
+ {"version":3,"file":"listMissingTranslations.cjs","names":["missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[]","dictionaries: Dictionary[]","multilingualDictionary: Dictionary[]","missingLocales"],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n const mergedDictionaries = getDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n id?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n const dictionariesKeys = Object.keys(unmergedDictionariesRecord);\n\n for (const dictionaryKey of dictionariesKeys) {\n const dictionaries: Dictionary[] =\n unmergedDictionariesRecord[dictionaryKey];\n\n const multilingualDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => !dictionary.locale\n );\n\n // 2 - Test all by merging all dictionaries to ensure no per-locale dictionary is missing\n for (const dictionary of multilingualDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n dictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: dictionary.id,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n const perLocaleDictionary: Dictionary[] = dictionaries.filter(\n (dictionary) => dictionary.locale\n );\n\n if (perLocaleDictionary.length === 0) {\n continue;\n }\n\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n locales: missingLocales,\n });\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":";;;;;;;AASA,MAAa,2BACX,yBACG;CACH,MAAM,wDAAiC,qBAAqB;CAC5D,MAAM,iGAAqD,cAAc;CACzE,MAAM,wEAAqC,cAAc;CAEzD,MAAMA,sBAKA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAEnD,MAAM,mBAAmB,OAAO,KAAK,2BAA2B;AAEhE,MAAK,MAAM,iBAAiB,kBAAkB;EAC5C,MAAMC,eACJ,2BAA2B;EAE7B,MAAMC,yBAAuC,aAAa,QACvD,eAAe,CAAC,WAAW,OAC7B;AAGD,OAAK,MAAM,cAAc,wBAAwB;GAC/C,MAAMC,+EACJ,YACA,QACD;AAED,OAAIA,iBAAe,SAAS,EAC1B,qBAAoB,KAAK;IACvB,KAAK;IACL,IAAI,WAAW;IACf,UAAU,WAAW;IACrB,SAASA;IACV,CAAC;;AAQN,MAJ0C,aAAa,QACpD,eAAe,WAAW,OAC5B,CAEuB,WAAW,EACjC;EAGF,MAAM,mBAAmB,mBAAmB;EAE5C,MAAMA,+EACJ,kBACA,QACD;AAED,MAAIA,iBAAe,SAAS,EAC1B,qBAAoB,KAAK;GACvB,KAAK;GACL,SAASA;GACV,CAAC;;CAIN,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SAAS,MAAM,EAAE,QAAQ,CAC9C;CACD,MAAM,iBAAiB,MAAM,KAAK,kBAAkB;AAMpD,QAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,SAAS,SAAS,OAAO,CAC9C;EAEqE"}
@@ -1,21 +1,16 @@
1
1
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_utils_checkAccess = require('./utils/checkAccess.cjs');
3
3
  const require__utils_asset = require('./_virtual/_utils_asset.cjs');
4
- const require_utils_calculateChunks = require('./utils/calculateChunks.cjs');
5
- const require_utils_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
6
4
  const require_utils_chunkInference = require('./utils/chunkInference.cjs');
7
5
  const require_utils_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
6
+ const require_utils_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
8
7
  const require_utils_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
8
+ const require_utils_calculateChunks = require('./utils/calculateChunks.cjs');
9
9
  let __intlayer_chokidar = require("@intlayer/chokidar");
10
- __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
11
10
  let __intlayer_config = require("@intlayer/config");
12
- __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
13
11
  let node_path = require("node:path");
14
- node_path = require_rolldown_runtime.__toESM(node_path);
15
12
  let node_fs = require("node:fs");
16
- node_fs = require_rolldown_runtime.__toESM(node_fs);
17
13
  let node_fs_promises = require("node:fs/promises");
18
- node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
19
14
  let fast_glob = require("fast-glob");
20
15
  fast_glob = require_rolldown_runtime.__toESM(fast_glob);
21
16
 
@@ -86,7 +81,7 @@ const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, c
86
81
  * Main translate function: scans all .md files in "en/" (unless you specified DOC_LIST),
87
82
  * then translates them to each locale in LOCALE_LIST.
88
83
  */
89
- const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, gitOptions }) => {
84
+ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions }) => {
90
85
  const configuration = (0, __intlayer_config.getConfiguration)(configOptions);
91
86
  const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
92
87
  if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
@@ -107,6 +102,11 @@ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLoca
107
102
  appLogger(`Translating file: ${(0, __intlayer_chokidar.formatPath)(docPath)} to ${(0, __intlayer_chokidar.formatLocale)(locale)}`);
108
103
  const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
109
104
  const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
105
+ if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) {
106
+ const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
107
+ appLogger(`${(0, __intlayer_config.colorize)("⊘", __intlayer_config.ANSIColors.YELLOW)} File ${(0, __intlayer_chokidar.formatPath)(relativePath)} already exists, skipping.`);
108
+ return;
109
+ }
110
110
  if (!(0, node_fs.existsSync)(outputFilePath)) {
111
111
  appLogger(`File ${outputFilePath} does not exist, creating it...`);
112
112
  (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
@@ -1 +1 @@
1
- {"version":3,"file":"translateDoc.cjs","names":["readAsset","ANSIColors","chunkText","chunkInference","fixChunkStartEndChars","docList: string[]","checkAIAccess","getOutputFilePath","checkFileModifiedRange"],"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n getChunk,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport type { IntlayerConfig, Locale, Locales } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n const chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n configuration,\n aiOptions,\n customInstructions\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,gBAAgB,OAC3B,cACA,gBACA,QACA,YACA,eACA,WACA,uBACG;AACH,KAAI;EACF,MAAM,gDAAyB,eAAe,EAC5C,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;EAGF,MAAM,cAAc,qCAAe,cAAc,QAAQ;EAEzD,IAAI,oBAAoB;EAGxB,MAAM,aAAaA,+BAAU,iCAAiC,QAAQ,CACnE,WAAW,kBAAkB,yC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AAQ,KAAK,EAAE,KAAK,KAAK,QAAQ,CACzE;;AAML,WAAU,wDAA+B,WAAW,GAAG;AACvD,WACE,qDAA8B,QAAQ,OAAO,CAAC,oDAA2B,QAAQ,CAAC,IACnF;AAED,WAAU,qDAA8B,QAAQ,OAAO,CAAC,SAAS;AACjE,WAAU,QAAQ,KAAK,SAAS,0CAAiB,KAAK,CAAC,IAAI,CAAC;AA6C5D,4CA1CiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;AAClC,YACE,yDAAgC,QAAQ,CAAC,4CAAmB,OAAO,GACpE;EAED,MAAM,2CAA4B,cAAc,QAAQ,SAAS,QAAQ;EACzE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,WACD;AAGD,MAAI,yBAAY,eAAe,EAAE;AAC/B,aAAU,QAAQ,eAAe,iCAAiC;AAClE,iDAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,8BAAc,gBAAgB,GAAG;;EAGnC,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;AAGF,QAAM,cACJ,sBACA,gBACA,QACA,YACA,eACA,WACA,mBACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
1
+ {"version":3,"file":"translateDoc.cjs","names":["readAsset","ANSIColors","chunkText","chunkInference","fixChunkStartEndChars","docList: string[]","checkAIAccess","getOutputFilePath","checkFileModifiedRange"],"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n getChunk,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport type { IntlayerConfig, Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n const chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n configuration,\n aiOptions,\n customInstructions\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,gBAAgB,OAC3B,cACA,gBACA,QACA,YACA,eACA,WACA,uBACG;AACH,KAAI;EACF,MAAM,gDAAyB,eAAe,EAC5C,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;EAGF,MA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AEjB,KAAI,YAAY;EACd,MAAM,kBAAkB,4CAAmB,WAAW;AAEtD,MAAI,gBAIF,WAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gCAAiB,QAAQ,KAAK,EAAE,KAAK,KAAK,QAAQ,CACzE;;AAML,WAAU,wDAA+B,WAAW,GAAG;AACvD,WACE,qDAA8B,QAAQ,OAAO,CAAC,oDAA2B,QAAQ,CAAC,IACnF;AAED,WAAU,qDAA8B,QAAQ,OAAO,CAAC,SAAS;AACjE,WAAU,QAAQ,KAAK,SAAS,0CAAiB,KAAK,CAAC,IAAI,CAAC;AAyD5D,4CAtDiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;AAClC,YACE,yDAAgC,QAAQ,CAAC,4CAAmB,OAAO,GACpE;EAED,MAAM,2CAA4B,cAAc,QAAQ,SAAS,QAAQ;EACzE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,WACD;AAGD,MAAI,wCAA2B,eAAe,EAAE;GAC9C,MAAM,uCACJ,cAAc,QAAQ,SACtB,eACD;AACD,aACE,mCAAY,KAAKN,6BAAW,OAAO,CAAC,4CAAmB,aAAa,CAAC,4BACtE;AACD;;AAIF,MAAI,yBAAY,eAAe,EAAE;AAC/B,aAAU,QAAQ,eAAe,iCAAiC;AAClE,iDAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,8BAAc,gBAAgB,GAAG;;EAGnC,MAAM,uBAAuBO,4DAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;AAGF,QAAM,cACJ,sBACA,gBACA,QACA,YACA,eACA,WACA,mBACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
@@ -0,0 +1,67 @@
1
+ const require_translation_alignment_computeSimilarity = require('./computeSimilarity.cjs');
2
+
3
+ //#region src/translation-alignment/alignBlocks.ts
4
+ const alignEnglishAndFrenchBlocks = (defaultBlocks, secondaryBlocks) => {
5
+ const defaultLength = defaultBlocks.length;
6
+ const secondaryLength = secondaryBlocks.length;
7
+ const scoreMatrix = Array.from({ length: defaultLength + 1 }, () => Array.from({ length: secondaryLength + 1 }, () => 0));
8
+ const traceMatrix = Array.from({ length: defaultLength + 1 }, () => Array.from({ length: secondaryLength + 1 }, () => "diagonal"));
9
+ const gapPenalty = -2;
10
+ const computeMatchScore = (defaultIndex, secondaryIndex) => {
11
+ const defaultBlock = defaultBlocks[defaultIndex];
12
+ const secondaryBlock = secondaryBlocks[secondaryIndex];
13
+ const typeBonus = defaultBlock.type === secondaryBlock.type ? 2 : 0;
14
+ const anchorSimilarity = require_translation_alignment_computeSimilarity.computeJaccardSimilarity(defaultBlock.anchorText, secondaryBlock.anchorText, 3);
15
+ return typeBonus + (Math.min(defaultBlock.content.length, secondaryBlock.content.length) / Math.max(defaultBlock.content.length, secondaryBlock.content.length) > .75 ? 1 : 0) + anchorSimilarity * 8;
16
+ };
17
+ for (let i$1 = 1; i$1 <= defaultLength; i$1 += 1) {
18
+ scoreMatrix[i$1][0] = scoreMatrix[i$1 - 1][0] + gapPenalty;
19
+ traceMatrix[i$1][0] = "up";
20
+ }
21
+ for (let j$1 = 1; j$1 <= secondaryLength; j$1 += 1) {
22
+ scoreMatrix[0][j$1] = scoreMatrix[0][j$1 - 1] + gapPenalty;
23
+ traceMatrix[0][j$1] = "left";
24
+ }
25
+ for (let i$1 = 1; i$1 <= defaultLength; i$1 += 1) for (let j$1 = 1; j$1 <= secondaryLength; j$1 += 1) {
26
+ const match = scoreMatrix[i$1 - 1][j$1 - 1] + computeMatchScore(i$1 - 1, j$1 - 1);
27
+ const deleteGap = scoreMatrix[i$1 - 1][j$1] + gapPenalty;
28
+ const insertGap = scoreMatrix[i$1][j$1 - 1] + gapPenalty;
29
+ const best = Math.max(match, deleteGap, insertGap);
30
+ scoreMatrix[i$1][j$1] = best;
31
+ traceMatrix[i$1][j$1] = best === match ? "diagonal" : best === deleteGap ? "up" : "left";
32
+ }
33
+ const result = [];
34
+ let i = defaultLength;
35
+ let j = secondaryLength;
36
+ while (i > 0 || j > 0) if (i > 0 && j > 0 && traceMatrix[i][j] === "diagonal") {
37
+ const englishIndex = i - 1;
38
+ const frenchIndex = j - 1;
39
+ const similarityScore = require_translation_alignment_computeSimilarity.computeJaccardSimilarity(defaultBlocks[englishIndex].anchorText, secondaryBlocks[frenchIndex].anchorText, 3);
40
+ result.unshift({
41
+ englishIndex,
42
+ frenchIndex,
43
+ similarityScore
44
+ });
45
+ i -= 1;
46
+ j -= 1;
47
+ } else if (i > 0 && (j === 0 || traceMatrix[i][j] === "up")) {
48
+ result.unshift({
49
+ englishIndex: i - 1,
50
+ frenchIndex: null,
51
+ similarityScore: 0
52
+ });
53
+ i -= 1;
54
+ } else if (j > 0 && (i === 0 || traceMatrix[i][j] === "left")) {
55
+ result.unshift({
56
+ englishIndex: -1,
57
+ frenchIndex: j - 1,
58
+ similarityScore: 0
59
+ });
60
+ j -= 1;
61
+ }
62
+ return result;
63
+ };
64
+
65
+ //#endregion
66
+ exports.alignEnglishAndFrenchBlocks = alignEnglishAndFrenchBlocks;
67
+ //# sourceMappingURL=alignBlocks.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alignBlocks.cjs","names":["scoreMatrix: number[][]","traceMatrix: ('diagonal' | 'up' | 'left')[][]","computeJaccardSimilarity","i","j","result: AlignmentPair[]"],"sources":["../../../src/translation-alignment/alignBlocks.ts"],"sourcesContent":["import { computeJaccardSimilarity } from './computeSimilarity';\nimport type { AlignmentPair, FingerprintedBlock } from './types';\n\nexport const alignEnglishAndFrenchBlocks = (\n defaultBlocks: FingerprintedBlock[],\n secondaryBlocks: FingerprintedBlock[]\n): AlignmentPair[] => {\n // Needleman–Wunsch style global alignment using anchor similarity and type equality\n const defaultLength = defaultBlocks.length;\n const secondaryLength = secondaryBlocks.length;\n\n const scoreMatrix: number[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 0)\n );\n const traceMatrix: ('diagonal' | 'up' | 'left')[][] = Array.from(\n { length: defaultLength + 1 },\n () => Array.from({ length: secondaryLength + 1 }, () => 'diagonal')\n );\n\n const gapPenalty = -2;\n\n const computeMatchScore = (\n defaultIndex: number,\n secondaryIndex: number\n ): number => {\n const defaultBlock = defaultBlocks[defaultIndex];\n const secondaryBlock = secondaryBlocks[secondaryIndex];\n const typeBonus = defaultBlock.type === secondaryBlock.type ? 2 : 0;\n const anchorSimilarity = computeJaccardSimilarity(\n defaultBlock.anchorText,\n secondaryBlock.anchorText,\n 3\n );\n const lengthRatio =\n Math.min(defaultBlock.content.length, secondaryBlock.content.length) /\n Math.max(defaultBlock.content.length, secondaryBlock.content.length);\n const lengthBonus = lengthRatio > 0.75 ? 1 : 0;\n return typeBonus + lengthBonus + anchorSimilarity * 8; // weighted toward anchor similarity\n };\n\n // initialize first row and column\n for (let i = 1; i <= defaultLength; i += 1) {\n scoreMatrix[i][0] = scoreMatrix[i - 1][0] + gapPenalty;\n traceMatrix[i][0] = 'up';\n }\n for (let j = 1; j <= secondaryLength; j += 1) {\n scoreMatrix[0][j] = scoreMatrix[0][j - 1] + gapPenalty;\n traceMatrix[0][j] = 'left';\n }\n\n // fill\n for (let i = 1; i <= defaultLength; i += 1) {\n for (let j = 1; j <= secondaryLength; j += 1) {\n const match = scoreMatrix[i - 1][j - 1] + computeMatchScore(i - 1, j - 1);\n const deleteGap = scoreMatrix[i - 1][j] + gapPenalty;\n const insertGap = scoreMatrix[i][j - 1] + gapPenalty;\n\n const best = Math.max(match, deleteGap, insertGap);\n scoreMatrix[i][j] = best;\n traceMatrix[i][j] =\n best === match ? 'diagonal' : best === deleteGap ? 'up' : 'left';\n }\n }\n\n // traceback\n const result: AlignmentPair[] = [];\n let i = defaultLength;\n let j = secondaryLength;\n while (i > 0 || j > 0) {\n if (i > 0 && j > 0 && traceMatrix[i][j] === 'diagonal') {\n const englishIndex = i - 1;\n const frenchIndex = j - 1;\n const similarityScore = computeJaccardSimilarity(\n defaultBlocks[englishIndex].anchorText,\n secondaryBlocks[frenchIndex].anchorText,\n 3\n );\n result.unshift({ englishIndex, frenchIndex, similarityScore });\n i -= 1;\n j -= 1;\n } else if (i > 0 && (j === 0 || traceMatrix[i][j] === 'up')) {\n result.unshift({\n englishIndex: i - 1,\n frenchIndex: null,\n similarityScore: 0,\n });\n i -= 1;\n } else if (j > 0 && (i === 0 || traceMatrix[i][j] === 'left')) {\n // french block has no corresponding english block (deleted)\n result.unshift({\n englishIndex: -1,\n frenchIndex: j - 1,\n similarityScore: 0,\n });\n j -= 1;\n }\n }\n return result;\n};\n"],"mappings":";;;AAGA,MAAa,+BACX,eACA,oBACoB;CAEpB,MAAM,gBAAgB,cAAc;CACpC,MAAM,kBAAkB,gBAAgB;CAExC,MAAMA,cAA0B,MAAM,KACpC,EAAE,QAAQ,gBAAgB,GAAG,QACvB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,GAAG,QAAQ,EAAE,CAC3D;CACD,MAAMC,cAAgD,MAAM,KAC1D,EAAE,QAAQ,gBAAgB,GAAG,QACvB,MAAM,KAAK,EAAE,QAAQ,kBAAkB,GAAG,QAAQ,WAAW,CACpE;CAED,MAAM,aAAa;CAEnB,MAAM,qBACJ,cACA,mBACW;EACX,MAAM,eAAe,cAAc;EACnC,MAAM,iBAAiB,gBAAgB;EACvC,MAAM,YAAY,aAAa,SAAS,eAAe,OAAO,IAAI;EAClE,MAAM,mBAAmBC,yEACvB,aAAa,YACb,eAAe,YACf,EACD;AAKD,SAAO,aAHL,KAAK,IAAI,aAAa,QAAQ,QAAQ,eAAe,QAAQ,OAAO,GACpE,KAAK,IAAI,aAAa,QAAQ,QAAQ,eAAe,QAAQ,OAAO,GACpC,MAAO,IAAI,KACZ,mBAAmB;;AAItD,MAAK,IAAIC,MAAI,GAAGA,OAAK,eAAe,OAAK,GAAG;AAC1C,cAAYA,KAAG,KAAK,YAAYA,MAAI,GAAG,KAAK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}
@@ -0,0 +1,25 @@
1
+
2
+ //#region src/translation-alignment/computeSimilarity.ts
3
+ const generateCharacterShingles = (text, shingleLength) => {
4
+ const normalized = text.replace(/\s+/g, " ").trim();
5
+ const set = /* @__PURE__ */ new Set();
6
+ if (normalized.length < shingleLength) {
7
+ if (normalized.length > 0) set.add(normalized);
8
+ return set;
9
+ }
10
+ for (let index = 0; index <= normalized.length - shingleLength; index += 1) set.add(normalized.slice(index, index + shingleLength));
11
+ return set;
12
+ };
13
+ const computeJaccardSimilarity = (a, b, shingleLength = 3) => {
14
+ const setA = generateCharacterShingles(a, shingleLength);
15
+ const setB = generateCharacterShingles(b, shingleLength);
16
+ if (setA.size === 0 && setB.size === 0) return 1;
17
+ const intersectionSize = Array.from(setA).filter((token) => setB.has(token)).length;
18
+ const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;
19
+ return unionSize === 0 ? 0 : intersectionSize / unionSize;
20
+ };
21
+
22
+ //#endregion
23
+ exports.computeJaccardSimilarity = computeJaccardSimilarity;
24
+ exports.generateCharacterShingles = generateCharacterShingles;
25
+ //# sourceMappingURL=computeSimilarity.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeSimilarity.cjs","names":[],"sources":["../../../src/translation-alignment/computeSimilarity.ts"],"sourcesContent":["// Character shingle Jaccard similarity (language agnostic)\nexport const generateCharacterShingles = (\n text: string,\n shingleLength: number\n): Set<string> => {\n const normalized = text.replace(/\\s+/g, ' ').trim();\n const set = new Set<string>();\n if (normalized.length < shingleLength) {\n if (normalized.length > 0) {\n set.add(normalized);\n }\n return set;\n }\n for (let index = 0; index <= normalized.length - shingleLength; index += 1) {\n set.add(normalized.slice(index, index + shingleLength));\n }\n return set;\n};\n\nexport const computeJaccardSimilarity = (\n a: string,\n b: string,\n shingleLength: number = 3\n): number => {\n const setA = generateCharacterShingles(a, shingleLength);\n const setB = generateCharacterShingles(b, shingleLength);\n if (setA.size === 0 && setB.size === 0) return 1;\n const intersectionSize = Array.from(setA).filter((token) =>\n setB.has(token)\n ).length;\n const unionSize = new Set([...Array.from(setA), ...Array.from(setB)]).size;\n return unionSize === 0 ? 0 : intersectionSize / unionSize;\n};\n"],"mappings":";;AACA,MAAa,6BACX,MACA,kBACgB;CAChB,MAAM,aAAa,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;CACnD,MAAM,sBAAM,IAAI,KAAa;AAC7B,KAAI,WAAW,SAAS,eAAe;AACrC,MAAI,WAAW,SAAS,EACtB,KAAI,IAAI,WAAW;AAErB,SAAO;;AAET,MAAK,IAAI,QAAQ,GAAG,SAAS,WAAW,SAAS,eAAe,SAAS,EACvE,KAAI,IAAI,WAAW,MAAM,OAAO,QAAQ,cAAc,CAAC;AAEzD,QAAO;;AAGT,MAAa,4BACX,GACA,GACA,gBAAwB,MACb;CACX,MAAM,OAAO,0BAA0B,GAAG,cAAc;CACxD,MAAM,OAAO,0BAA0B,GAAG,cAAc;AACxD,KAAI,KAAK,SAAS,KAAK,KAAK,SAAS,EAAG,QAAO;CAC/C,MAAM,mBAAmB,MAAM,KAAK,KAAK,CAAC,QAAQ,UAChD,KAAK,IAAI,MAAM,CAChB,CAAC;CACF,MAAM,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,KAAK,EAAE,GAAG,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC;AACtE,QAAO,cAAc,IAAI,IAAI,mBAAmB"}
@@ -0,0 +1,23 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let node_crypto = require("node:crypto");
3
+ node_crypto = require_rolldown_runtime.__toESM(node_crypto);
4
+
5
+ //#region src/translation-alignment/fingerprintBlock.ts
6
+ const computeStringDigest = (text) => node_crypto.default.createHash("sha256").update(text).digest("hex");
7
+ const fingerprintBlock = (block, previousBlock, nextBlock) => {
8
+ const semanticDigest = computeStringDigest(block.semanticText);
9
+ const anchorDigest = computeStringDigest(block.anchorText);
10
+ const compositeKey = `${semanticDigest}:${anchorDigest}`;
11
+ const contextKey = computeStringDigest(`${computeStringDigest(previousBlock?.semanticText ?? "")}:${computeStringDigest(nextBlock?.semanticText ?? "")}`);
12
+ return {
13
+ ...block,
14
+ semanticDigest,
15
+ anchorDigest,
16
+ compositeKey,
17
+ contextKey
18
+ };
19
+ };
20
+
21
+ //#endregion
22
+ exports.fingerprintBlock = fingerprintBlock;
23
+ //# sourceMappingURL=fingerprintBlock.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprintBlock.cjs","names":["crypto"],"sources":["../../../src/translation-alignment/fingerprintBlock.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport type { FingerprintedBlock, NormalizedBlock } from './types';\n\nconst computeStringDigest = (text: string): string =>\n crypto.createHash('sha256').update(text).digest('hex');\n\nexport const fingerprintBlock = (\n block: NormalizedBlock,\n previousBlock: NormalizedBlock | null,\n nextBlock: NormalizedBlock | null\n): FingerprintedBlock => {\n const semanticDigest = computeStringDigest(block.semanticText);\n const anchorDigest = computeStringDigest(block.anchorText);\n const compositeKey = `${semanticDigest}:${anchorDigest}`;\n\n const previousDigest = computeStringDigest(previousBlock?.semanticText ?? '');\n const nextDigest = computeStringDigest(nextBlock?.semanticText ?? '');\n const contextKey = computeStringDigest(`${previousDigest}:${nextDigest}`);\n\n return {\n ...block,\n semanticDigest,\n anchorDigest,\n compositeKey,\n contextKey,\n };\n};\n"],"mappings":";;;;;AAGA,MAAM,uBAAuB,SAC3BA,oBAAO,WAAW,SAAS,CAAC,OAAO,KAAK,CAAC,OAAO,MAAM;AAExD,MAAa,oBACX,OACA,eACA,cACuB;CACvB,MAAM,iBAAiB,oBAAoB,MAAM,aAAa;CAC9D,MAAM,eAAe,oBAAoB,MAAM,WAAW;CAC1D,MAAM,eAAe,GAAG,eAAe,GAAG;CAI1C,MAAM,aAAa,oBAAoB,GAFhB,oBAAoB,eAAe,gBAAgB,GAAG,CAEpB,GADtC,oBAAoB,WAAW,gBAAgB,GAAG,GACI;AAEzE,QAAO;EACL,GAAG;EACH;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,21 @@
1
+ const require_translation_alignment_computeSimilarity = require('./computeSimilarity.cjs');
2
+ const require_translation_alignment_alignBlocks = require('./alignBlocks.cjs');
3
+ const require_translation_alignment_fingerprintBlock = require('./fingerprintBlock.cjs');
4
+ const require_translation_alignment_mapChangedLinesToBlocks = require('./mapChangedLinesToBlocks.cjs');
5
+ const require_translation_alignment_normalizeBlock = require('./normalizeBlock.cjs');
6
+ const require_translation_alignment_planActions = require('./planActions.cjs');
7
+ const require_translation_alignment_rebuildDocument = require('./rebuildDocument.cjs');
8
+ const require_translation_alignment_segmentDocument = require('./segmentDocument.cjs');
9
+ const require_translation_alignment_pipeline = require('./pipeline.cjs');
10
+
11
+ exports.alignEnglishAndFrenchBlocks = require_translation_alignment_alignBlocks.alignEnglishAndFrenchBlocks;
12
+ exports.buildAlignmentPlan = require_translation_alignment_pipeline.buildAlignmentPlan;
13
+ exports.computeJaccardSimilarity = require_translation_alignment_computeSimilarity.computeJaccardSimilarity;
14
+ exports.fingerprintBlock = require_translation_alignment_fingerprintBlock.fingerprintBlock;
15
+ exports.generateCharacterShingles = require_translation_alignment_computeSimilarity.generateCharacterShingles;
16
+ exports.identifySegmentsToReview = require_translation_alignment_rebuildDocument.identifySegmentsToReview;
17
+ exports.mapChangedLinesToBlocks = require_translation_alignment_mapChangedLinesToBlocks.mapChangedLinesToBlocks;
18
+ exports.mergeReviewedSegments = require_translation_alignment_rebuildDocument.mergeReviewedSegments;
19
+ exports.normalizeBlock = require_translation_alignment_normalizeBlock.normalizeBlock;
20
+ exports.planAlignmentActions = require_translation_alignment_planActions.planAlignmentActions;
21
+ exports.segmentDocument = require_translation_alignment_segmentDocument.segmentDocument;
@@ -0,0 +1,18 @@
1
+
2
+ //#region src/translation-alignment/mapChangedLinesToBlocks.ts
3
+ const mapChangedLinesToBlocks = (blocks, changedLines) => {
4
+ const changedSet = /* @__PURE__ */ new Set();
5
+ if (!changedLines || changedLines.length === 0) return changedSet;
6
+ const changedLookup = new Set(changedLines);
7
+ blocks.forEach((block, index) => {
8
+ for (let line = block.lineStart; line <= block.lineEnd; line += 1) if (changedLookup.has(line)) {
9
+ changedSet.add(index);
10
+ break;
11
+ }
12
+ });
13
+ return changedSet;
14
+ };
15
+
16
+ //#endregion
17
+ exports.mapChangedLinesToBlocks = mapChangedLinesToBlocks;
18
+ //# sourceMappingURL=mapChangedLinesToBlocks.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapChangedLinesToBlocks.cjs","names":[],"sources":["../../../src/translation-alignment/mapChangedLinesToBlocks.ts"],"sourcesContent":["import type { Block, LineChange } from './types';\n\nexport const mapChangedLinesToBlocks = (\n blocks: Block[],\n changedLines: LineChange[]\n): Set<number> => {\n const changedSet = new Set<number>();\n if (!changedLines || changedLines.length === 0) return changedSet;\n\n const changedLookup = new Set<number>(changedLines);\n\n blocks.forEach((block, index) => {\n for (let line = block.lineStart; line <= block.lineEnd; line += 1) {\n if (changedLookup.has(line)) {\n changedSet.add(index);\n break;\n }\n }\n });\n\n return changedSet;\n};\n"],"mappings":";;AAEA,MAAa,2BACX,QACA,iBACgB;CAChB,MAAM,6BAAa,IAAI,KAAa;AACpC,KAAI,CAAC,gBAAgB,aAAa,WAAW,EAAG,QAAO;CAEvD,MAAM,gBAAgB,IAAI,IAAY,aAAa;AAEnD,QAAO,SAAS,OAAO,UAAU;AAC/B,OAAK,IAAI,OAAO,MAAM,WAAW,QAAQ,MAAM,SAAS,QAAQ,EAC9D,KAAI,cAAc,IAAI,KAAK,EAAE;AAC3B,cAAW,IAAI,MAAM;AACrB;;GAGJ;AAEF,QAAO"}
@@ -0,0 +1,22 @@
1
+
2
+ //#region src/translation-alignment/normalizeBlock.ts
3
+ const removeMarkdownFormatting = (text) => {
4
+ return text.replace(/`{1,3}[^`]*`{1,3}/g, " ").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/_([^_]+)_/g, "$1").replace(/~~([^~]+)~~/g, "$1").replace(/!?\[[^\]]*\]\([^)]*\)/g, " ").replace(/^\s*#{1,6}\s+/gm, "").replace(/^\s*>\s?/gm, "").replace(/^\s*[-*+]\s+/gm, "").replace(/^\s*\d+\.\s+/gm, "");
5
+ };
6
+ const collapseWhitespace = (text) => text.replace(/\s+/g, " ").trim();
7
+ const stripLettersKeepDigitsAndSymbols = (text) => {
8
+ return text.replace(/\p{L}+/gu, "");
9
+ };
10
+ const normalizeBlock = (block) => {
11
+ const semanticCollapsed = collapseWhitespace(removeMarkdownFormatting(block.content).toLowerCase());
12
+ const anchorCollapsed = collapseWhitespace(stripLettersKeepDigitsAndSymbols(block.content));
13
+ return {
14
+ ...block,
15
+ semanticText: semanticCollapsed,
16
+ anchorText: anchorCollapsed
17
+ };
18
+ };
19
+
20
+ //#endregion
21
+ exports.normalizeBlock = normalizeBlock;
22
+ //# sourceMappingURL=normalizeBlock.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeBlock.cjs","names":[],"sources":["../../../src/translation-alignment/normalizeBlock.ts"],"sourcesContent":["import type { Block, NormalizedBlock } from './types';\n\nconst removeMarkdownFormatting = (text: string): string => {\n return text\n .replace(/`{1,3}[^`]*`{1,3}/g, ' ')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '$1')\n .replace(/\\*([^*]+)\\*/g, '$1')\n .replace(/_([^_]+)_/g, '$1')\n .replace(/~~([^~]+)~~/g, '$1')\n .replace(/!?\\[[^\\]]*\\]\\([^)]*\\)/g, ' ')\n .replace(/^\\s*#{1,6}\\s+/gm, '')\n .replace(/^\\s*>\\s?/gm, '')\n .replace(/^\\s*[-*+]\\s+/gm, '')\n .replace(/^\\s*\\d+\\.\\s+/gm, '');\n};\n\nconst collapseWhitespace = (text: string): string =>\n text.replace(/\\s+/g, ' ').trim();\n\nconst stripLettersKeepDigitsAndSymbols = (text: string): string => {\n // Keep digits and non-letter characters, remove all letters (including accents)\n return text.replace(/\\p{L}+/gu, '');\n};\n\nexport const normalizeBlock = (block: Block): NormalizedBlock => {\n const contentWithoutMarkdown = removeMarkdownFormatting(block.content);\n const semanticLowercased = contentWithoutMarkdown.toLowerCase();\n const semanticCollapsed = collapseWhitespace(semanticLowercased);\n\n const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content);\n const anchorCollapsed = collapseWhitespace(anchorOnlySymbols);\n\n return {\n ...block,\n semanticText: semanticCollapsed,\n anchorText: anchorCollapsed,\n };\n};\n"],"mappings":";;AAEA,MAAM,4BAA4B,SAAyB;AACzD,QAAO,KACJ,QAAQ,sBAAsB,IAAI,CAClC,QAAQ,oBAAoB,KAAK,CACjC,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,cAAc,KAAK,CAC3B,QAAQ,gBAAgB,KAAK,CAC7B,QAAQ,0BAA0B,IAAI,CACtC,QAAQ,mBAAmB,GAAG,CAC9B,QAAQ,cAAc,GAAG,CACzB,QAAQ,kBAAkB,GAAG,CAC7B,QAAQ,kBAAkB,GAAG;;AAGlC,MAAM,sBAAsB,SAC1B,KAAK,QAAQ,QAAQ,IAAI,CAAC,MAAM;AAElC,MAAM,oCAAoC,SAAyB;AAEjE,QAAO,KAAK,QAAQ,YAAY,GAAG;;AAGrC,MAAa,kBAAkB,UAAkC;CAG/D,MAAM,oBAAoB,mBAFK,yBAAyB,MAAM,QAAQ,CACpB,aAAa,CACC;CAGhE,MAAM,kBAAkB,mBADE,iCAAiC,MAAM,QAAQ,CACZ;AAE7D,QAAO;EACL,GAAG;EACH,cAAc;EACd,YAAY;EACb"}
@@ -0,0 +1,37 @@
1
+ const require_translation_alignment_alignBlocks = require('./alignBlocks.cjs');
2
+ const require_translation_alignment_fingerprintBlock = require('./fingerprintBlock.cjs');
3
+ const require_translation_alignment_mapChangedLinesToBlocks = require('./mapChangedLinesToBlocks.cjs');
4
+ const require_translation_alignment_normalizeBlock = require('./normalizeBlock.cjs');
5
+ const require_translation_alignment_planActions = require('./planActions.cjs');
6
+ const require_translation_alignment_rebuildDocument = require('./rebuildDocument.cjs');
7
+ const require_translation_alignment_segmentDocument = require('./segmentDocument.cjs');
8
+
9
+ //#region src/translation-alignment/pipeline.ts
10
+ const buildAlignmentPlan = ({ englishText, frenchText, changedLines, similarityOptions }) => {
11
+ const englishBlocksRaw = require_translation_alignment_segmentDocument.segmentDocument(englishText);
12
+ const frenchBlocksRaw = require_translation_alignment_segmentDocument.segmentDocument(frenchText);
13
+ const englishNormalized = englishBlocksRaw.map(require_translation_alignment_normalizeBlock.normalizeBlock);
14
+ const frenchNormalized = frenchBlocksRaw.map(require_translation_alignment_normalizeBlock.normalizeBlock);
15
+ const englishBlocks = englishNormalized.map((block, index, array) => require_translation_alignment_fingerprintBlock.fingerprintBlock(block, array[index - 1] ?? null, array[index + 1] ?? null));
16
+ const frenchBlocks = frenchNormalized.map((block, index, array) => require_translation_alignment_fingerprintBlock.fingerprintBlock(block, array[index - 1] ?? null, array[index + 1] ?? null));
17
+ const plan = require_translation_alignment_planActions.planAlignmentActions(require_translation_alignment_alignBlocks.alignEnglishAndFrenchBlocks(englishBlocks, frenchBlocks), require_translation_alignment_mapChangedLinesToBlocks.mapChangedLinesToBlocks(englishBlocks, Array.isArray(changedLines) ? changedLines : []), {
18
+ minimumMatchForReuse: similarityOptions?.minimumMatchForReuse ?? .9,
19
+ minimumMatchForNearDuplicate: similarityOptions?.minimumMatchForNearDuplicate ?? .8
20
+ });
21
+ const { segmentsToReview } = require_translation_alignment_rebuildDocument.identifySegmentsToReview({
22
+ englishBlocks,
23
+ frenchBlocks,
24
+ plan
25
+ });
26
+ return {
27
+ englishBlocks,
28
+ frenchBlocks,
29
+ plan,
30
+ segmentsToReview
31
+ };
32
+ };
33
+
34
+ //#endregion
35
+ exports.buildAlignmentPlan = buildAlignmentPlan;
36
+ exports.mergeReviewedSegments = require_translation_alignment_rebuildDocument.mergeReviewedSegments;
37
+ //# sourceMappingURL=pipeline.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.cjs","names":["segmentDocument","normalizeBlock","englishBlocks: FingerprintedBlock[]","fingerprintBlock","frenchBlocks: FingerprintedBlock[]","planAlignmentActions","alignEnglishAndFrenchBlocks","mapChangedLinesToBlocks","identifySegmentsToReview"],"sources":["../../../src/translation-alignment/pipeline.ts"],"sourcesContent":["import { alignEnglishAndFrenchBlocks } from './alignBlocks';\nimport { fingerprintBlock } from './fingerprintBlock';\nimport { mapChangedLinesToBlocks } from './mapChangedLinesToBlocks';\nimport { normalizeBlock } from './normalizeBlock';\nimport { planAlignmentActions } from './planActions';\nimport {\n identifySegmentsToReview,\n mergeReviewedSegments,\n type SegmentToReview,\n} from './rebuildDocument';\nimport { segmentDocument } from './segmentDocument';\nimport type {\n AlignmentPlan,\n FingerprintedBlock,\n SimilarityOptions,\n} from './types';\n\nexport type BuildAlignmentPlanInput = {\n englishText: string;\n frenchText: string;\n changedLines: number[] | undefined;\n similarityOptions?: Partial<SimilarityOptions>;\n};\n\nexport type BuildAlignmentPlanOutput = {\n englishBlocks: FingerprintedBlock[];\n frenchBlocks: FingerprintedBlock[];\n plan: AlignmentPlan;\n segmentsToReview: SegmentToReview[];\n};\n\nexport const buildAlignmentPlan = ({\n englishText,\n frenchText,\n changedLines,\n similarityOptions,\n}: BuildAlignmentPlanInput): BuildAlignmentPlanOutput => {\n const englishBlocksRaw = segmentDocument(englishText);\n const frenchBlocksRaw = segmentDocument(frenchText);\n\n const englishNormalized = englishBlocksRaw.map(normalizeBlock);\n const frenchNormalized = frenchBlocksRaw.map(normalizeBlock);\n\n const englishBlocks: FingerprintedBlock[] = englishNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n const frenchBlocks: FingerprintedBlock[] = frenchNormalized.map(\n (block, index, array) =>\n fingerprintBlock(\n block,\n array[index - 1] ?? null,\n array[index + 1] ?? null\n )\n );\n\n const alignment = alignEnglishAndFrenchBlocks(englishBlocks, frenchBlocks);\n\n const changedIndexes = mapChangedLinesToBlocks(\n englishBlocks,\n Array.isArray(changedLines) ? changedLines : []\n );\n\n const plan = planAlignmentActions(alignment, changedIndexes, {\n minimumMatchForReuse: similarityOptions?.minimumMatchForReuse ?? 0.9,\n minimumMatchForNearDuplicate:\n similarityOptions?.minimumMatchForNearDuplicate ?? 0.8,\n });\n\n const { segmentsToReview } = identifySegmentsToReview({\n englishBlocks,\n frenchBlocks,\n plan,\n });\n\n return { englishBlocks, frenchBlocks, plan, segmentsToReview };\n};\n\nexport { mergeReviewedSegments };\nexport type { SegmentToReview };\n"],"mappings":";;;;;;;;;AA+BA,MAAa,sBAAsB,EACjC,aACA,YACA,cACA,wBACuD;CACvD,MAAM,mBAAmBA,8DAAgB,YAAY;CACrD,MAAM,kBAAkBA,8DAAgB,WAAW;CAEnD,MAAM,oBAAoB,iBAAiB,IAAIC,4DAAe;CAC9D,MAAM,mBAAmB,gBAAgB,IAAIA,4DAAe;CAE5D,MAAMC,gBAAsC,kBAAkB,KAC3D,OAAO,OAAO,UACbC,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,KACrB,CACJ;CACD,MAAMC,eAAqC,iBAAiB,KACzD,OAAO,OAAO,UACbD,gEACE,OACA,MAAM,QAAQ,MAAM,MACpB,MAAM,QAAQ,MAAM,KACrB,CACJ;CASD,MAAM,OAAOE,+DAPKC,sEAA4B,eAAe,aAAa,EAEnDC,8EACrB,eACA,MAAM,QAAQ,aAAa,GAAG,eAAe,EAAE,CAChD,EAE4D;EAC3D,sBAAsB,mBAAmB,wBAAwB;EACjE,8BACE,mBAAmB,gCAAgC;EACtD,CAAC;CAEF,MAAM,EAAE,qBAAqBC,uEAAyB;EACpD;EACA;EACA;EACD,CAAC;AAEF,QAAO;EAAE;EAAe;EAAc;EAAM;EAAkB"}