@intlayer/cli 8.4.4 → 8.4.6

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 (305) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +186 -1
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  4. package/dist/cjs/_virtual/_utils_asset.cjs +98 -0
  5. package/dist/cjs/auth/login.cjs +90 -2
  6. package/dist/cjs/auth/login.cjs.map +1 -1
  7. package/dist/cjs/build.cjs +30 -1
  8. package/dist/cjs/build.cjs.map +1 -1
  9. package/dist/cjs/ci.cjs +76 -1
  10. package/dist/cjs/ci.cjs.map +1 -1
  11. package/dist/cjs/cli.cjs +485 -1
  12. package/dist/cjs/cli.cjs.map +1 -1
  13. package/dist/cjs/config.cjs +15 -1
  14. package/dist/cjs/config.cjs.map +1 -1
  15. package/dist/cjs/editor.cjs +50 -1
  16. package/dist/cjs/editor.cjs.map +1 -1
  17. package/dist/cjs/extract.cjs +108 -1
  18. package/dist/cjs/extract.cjs.map +1 -1
  19. package/dist/cjs/fill/deepMergeContent.cjs +27 -1
  20. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  21. package/dist/cjs/fill/fill.cjs +89 -1
  22. package/dist/cjs/fill/fill.cjs.map +1 -1
  23. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +32 -1
  24. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  25. package/dist/cjs/fill/formatFillData.cjs +91 -1
  26. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  27. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +26 -1
  28. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  29. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +51 -1
  30. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  31. package/dist/cjs/fill/index.cjs +6 -1
  32. package/dist/cjs/fill/listTranslationsTasks.cjs +72 -1
  33. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  34. package/dist/cjs/fill/translateDictionary.cjs +241 -1
  35. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  36. package/dist/cjs/fill/writeFill.cjs +53 -1
  37. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  38. package/dist/cjs/getTargetDictionary.cjs +36 -1
  39. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  40. package/dist/cjs/index.cjs +44 -1
  41. package/dist/cjs/init.cjs +22 -1
  42. package/dist/cjs/init.cjs.map +1 -1
  43. package/dist/cjs/initMCP.cjs +69 -1
  44. package/dist/cjs/initMCP.cjs.map +1 -1
  45. package/dist/cjs/initSkills.cjs +93 -1
  46. package/dist/cjs/initSkills.cjs.map +1 -1
  47. package/dist/cjs/listContentDeclaration.cjs +42 -1
  48. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  49. package/dist/cjs/listProjects.cjs +28 -1
  50. package/dist/cjs/listProjects.cjs.map +1 -1
  51. package/dist/cjs/liveSync.cjs +153 -8
  52. package/dist/cjs/liveSync.cjs.map +1 -1
  53. package/dist/cjs/pull.cjs +153 -1
  54. package/dist/cjs/pull.cjs.map +1 -1
  55. package/dist/cjs/push/pullLog.cjs +105 -3
  56. package/dist/cjs/push/pullLog.cjs.map +1 -1
  57. package/dist/cjs/push/push.cjs +212 -1
  58. package/dist/cjs/push/push.cjs.map +1 -1
  59. package/dist/cjs/pushConfig.cjs +22 -1
  60. package/dist/cjs/pushConfig.cjs.map +1 -1
  61. package/dist/cjs/pushLog.cjs +86 -3
  62. package/dist/cjs/pushLog.cjs.map +1 -1
  63. package/dist/cjs/reviewDoc/reviewDoc.cjs +73 -1
  64. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  65. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +98 -1
  66. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  67. package/dist/cjs/searchDoc.cjs +41 -1
  68. package/dist/cjs/searchDoc.cjs.map +1 -1
  69. package/dist/cjs/test/index.cjs +7 -1
  70. package/dist/cjs/test/listMissingTranslations.cjs +66 -1
  71. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  72. package/dist/cjs/test/test.cjs +56 -1
  73. package/dist/cjs/test/test.cjs.map +1 -1
  74. package/dist/cjs/translateDoc/index.cjs +9 -1
  75. package/dist/cjs/translateDoc/translateDoc.cjs +79 -1
  76. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  77. package/dist/cjs/translateDoc/translateFile.cjs +106 -2
  78. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  79. package/dist/cjs/translateDoc/validation.cjs +49 -5
  80. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  81. package/dist/cjs/translation-alignment/alignBlocks.cjs +67 -1
  82. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
  83. package/dist/cjs/translation-alignment/computeSimilarity.cjs +25 -1
  84. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
  85. package/dist/cjs/translation-alignment/fingerprintBlock.cjs +23 -1
  86. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
  87. package/dist/cjs/translation-alignment/index.cjs +22 -1
  88. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +18 -1
  89. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
  90. package/dist/cjs/translation-alignment/normalizeBlock.cjs +22 -1
  91. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
  92. package/dist/cjs/translation-alignment/pipeline.cjs +37 -1
  93. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
  94. package/dist/cjs/translation-alignment/planActions.cjs +46 -1
  95. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
  96. package/dist/cjs/translation-alignment/rebuildDocument.cjs +49 -2
  97. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
  98. package/dist/cjs/translation-alignment/segmentDocument.cjs +66 -5
  99. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
  100. package/dist/cjs/utils/calculateChunks.cjs +89 -2
  101. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  102. package/dist/cjs/utils/checkAccess.cjs +83 -1
  103. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  104. package/dist/cjs/utils/checkConfigConsistency.cjs +16 -1
  105. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  106. package/dist/cjs/utils/checkFileModifiedRange.cjs +81 -1
  107. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  108. package/dist/cjs/utils/checkLastUpdateTime.cjs +19 -1
  109. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  110. package/dist/cjs/utils/chunkInference.cjs +45 -1
  111. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  112. package/dist/cjs/utils/fixChunkStartEndChars.cjs +27 -3
  113. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  114. package/dist/cjs/utils/formatTimeDiff.cjs +20 -1
  115. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  116. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +16 -1
  117. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  118. package/dist/cjs/utils/getOutputFilePath.cjs +108 -1
  119. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  120. package/dist/cjs/utils/getParentPackageJSON.cjs +20 -1
  121. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  122. package/dist/cjs/utils/listSpecialChars.cjs +54 -2
  123. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  124. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +102 -1
  125. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  126. package/dist/cjs/utils/openBrowser.cjs +19 -1
  127. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  128. package/dist/cjs/utils/reorderParagraphs.cjs +91 -3
  129. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  130. package/dist/cjs/utils/setupAI.cjs +66 -1
  131. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  132. package/dist/cjs/watch.cjs +47 -1
  133. package/dist/cjs/watch.cjs.map +1 -1
  134. package/dist/esm/IntlayerEventListener.mjs +183 -1
  135. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  136. package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
  137. package/dist/esm/_virtual/_utils_asset.mjs +97 -0
  138. package/dist/esm/auth/login.mjs +86 -2
  139. package/dist/esm/auth/login.mjs.map +1 -1
  140. package/dist/esm/build.mjs +28 -1
  141. package/dist/esm/build.mjs.map +1 -1
  142. package/dist/esm/ci.mjs +74 -1
  143. package/dist/esm/ci.mjs.map +1 -1
  144. package/dist/esm/cli.mjs +482 -1
  145. package/dist/esm/cli.mjs.map +1 -1
  146. package/dist/esm/config.mjs +13 -1
  147. package/dist/esm/config.mjs.map +1 -1
  148. package/dist/esm/editor.mjs +50 -1
  149. package/dist/esm/editor.mjs.map +1 -0
  150. package/dist/esm/extract.mjs +104 -1
  151. package/dist/esm/extract.mjs.map +1 -1
  152. package/dist/esm/fill/deepMergeContent.mjs +25 -1
  153. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  154. package/dist/esm/fill/fill.mjs +86 -1
  155. package/dist/esm/fill/fill.mjs.map +1 -1
  156. package/dist/esm/fill/formatAutoFilledFilePath.mjs +30 -1
  157. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  158. package/dist/esm/fill/formatFillData.mjs +89 -1
  159. package/dist/esm/fill/formatFillData.mjs.map +1 -1
  160. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs +24 -1
  161. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
  162. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +49 -1
  163. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  164. package/dist/esm/fill/index.mjs +4 -1
  165. package/dist/esm/fill/listTranslationsTasks.mjs +69 -1
  166. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  167. package/dist/esm/fill/translateDictionary.mjs +238 -1
  168. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  169. package/dist/esm/fill/writeFill.mjs +51 -1
  170. package/dist/esm/fill/writeFill.mjs.map +1 -1
  171. package/dist/esm/getTargetDictionary.mjs +33 -1
  172. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  173. package/dist/esm/index.mjs +20 -1
  174. package/dist/esm/init.mjs +19 -1
  175. package/dist/esm/init.mjs.map +1 -1
  176. package/dist/esm/initMCP.mjs +65 -1
  177. package/dist/esm/initMCP.mjs.map +1 -1
  178. package/dist/esm/initSkills.mjs +87 -1
  179. package/dist/esm/initSkills.mjs.map +1 -1
  180. package/dist/esm/listContentDeclaration.mjs +39 -1
  181. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  182. package/dist/esm/listProjects.mjs +26 -1
  183. package/dist/esm/listProjects.mjs.map +1 -1
  184. package/dist/esm/liveSync.mjs +150 -8
  185. package/dist/esm/liveSync.mjs.map +1 -1
  186. package/dist/esm/pull.mjs +150 -1
  187. package/dist/esm/pull.mjs.map +1 -1
  188. package/dist/esm/push/pullLog.mjs +102 -3
  189. package/dist/esm/push/pullLog.mjs.map +1 -1
  190. package/dist/esm/push/push.mjs +208 -1
  191. package/dist/esm/push/push.mjs.map +1 -1
  192. package/dist/esm/pushConfig.mjs +20 -1
  193. package/dist/esm/pushConfig.mjs.map +1 -1
  194. package/dist/esm/pushLog.mjs +83 -3
  195. package/dist/esm/pushLog.mjs.map +1 -1
  196. package/dist/esm/reviewDoc/reviewDoc.mjs +69 -1
  197. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  198. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +95 -1
  199. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  200. package/dist/esm/searchDoc.mjs +39 -1
  201. package/dist/esm/searchDoc.mjs.map +1 -1
  202. package/dist/esm/test/index.mjs +4 -1
  203. package/dist/esm/test/listMissingTranslations.mjs +63 -1
  204. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  205. package/dist/esm/test/test.mjs +53 -1
  206. package/dist/esm/test/test.mjs.map +1 -1
  207. package/dist/esm/translateDoc/index.mjs +5 -1
  208. package/dist/esm/translateDoc/translateDoc.mjs +75 -1
  209. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  210. package/dist/esm/translateDoc/translateFile.mjs +103 -2
  211. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  212. package/dist/esm/translateDoc/validation.mjs +46 -5
  213. package/dist/esm/translateDoc/validation.mjs.map +1 -1
  214. package/dist/esm/translation-alignment/alignBlocks.mjs +66 -1
  215. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
  216. package/dist/esm/translation-alignment/computeSimilarity.mjs +22 -1
  217. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
  218. package/dist/esm/translation-alignment/fingerprintBlock.mjs +20 -1
  219. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
  220. package/dist/esm/translation-alignment/index.mjs +11 -1
  221. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +16 -1
  222. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
  223. package/dist/esm/translation-alignment/normalizeBlock.mjs +20 -1
  224. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
  225. package/dist/esm/translation-alignment/pipeline.mjs +35 -1
  226. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
  227. package/dist/esm/translation-alignment/planActions.mjs +44 -1
  228. package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
  229. package/dist/esm/translation-alignment/rebuildDocument.mjs +46 -2
  230. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
  231. package/dist/esm/translation-alignment/segmentDocument.mjs +64 -5
  232. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
  233. package/dist/esm/utils/calculateChunks.mjs +87 -2
  234. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  235. package/dist/esm/utils/checkAccess.mjs +79 -1
  236. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  237. package/dist/esm/utils/checkConfigConsistency.mjs +14 -1
  238. package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
  239. package/dist/esm/utils/checkFileModifiedRange.mjs +80 -1
  240. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  241. package/dist/esm/utils/checkLastUpdateTime.mjs +17 -1
  242. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  243. package/dist/esm/utils/chunkInference.mjs +43 -1
  244. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  245. package/dist/esm/utils/fixChunkStartEndChars.mjs +25 -3
  246. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  247. package/dist/esm/utils/formatTimeDiff.mjs +18 -1
  248. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  249. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +14 -1
  250. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  251. package/dist/esm/utils/getOutputFilePath.mjs +104 -1
  252. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  253. package/dist/esm/utils/getParentPackageJSON.mjs +18 -1
  254. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  255. package/dist/esm/utils/listSpecialChars.mjs +52 -2
  256. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  257. package/dist/esm/utils/mapChunksBetweenFiles.mjs +100 -1
  258. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  259. package/dist/esm/utils/openBrowser.mjs +17 -1
  260. package/dist/esm/utils/openBrowser.mjs.map +1 -1
  261. package/dist/esm/utils/reorderParagraphs.mjs +90 -3
  262. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  263. package/dist/esm/utils/setupAI.mjs +63 -1
  264. package/dist/esm/utils/setupAI.mjs.map +1 -1
  265. package/dist/esm/watch.mjs +45 -1
  266. package/dist/esm/watch.mjs.map +1 -1
  267. package/dist/types/fill/fill.d.ts +1 -1
  268. package/dist/types/fill/fill.d.ts.map +1 -1
  269. package/dist/types/fill/formatFillData.d.ts.map +1 -1
  270. package/dist/types/fill/translateDictionary.d.ts +1 -1
  271. package/dist/types/getTargetDictionary.d.ts +19 -2
  272. package/dist/types/getTargetDictionary.d.ts.map +1 -0
  273. package/dist/types/index.d.ts +2 -2
  274. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -1
  275. package/dist/types/test/index.d.ts +2 -2
  276. package/dist/types/test/listMissingTranslations.d.ts +28 -2
  277. package/dist/types/test/listMissingTranslations.d.ts.map +1 -0
  278. package/dist/types/test/test.d.ts +11 -2
  279. package/dist/types/test/test.d.ts.map +1 -0
  280. package/dist/types/translateDoc/index.d.ts +1 -1
  281. package/dist/types/translateDoc/translateDoc.d.ts +1 -1
  282. package/dist/types/translateDoc/translateFile.d.ts +1 -1
  283. package/dist/types/translateDoc/types.d.ts +48 -2
  284. package/dist/types/translateDoc/types.d.ts.map +1 -0
  285. package/dist/types/utils/chunkInference.d.ts +1 -1
  286. package/dist/types/utils/getOutputFilePath.d.ts +18 -1
  287. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  288. package/dist/types/utils/setupAI.d.ts +21 -2
  289. package/dist/types/utils/setupAI.d.ts.map +1 -0
  290. package/package.json +12 -12
  291. package/dist/cjs/_utils_asset-ghp_Cjwk.cjs +0 -2
  292. package/dist/cjs/chunk-Bmb41Sf3.cjs +0 -1
  293. package/dist/esm/_utils_asset-B187VPMw.mjs +0 -2
  294. package/dist/esm/editor-D8BGlLzF.mjs +0 -2
  295. package/dist/esm/editor-D8BGlLzF.mjs.map +0 -1
  296. package/dist/types/getTargetDictionary-RBSRtaQj.d.ts +0 -19
  297. package/dist/types/getTargetDictionary-RBSRtaQj.d.ts.map +0 -1
  298. package/dist/types/listMissingTranslations-DxKw7nqI.d.ts +0 -28
  299. package/dist/types/listMissingTranslations-DxKw7nqI.d.ts.map +0 -1
  300. package/dist/types/setupAI-Bosjx7ah.d.ts +0 -21
  301. package/dist/types/setupAI-Bosjx7ah.d.ts.map +0 -1
  302. package/dist/types/test-DUTiJR5_.d.ts +0 -11
  303. package/dist/types/test-DUTiJR5_.d.ts.map +0 -1
  304. package/dist/types/types-BKvc3FmV.d.ts +0 -48
  305. package/dist/types/types-BKvc3FmV.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\n\ninterface SearchDocOptions {\n query: string;\n limit?: number;\n configOptions?: GetConfigurationOptions;\n}\n\nexport const searchDoc = async ({\n query,\n limit = 10,\n configOptions,\n}: SearchDocOptions) => {\n const config = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(config);\n\n try {\n const { searchDoc } = getSearchAPI(undefined, config);\n const response = await searchDoc({\n input: query,\n limit: limit.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n appLogger('No relevant chunks found.');\n return;\n }\n\n const chunks = response.data;\n\n appLogger(`Found ${colorizeNumber(chunks.length)} relevant chunks:`);\n\n chunks.forEach((chunk: any) => {\n appLogger('---');\n appLogger(`${colorizeKey('File')}: ${chunk.fileKey}`);\n appLogger(`${colorizeKey('Title')}: ${chunk.docName}`);\n appLogger(`${colorizeKey('URL')}: ${chunk.docUrl}`);\n appLogger(`${colorizeKey('Chunk')}: ${chunk.chunkNumber}`);\n appLogger(`${colorizeKey('Content')}:`);\n appLogger(chunk.content);\n });\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n appLogger(`Search failed: ${errorMessage}`, { level: 'error' });\n }\n};\n"],"mappings":"8OAkBA,MAAa,EAAY,MAAO,CAC9B,QACA,QAAQ,GACR,mBACsB,CACtB,IAAM,GAAA,EAAA,EAAA,kBAA0B,EAAc,EAC9C,EAAA,EAAA,kBAAiB,EAAc,CAE/B,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAO,CAEtC,GAAI,CACF,GAAM,CAAE,cAAA,EAAA,EAAA,cAA2B,IAAA,GAAW,EAAO,CAC/C,EAAW,MAAM,EAAU,CAC/B,MAAO,EACP,MAAO,EAAM,UAAU,CACvB,cAAe,OAChB,CAAC,CAEF,GAAI,CAAC,EAAS,MAAQ,CAAC,MAAM,QAAQ,EAAS,KAAK,CAAE,CACnD,EAAU,4BAA4B,CACtC,OAGF,IAAM,EAAS,EAAS,KAExB,EAAU,UAAA,EAAA,EAAA,gBAAwB,EAAO,OAAO,CAAC,mBAAmB,CAEpE,EAAO,QAAS,GAAe,CAC7B,EAAU,MAAM,CAChB,EAAU,IAAA,EAAA,EAAA,aAAe,OAAO,CAAC,IAAI,EAAM,UAAU,CACrD,EAAU,IAAA,EAAA,EAAA,aAAe,QAAQ,CAAC,IAAI,EAAM,UAAU,CACtD,EAAU,IAAA,EAAA,EAAA,aAAe,MAAM,CAAC,IAAI,EAAM,SAAS,CACnD,EAAU,IAAA,EAAA,EAAA,aAAe,QAAQ,CAAC,IAAI,EAAM,cAAc,CAC1D,EAAU,IAAA,EAAA,EAAA,aAAe,UAAU,CAAC,GAAG,CACvC,EAAU,EAAM,QAAQ,EACxB,OACK,EAAO,CAGd,EAAU,kBADR,aAAiB,MAAQ,EAAM,QAAU,8BACC,CAAE,MAAO,QAAS,CAAC"}
1
+ {"version":3,"file":"searchDoc.cjs","names":[],"sources":["../../src/searchDoc.ts"],"sourcesContent":["import { getSearchAPI } from '@intlayer/api';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\n\ninterface SearchDocOptions {\n query: string;\n limit?: number;\n configOptions?: GetConfigurationOptions;\n}\n\nexport const searchDoc = async ({\n query,\n limit = 10,\n configOptions,\n}: SearchDocOptions) => {\n const config = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(config);\n\n try {\n const { searchDoc } = getSearchAPI(undefined, config);\n const response = await searchDoc({\n input: query,\n limit: limit.toString(),\n returnContent: 'true',\n });\n\n if (!response.data || !Array.isArray(response.data)) {\n appLogger('No relevant chunks found.');\n return;\n }\n\n const chunks = response.data;\n\n appLogger(`Found ${colorizeNumber(chunks.length)} relevant chunks:`);\n\n chunks.forEach((chunk: any) => {\n appLogger('---');\n appLogger(`${colorizeKey('File')}: ${chunk.fileKey}`);\n appLogger(`${colorizeKey('Title')}: ${chunk.docName}`);\n appLogger(`${colorizeKey('URL')}: ${chunk.docUrl}`);\n appLogger(`${colorizeKey('Chunk')}: ${chunk.chunkNumber}`);\n appLogger(`${colorizeKey('Content')}:`);\n appLogger(chunk.content);\n });\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : 'An unknown error occurred';\n appLogger(`Search failed: ${errorMessage}`, { level: 'error' });\n }\n};\n"],"mappings":";;;;;;;;AAkBA,MAAa,YAAY,OAAO,EAC9B,OACA,QAAQ,IACR,oBACsB;CACtB,MAAM,qDAA0B,cAAc;AAC9C,8CAAiB,cAAc;CAE/B,MAAM,sDAAyB,OAAO;AAEtC,KAAI;EACF,MAAM,EAAE,8CAA2B,QAAW,OAAO;EACrD,MAAM,WAAW,MAAM,UAAU;GAC/B,OAAO;GACP,OAAO,MAAM,UAAU;GACvB,eAAe;GAChB,CAAC;AAEF,MAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,QAAQ,SAAS,KAAK,EAAE;AACnD,aAAU,4BAA4B;AACtC;;EAGF,MAAM,SAAS,SAAS;AAExB,YAAU,qDAAwB,OAAO,OAAO,CAAC,mBAAmB;AAEpE,SAAO,SAAS,UAAe;AAC7B,aAAU,MAAM;AAChB,aAAU,4CAAe,OAAO,CAAC,IAAI,MAAM,UAAU;AACrD,aAAU,4CAAe,QAAQ,CAAC,IAAI,MAAM,UAAU;AACtD,aAAU,4CAAe,MAAM,CAAC,IAAI,MAAM,SAAS;AACnD,aAAU,4CAAe,QAAQ,CAAC,IAAI,MAAM,cAAc;AAC1D,aAAU,4CAAe,UAAU,CAAC,GAAG;AACvC,aAAU,MAAM,QAAQ;IACxB;UACK,OAAO;AAGd,YAAU,kBADR,iBAAiB,QAAQ,MAAM,UAAU,+BACC,EAAE,OAAO,SAAS,CAAC"}
@@ -1 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./listMissingTranslations.cjs`),t=require(`./test.cjs`);exports.listMissingTranslations=e.listMissingTranslations,exports.listMissingTranslationsWithConfig=e.listMissingTranslationsWithConfig,exports.testMissingTranslations=t.testMissingTranslations;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
3
+ const require_test_test = require('./test.cjs');
4
+
5
+ exports.listMissingTranslations = require_test_listMissingTranslations.listMissingTranslations;
6
+ exports.listMissingTranslationsWithConfig = require_test_listMissingTranslations.listMissingTranslationsWithConfig;
7
+ exports.testMissingTranslations = require_test_test.testMissingTranslations;
@@ -1,2 +1,67 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../chunk-Bmb41Sf3.cjs`);let e=require(`@intlayer/chokidar/cli`),t=require(`@intlayer/config/node`),n=require(`@intlayer/unmerged-dictionaries-entry`),r=require(`@intlayer/core/plugins`),i=require(`@intlayer/dictionaries-entry`);const a=e=>{let t=(0,n.getUnmergedDictionaries)(e),a=(0,i.getDictionaries)(e),o=[],{locales:s,requiredLocales:c}=e.internationalization,l=Object.keys(t);for(let e of l){let n=t[e],i=n.filter(e=>!e.locale);for(let t of i){let n=(0,r.getMissingLocalesContentFromDictionary)(t,s);n.length>0&&o.push({key:e,id:t.id,filePath:t.filePath,locales:n})}if(n.filter(e=>e.locale).length===0)continue;let c=a[e],l=(0,r.getMissingLocalesContentFromDictionary)(c,s);l.length>0&&o.push({key:e,locales:l})}let u=new Set(o.flatMap(e=>e.locales)),d=Array.from(u);return{missingTranslations:o,missingLocales:d,missingRequiredLocales:d.filter(e=>(c??s).includes(e))}},o=n=>{let r=(0,t.getConfiguration)(n);return(0,e.logConfigDetails)(n),a(r)};exports.listMissingTranslations=o,exports.listMissingTranslationsWithConfig=a;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
4
+ let _intlayer_config_node = require("@intlayer/config/node");
5
+ let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
6
+ let _intlayer_core_plugins = require("@intlayer/core/plugins");
7
+ let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
8
+
9
+ //#region src/test/listMissingTranslations.ts
10
+ const listMissingTranslationsWithConfig = (configuration) => {
11
+ const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
12
+ const mergedDictionaries = (0, _intlayer_dictionaries_entry.getDictionaries)(configuration);
13
+ const missingTranslations = [];
14
+ const { locales, requiredLocales } = configuration.internationalization;
15
+ const dictionariesKeys = new Set([...Object.keys(unmergedDictionariesRecord), ...Object.keys(mergedDictionaries)]);
16
+ for (const dictionaryKey of dictionariesKeys) {
17
+ const dictionaries = unmergedDictionariesRecord[dictionaryKey] ?? [];
18
+ const multilingualDictionary = dictionaries.filter((dictionary) => !dictionary.locale);
19
+ for (const dictionary of multilingualDictionary) {
20
+ const missingLocales = (0, _intlayer_core_plugins.getMissingLocalesContentFromDictionary)(dictionary, locales);
21
+ if (missingLocales.length > 0) missingTranslations.push({
22
+ key: dictionaryKey,
23
+ id: dictionary.id,
24
+ filePath: dictionary.filePath,
25
+ locales: missingLocales
26
+ });
27
+ }
28
+ const perLocaleDictionary = dictionaries.filter((dictionary) => dictionary.locale);
29
+ if (dictionaries.length === 0) {
30
+ const mergedDictionary = mergedDictionaries[dictionaryKey];
31
+ if (mergedDictionary) {
32
+ const missingLocales = (0, _intlayer_core_plugins.getMissingLocalesContentFromDictionary)(mergedDictionary, locales);
33
+ if (missingLocales.length > 0) missingTranslations.push({
34
+ key: dictionaryKey,
35
+ id: mergedDictionary.id,
36
+ filePath: mergedDictionary.filePath,
37
+ locales: missingLocales
38
+ });
39
+ }
40
+ continue;
41
+ }
42
+ if (perLocaleDictionary.length === 0) continue;
43
+ const mergedDictionary = mergedDictionaries[dictionaryKey];
44
+ const missingLocales = (0, _intlayer_core_plugins.getMissingLocalesContentFromDictionary)(mergedDictionary, locales);
45
+ if (missingLocales.length > 0) missingTranslations.push({
46
+ key: dictionaryKey,
47
+ locales: missingLocales
48
+ });
49
+ }
50
+ const missingLocalesSet = new Set(missingTranslations.flatMap((missingTranslation) => missingTranslation.locales));
51
+ const missingLocales = Array.from(missingLocalesSet);
52
+ return {
53
+ missingTranslations,
54
+ missingLocales,
55
+ missingRequiredLocales: missingLocales.filter((locale) => (requiredLocales ?? locales).includes(locale))
56
+ };
57
+ };
58
+ const listMissingTranslations = (configurationOptions) => {
59
+ const configuration = (0, _intlayer_config_node.getConfiguration)(configurationOptions);
60
+ (0, _intlayer_chokidar_cli.logConfigDetails)(configurationOptions);
61
+ return listMissingTranslationsWithConfig(configuration);
62
+ };
63
+
64
+ //#endregion
65
+ exports.listMissingTranslations = listMissingTranslations;
66
+ exports.listMissingTranslationsWithConfig = listMissingTranslationsWithConfig;
2
67
  //# sourceMappingURL=listMissingTranslations.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\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 // 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\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":"gTAYA,MAAa,EACX,GACG,CACH,IAAM,GAAA,EAAA,EAAA,yBAAqD,EAAc,CACnE,GAAA,EAAA,EAAA,iBAAqC,EAAc,CAEnD,EAKA,EAAE,CAEF,CAAE,UAAS,mBAAoB,EAAc,qBAE7C,EAAmB,OAAO,KAAK,EAA2B,CAEhE,IAAK,IAAM,KAAiB,EAAkB,CAC5C,IAAM,EACJ,EAA2B,GAEvB,EAAuC,EAAa,OACvD,GAAe,CAAC,EAAW,OAC7B,CAGD,IAAK,IAAM,KAAc,EAAwB,CAC/C,IAAM,GAAA,EAAA,EAAA,wCACJ,EACA,EACD,CAEG,EAAe,OAAS,GAC1B,EAAoB,KAAK,CACvB,IAAK,EACL,GAAI,EAAW,GACf,SAAU,EAAW,SACrB,QAAS,EACV,CAAC,CAQN,GAJ0C,EAAa,OACpD,GAAe,EAAW,OAC5B,CAEuB,SAAW,EACjC,SAGF,IAAM,EAAmB,EAAmB,GAEtC,GAAA,EAAA,EAAA,wCACJ,EACA,EACD,CAEG,EAAe,OAAS,GAC1B,EAAoB,KAAK,CACvB,IAAK,EACL,QAAS,EACV,CAAC,CAIN,IAAM,EAAoB,IAAI,IAC5B,EAAoB,QAAS,GAAM,EAAE,QAAQ,CAC9C,CACK,EAAiB,MAAM,KAAK,EAAkB,CAMpD,MAAO,CAAE,sBAAqB,iBAAgB,uBAJf,EAAe,OAAQ,IACnD,GAAmB,GAAS,SAAS,EAAO,CAC9C,CAEqE,EAG3D,EACX,GACG,CACH,IAAM,GAAA,EAAA,EAAA,kBAAiC,EAAqB,CAG5D,OAFA,EAAA,EAAA,kBAAiB,EAAqB,CAE/B,EAAkC,EAAc"}
1
+ {"version":3,"file":"listMissingTranslations.cjs","names":[],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { getMissingLocalesContentFromDictionary } from '@intlayer/core/plugins';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslationsWithConfig = (\n configuration: IntlayerConfig\n) => {\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 // Use the union of keys from both unmerged and merged dictionaries so that\n // dictionaries compiled only as merged (no per-locale split) are still checked.\n const dictionariesKeys = new Set([\n ...Object.keys(unmergedDictionariesRecord),\n ...Object.keys(mergedDictionaries),\n ]);\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 // 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 there are no unmerged dictionaries for this key, fall back to the\n // merged dictionary directly (covers the case where the dict was compiled\n // as merged-only and unmerged_dictionaries.cjs is empty for this key).\n if (dictionaries.length === 0) {\n const mergedDictionary = mergedDictionaries[dictionaryKey];\n\n if (mergedDictionary) {\n const missingLocales = getMissingLocalesContentFromDictionary(\n mergedDictionary,\n locales\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionaryKey,\n id: mergedDictionary.id,\n filePath: mergedDictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n\n continue;\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(\n (missingTranslation) => missingTranslation.locales\n )\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\nexport const listMissingTranslations = (\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n logConfigDetails(configurationOptions);\n\n return listMissingTranslationsWithConfig(configuration);\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,qCACX,kBACG;CACH,MAAM,gGAAqD,cAAc;CACzE,MAAM,uEAAqC,cAAc;CAEzD,MAAM,sBAKA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;CAInD,M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object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`./listMissingTranslations.cjs`);let n=require(`@intlayer/chokidar/build`),r=require(`@intlayer/chokidar/utils`),i=require(`@intlayer/config/colors`);i=e.t(i);let a=require(`@intlayer/config/logger`),o=require(`@intlayer/config/node`);const s=async e=>{let s=(0,o.getConfiguration)(e?.configOptions),{locales:c,requiredLocales:l}=s.internationalization,u=(0,a.getAppLogger)(s);e?.build===!0?await(0,n.prepareIntlayer)(s,{forceRun:!0}):e?.build===void 0&&await(0,n.prepareIntlayer)(s);let d=t.listMissingTranslations(e?.configOptions),f=d.missingTranslations.map(e=>` - ${e.key}`).reduce((e,t)=>Math.max(e,t.length),0),p=d.missingTranslations.map(e=>(0,r.formatLocale)(e.locales,!1)).reduce((e,t)=>Math.max(e,t.length),0),m=d.missingTranslations.map(e=>[(0,a.colon)(` - ${(0,a.colorizeKey)(e.key)}`,{colSize:f,maxSize:40}),` - `,(0,a.colon)((0,r.formatLocale)(e.locales,i.RED),{colSize:p,maxSize:40}),e.filePath?` - ${(0,r.formatPath)(e.filePath)}`:``,e.id?` - remote`:``].join(``));u(`Missing translations:`,{level:`info`}),m.forEach(e=>{u(e,{level:`info`})}),u(`Locales: ${(0,r.formatLocale)(c)}`),u(`Required locales: ${(0,r.formatLocale)(l??c)}`),u(`Missing locales: ${d.missingLocales.length===0?(0,a.colorize)(`-`,i.GREEN):(0,r.formatLocale)(d.missingLocales,i.RED)}`),u(`Missing required locales: ${d.missingRequiredLocales.length===0?(0,a.colorize)(`-`,i.GREEN):(0,r.formatLocale)(d.missingRequiredLocales,i.RED)}`),u(`Total missing locales: ${(0,a.colorizeNumber)(d.missingLocales.length,{one:i.RED,other:i.RED,zero:i.GREEN})}`),u(`Total missing required locales: ${(0,a.colorizeNumber)(d.missingRequiredLocales.length,{one:i.RED,other:i.RED,zero:i.GREEN})}`),d.missingRequiredLocales.length>0&&process.exit(1)};exports.testMissingTranslations=s;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_test_listMissingTranslations = require('./listMissingTranslations.cjs');
4
+ let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
5
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
6
+ let _intlayer_config_colors = require("@intlayer/config/colors");
7
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
8
+ let _intlayer_config_logger = require("@intlayer/config/logger");
9
+ let _intlayer_config_node = require("@intlayer/config/node");
10
+
11
+ //#region src/test/test.ts
12
+ const testMissingTranslations = async (options) => {
13
+ const config = (0, _intlayer_config_node.getConfiguration)(options?.configOptions);
14
+ const { locales, requiredLocales } = config.internationalization;
15
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(config);
16
+ if (options?.build === true) await (0, _intlayer_chokidar_build.prepareIntlayer)(config, { forceRun: true });
17
+ else if (typeof options?.build === "undefined") await (0, _intlayer_chokidar_build.prepareIntlayer)(config);
18
+ const result = require_test_listMissingTranslations.listMissingTranslations(options?.configOptions);
19
+ const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
20
+ const maxLocalesColSize = result.missingTranslations.map((t) => (0, _intlayer_chokidar_utils.formatLocale)(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
21
+ const formattedMissingTranslations = result.missingTranslations.map((translation) => [
22
+ (0, _intlayer_config_logger.colon)(` - ${(0, _intlayer_config_logger.colorizeKey)(translation.key)}`, {
23
+ colSize: maxKeyColSize,
24
+ maxSize: 40
25
+ }),
26
+ " - ",
27
+ (0, _intlayer_config_logger.colon)((0, _intlayer_chokidar_utils.formatLocale)(translation.locales, _intlayer_config_colors.RED), {
28
+ colSize: maxLocalesColSize,
29
+ maxSize: 40
30
+ }),
31
+ translation.filePath ? ` - ${(0, _intlayer_chokidar_utils.formatPath)(translation.filePath)}` : "",
32
+ translation.id ? " - remote" : ""
33
+ ].join(""));
34
+ appLogger(`Missing translations:`, { level: "info" });
35
+ formattedMissingTranslations.forEach((t) => {
36
+ appLogger(t, { level: "info" });
37
+ });
38
+ appLogger(`Locales: ${(0, _intlayer_chokidar_utils.formatLocale)(locales)}`);
39
+ appLogger(`Required locales: ${(0, _intlayer_chokidar_utils.formatLocale)(requiredLocales ?? locales)}`);
40
+ appLogger(`Missing locales: ${result.missingLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0, _intlayer_chokidar_utils.formatLocale)(result.missingLocales, _intlayer_config_colors.RED)}`);
41
+ appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? (0, _intlayer_config_logger.colorize)("-", _intlayer_config_colors.GREEN) : (0, _intlayer_chokidar_utils.formatLocale)(result.missingRequiredLocales, _intlayer_config_colors.RED)}`);
42
+ appLogger(`Total missing locales: ${(0, _intlayer_config_logger.colorizeNumber)(result.missingLocales.length, {
43
+ one: _intlayer_config_colors.RED,
44
+ other: _intlayer_config_colors.RED,
45
+ zero: _intlayer_config_colors.GREEN
46
+ })}`);
47
+ appLogger(`Total missing required locales: ${(0, _intlayer_config_logger.colorizeNumber)(result.missingRequiredLocales.length, {
48
+ one: _intlayer_config_colors.RED,
49
+ other: _intlayer_config_colors.RED,
50
+ zero: _intlayer_config_colors.GREEN
51
+ })}`);
52
+ if (result.missingRequiredLocales.length > 0) process.exit(1);
53
+ };
54
+
55
+ //#endregion
56
+ exports.testMissingTranslations = testMissingTranslations;
2
57
  //# sourceMappingURL=test.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { listMissingTranslations } from './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\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 if (result.missingRequiredLocales.length > 0) {\n process.exit(1);\n }\n};\n"],"mappings":"iWAqBA,MAAa,EAA0B,KACrC,IACG,CACH,IAAM,GAAA,EAAA,EAAA,kBAA0B,GAAS,cAAc,CACjD,CAAE,UAAS,mBAAoB,EAAO,qBAEtC,GAAA,EAAA,EAAA,cAAyB,EAAO,CAElC,GAAS,QAAU,GACrB,MAAA,EAAA,EAAA,iBAAsB,EAAQ,CAAE,SAAU,GAAM,CAAC,CACjC,GAAS,QAAU,QACnC,MAAA,EAAA,EAAA,iBAAsB,EAAO,CAG/B,IAAM,EAASA,EAAAA,wBAAwB,GAAS,cAAc,CAExD,EAAgB,EAAO,oBAC1B,IAAK,GAAM,MAAM,EAAE,MAAM,CACzB,QAAQ,EAAK,IAAM,KAAK,IAAI,EAAK,EAAE,OAAO,CAAE,EAAE,CAC3C,EAAoB,EAAO,oBAC9B,IAAK,IAAA,EAAA,EAAA,cAAmB,EAAE,QAAS,GAAM,CAAC,CAC1C,QAAQ,EAAK,IAAM,KAAK,IAAI,EAAK,EAAE,OAAO,CAAE,EAAE,CAE3C,EAA+B,EAAO,oBAAoB,IAC7D,GACC,aACQ,OAAA,EAAA,EAAA,aAAkB,EAAY,IAAI,GAAI,CAC1C,QAAS,EACT,QAAS,GACV,CAAC,CACF,qCACmB,EAAY,QAASC,EAAW,IAAI,CAAE,CACvD,QAAS,EACT,QAAS,GACV,CAAC,CAEF,EAAY,SAAW,OAAA,EAAA,EAAA,YAAiB,EAAY,SAAS,GAAK,GAClE,EAAY,GAAK,YAAc,GAChC,CAAC,KAAK,GAAG,CACb,CAED,EAAU,wBAAyB,CACjC,MAAO,OACR,CAAC,CAEF,EAA6B,QAAS,GAAM,CAC1C,EAAU,EAAG,CACX,MAAO,OACR,CAAC,EACF,CAEF,EAAU,aAAA,EAAA,EAAA,cAAyB,EAAQ,GAAG,CAC9C,EAAU,sBAAA,EAAA,EAAA,cAAkC,GAAmB,EAAQ,GAAG,CAC1E,EACE,oBAAoB,EAAO,eAAe,SAAW,GAAA,EAAA,EAAA,UAAa,IAAKA,EAAW,MAAM,EAAA,EAAA,EAAA,cAAgB,EAAO,eAAgBA,EAAW,IAAI,GAC/I,CAED,EACE,6BAA6B,EAAO,uBAAuB,SAAW,GAAA,EAAA,EAAA,UAAa,IAAKA,EAAW,MAAM,EAAA,EAAA,EAAA,cAAgB,EAAO,uBAAwBA,EAAW,IAAI,GACxK,CACD,EACE,2BAAA,EAAA,EAAA,gBAAyC,EAAO,eAAe,OAAQ,CACrE,IAAKA,EAAW,IAChB,MAAOA,EAAW,IAClB,KAAMA,EAAW,MAClB,CAAC,GACH,CACD,EACE,oCAAA,EAAA,EAAA,gBACE,EAAO,uBAAuB,OAC9B,CACE,IAAKA,EAAW,IAChB,MAAOA,EAAW,IAClB,KAAMA,EAAW,MAClB,CACF,GACF,CAEG,EAAO,uBAAuB,OAAS,GACzC,QAAQ,KAAK,EAAE"}
1
+ {"version":3,"file":"test.cjs","names":["listMissingTranslations","ANSIColors"],"sources":["../../../src/test/test.ts"],"sourcesContent":["import { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { listMissingTranslations } from './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\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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WACE,6BAA6B,OAAO,uBAAuB,WAAW,0CAAa,KAAKA,wBAAW,MAAM,8CAAgB,OAAO,wBAAwBA,wBAAW,IAAI,GACxK;AACD,WACE,sEAAyC,OAAO,eAAe,QAAQ;EACrE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CAAC,GACH;AACD,WACE,+EACE,OAAO,uBAAuB,QAC9B;EACE,KAAKA,wBAAW;EAChB,OAAOA,wBAAW;EAClB,MAAMA,wBAAW;EAClB,CACF,GACF;AAED,KAAI,OAAO,uBAAuB,SAAS,EACzC,SAAQ,KAAK,EAAE"}
@@ -1 +1,9 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./validation.cjs`),t=require(`./translateFile.cjs`),n=require(`./translateDoc.cjs`);require(`./types.cjs`),exports.sanitizeChunk=e.sanitizeChunk,exports.translateDoc=n.translateDoc,exports.translateFile=t.translateFile,exports.validateTranslation=e.validateTranslation;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_translateDoc_validation = require('./validation.cjs');
3
+ const require_translateDoc_translateFile = require('./translateFile.cjs');
4
+ const require_translateDoc_translateDoc = require('./translateDoc.cjs');
5
+
6
+ exports.sanitizeChunk = require_translateDoc_validation.sanitizeChunk;
7
+ exports.translateDoc = require_translateDoc_translateDoc.translateDoc;
8
+ exports.translateFile = require_translateDoc_translateFile.translateFile;
9
+ exports.validateTranslation = require_translateDoc_validation.validateTranslation;
@@ -1,2 +1,80 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../utils/setupAI.cjs`),n=require(`../utils/checkFileModifiedRange.cjs`),r=require(`../utils/getOutputFilePath.cjs`),i=require(`./translateFile.cjs`);let a=require(`node:fs`),o=require(`node:path`),s=require(`@intlayer/chokidar/cli`),c=require(`@intlayer/chokidar/utils`),l=require(`@intlayer/config/colors`);l=e.t(l);let u=require(`@intlayer/config/logger`),d=require(`@intlayer/config/node`),f=require(`fast-glob`);f=e.t(f);let p=require(`node:perf_hooks`);const m=async({docPattern:e,locales:m,excludedGlobPattern:h,baseLocale:g,aiOptions:_,nbSimultaneousFileProcessed:v=20,configOptions:y,customInstructions:b,skipIfModifiedBefore:x,skipIfModifiedAfter:S,skipIfExists:C,gitOptions:w,flushStrategy:T=`incremental`})=>{let E=(0,d.getConfiguration)(y);(0,s.logConfigDetails)(y);let D=(0,u.getAppLogger)(E),O=v,k=(0,c.pLimit)(O),A=await(0,f.default)(e,{ignore:h}),j=await t.setupAI(E,_);if(!j?.hasAIAccess)return;let{aiClient:M,aiConfig:N}=j;if(w){let e=await(0,s.listGitFiles)(w);e&&(A=A.filter(t=>e.some(e=>(0,o.join)(process.cwd(),t)===e)))}let P=p.performance.now();D(`Translating ${(0,u.colorizeNumber)(A.length)} files to ${(0,u.colorizeNumber)(m.length)} locales. \nGlobal Concurrency: ${(0,u.colorizeNumber)(O)} chunks in parallel.`);let F={count:0,maxErrors:5,shouldStop:!1};await(0,c.parallelize)(A.flatMap(e=>m.map(t=>async()=>{if(F.shouldStop)return;let s=(0,o.join)(E.system.baseDir,e),c=r.getOutputFilePath(s,t,g);if(C&&(0,a.existsSync)(c))return;T===`incremental`&&!(0,a.existsSync)(c)&&((0,a.mkdirSync)((0,o.dirname)(c),{recursive:!0}),(0,a.writeFileSync)(c,``));let l=n.checkFileModifiedRange(c,{skipIfModifiedBefore:x,skipIfModifiedAfter:S});if(l.isSkipped){D(l.message);return}await i.translateFile({baseFilePath:s,outputFilePath:c,locale:t,baseLocale:g,configuration:E,errorState:F,aiOptions:_,customInstructions:b,aiClient:M,aiConfig:N,flushStrategy:T,limit:k})})),e=>e(),50);let I=((p.performance.now()-P)/1e3).toFixed(2);F.count>0?D(`Finished with ${F.count} errors in ${I}s.`):D(`${(0,u.colorize)(`✔`,l.GREEN)} Batch completed successfully in ${(0,u.colorizeNumber)(I)}s.`)};exports.translateDoc=m;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_utils_setupAI = require('../utils/setupAI.cjs');
4
+ const require_utils_getOutputFilePath = require('../utils/getOutputFilePath.cjs');
5
+ const require_utils_checkFileModifiedRange = require('../utils/checkFileModifiedRange.cjs');
6
+ const require_translateDoc_translateFile = require('./translateFile.cjs');
7
+ let node_fs = require("node:fs");
8
+ let node_path = require("node:path");
9
+ let _intlayer_chokidar_cli = require("@intlayer/chokidar/cli");
10
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
11
+ let _intlayer_config_colors = require("@intlayer/config/colors");
12
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
13
+ let _intlayer_config_logger = require("@intlayer/config/logger");
14
+ let _intlayer_config_node = require("@intlayer/config/node");
15
+ let fast_glob = require("fast-glob");
16
+ fast_glob = require_runtime.__toESM(fast_glob);
17
+ let node_perf_hooks = require("node:perf_hooks");
18
+
19
+ //#region src/translateDoc/translateDoc.ts
20
+ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed = 20, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions, flushStrategy = "incremental" }) => {
21
+ const configuration = (0, _intlayer_config_node.getConfiguration)(configOptions);
22
+ (0, _intlayer_chokidar_cli.logConfigDetails)(configOptions);
23
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration);
24
+ const maxConcurrentChunks = nbSimultaneousFileProcessed;
25
+ const globalChunkLimiter = (0, _intlayer_chokidar_utils.pLimit)(maxConcurrentChunks);
26
+ let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
27
+ const aiResult = await require_utils_setupAI.setupAI(configuration, aiOptions);
28
+ if (!aiResult?.hasAIAccess) return;
29
+ const { aiClient, aiConfig } = aiResult;
30
+ if (gitOptions) {
31
+ const gitChangedFiles = await (0, _intlayer_chokidar_cli.listGitFiles)(gitOptions);
32
+ if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
33
+ }
34
+ const batchStartTime = node_perf_hooks.performance.now();
35
+ appLogger(`Translating ${(0, _intlayer_config_logger.colorizeNumber)(docList.length)} files to ${(0, _intlayer_config_logger.colorizeNumber)(locales.length)} locales. \nGlobal Concurrency: ${(0, _intlayer_config_logger.colorizeNumber)(maxConcurrentChunks)} chunks in parallel.`);
36
+ const errorState = {
37
+ count: 0,
38
+ maxErrors: 5,
39
+ shouldStop: false
40
+ };
41
+ await (0, _intlayer_chokidar_utils.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
42
+ if (errorState.shouldStop) return;
43
+ const absoluteBaseFilePath = (0, node_path.join)(configuration.system.baseDir, docPath);
44
+ const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
45
+ if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) return;
46
+ if (flushStrategy === "incremental" && !(0, node_fs.existsSync)(outputFilePath)) {
47
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
48
+ (0, node_fs.writeFileSync)(outputFilePath, "");
49
+ }
50
+ const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
51
+ skipIfModifiedBefore,
52
+ skipIfModifiedAfter
53
+ });
54
+ if (fileModificationData.isSkipped) {
55
+ appLogger(fileModificationData.message);
56
+ return;
57
+ }
58
+ await require_translateDoc_translateFile.translateFile({
59
+ baseFilePath: absoluteBaseFilePath,
60
+ outputFilePath,
61
+ locale,
62
+ baseLocale,
63
+ configuration,
64
+ errorState,
65
+ aiOptions,
66
+ customInstructions,
67
+ aiClient,
68
+ aiConfig,
69
+ flushStrategy,
70
+ limit: globalChunkLimiter
71
+ });
72
+ })), (task) => task(), 50);
73
+ const batchDuration = ((node_perf_hooks.performance.now() - batchStartTime) / 1e3).toFixed(2);
74
+ if (errorState.count > 0) appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);
75
+ else appLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} Batch completed successfully in ${(0, _intlayer_config_logger.colorizeNumber)(batchDuration)}s.`);
76
+ };
77
+
78
+ //#endregion
79
+ exports.translateDoc = translateDoc;
2
80
  //# sourceMappingURL=translateDoc.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateDoc.cjs","names":["setupAI","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { listGitFiles, logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize, pLimit } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n const { aiClient, aiConfig } = aiResult;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // 2. FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\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 // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // 3. HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":"ikBAoBA,MAAa,EAAe,MAAO,CACjC,aACA,UACA,sBACA,aACA,YACA,8BAA8B,GAC9B,gBACA,qBACA,uBACA,sBACA,eACA,aACA,gBAAgB,iBACS,CACzB,IAAM,GAAA,EAAA,EAAA,kBAAiC,EAAc,EACrD,EAAA,EAAA,kBAAiB,EAAc,CAE/B,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAKvC,EAAsB,EACtB,GAAA,EAAA,EAAA,QAA4B,EAAoB,CAElD,EAAoB,MAAA,EAAA,EAAA,SAAS,EAAY,CAC3C,OAAQ,EACT,CAAC,CAEI,EAAW,MAAMA,EAAAA,QAAQ,EAAe,EAAU,CACxD,GAAI,CAAC,GAAU,YAAa,OAC5B,GAAM,CAAE,WAAU,YAAa,EAE/B,GAAI,EAAY,CACd,IAAM,EAAkB,MAAA,EAAA,EAAA,cAAmB,EAAW,CAClD,IACF,EAAU,EAAQ,OAAQ,GACxB,EAAgB,KAAM,IAAA,EAAA,EAAA,MAAiB,QAAQ,KAAK,CAAE,EAAK,GAAK,EAAQ,CACzE,EAIL,IAAM,EAAiBC,EAAAA,YAAY,KAAK,CAExC,EACE,gBAAA,EAAA,EAAA,gBAA8B,EAAQ,OAAO,CAAC,aAAA,EAAA,EAAA,gBAA2B,EAAQ,OAAO,CAAC,mCAAA,EAAA,EAAA,gBACjD,EAAoB,CAAC,sBAC9D,CAED,IAAM,EAAyB,CAC7B,MAAO,EACP,UAAW,EACX,WAAY,GACb,CAyDD,MAAA,EAAA,EAAA,aArDiB,EAAQ,QAAS,GAChC,EAAQ,IAAK,GAAW,SAAY,CAClC,GAAI,EAAW,WAAY,OAE3B,IAAM,GAAA,EAAA,EAAA,MAA4B,EAAc,OAAO,QAAS,EAAQ,CAClE,EAAiBC,EAAAA,kBACrB,EACA,EACA,EACD,CAGD,GAAI,IAAA,EAAA,EAAA,YAA2B,EAAe,CAAE,OAE5C,IAAkB,eAAiB,EAAA,EAAA,EAAA,YAAY,EAAe,IAChE,EAAA,EAAA,YAAA,EAAA,EAAA,SAAkB,EAAe,CAAE,CAAE,UAAW,GAAM,CAAC,EACvD,EAAA,EAAA,eAAc,EAAgB,GAAG,EAGnC,IAAM,EAAuBC,EAAAA,uBAAuB,EAAgB,CAClE,uBACA,sBACD,CAAC,CAEF,GAAI,EAAqB,UAAW,CAClC,EAAU,EAAqB,QAAQ,CACvC,OAIF,MAAMC,EAAAA,cAAc,CAClB,aAAc,EACd,iBACQ,SACR,aACA,gBACA,aACA,YACA,qBACA,WACA,WACA,gBACA,MAAO,EACR,CAAC,EACF,CACH,CAQ4B,GAAS,GAAM,CAFpB,GAEsC,CAG9D,IAAM,IADeH,EAAAA,YAAY,KAAK,CACC,GAAkB,KAAM,QAAQ,EAAE,CAErE,EAAW,MAAQ,EACrB,EAAU,iBAAiB,EAAW,MAAM,aAAa,EAAc,IAAI,CAE3E,EACE,IAAA,EAAA,EAAA,UAAY,IAAKI,EAAW,MAAM,CAAC,oCAAA,EAAA,EAAA,gBAAkD,EAAc,CAAC,IACrG"}
1
+ {"version":3,"file":"translateDoc.cjs","names":["setupAI","performance","getOutputFilePath","checkFileModifiedRange","translateFile","ANSIColors"],"sources":["../../../src/translateDoc/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { listGitFiles, logConfigDetails } from '@intlayer/chokidar/cli';\nimport { parallelize, pLimit } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport fg from 'fast-glob';\nimport { checkFileModifiedRange } from '../utils/checkFileModifiedRange';\nimport { getOutputFilePath } from '../utils/getOutputFilePath';\nimport { setupAI } from '../utils/setupAI';\nimport { translateFile } from './translateFile';\nimport type { ErrorState, TranslateDocOptions } from './types';\n\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed = 20, // Default to a higher concurrency for chunks\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n flushStrategy = 'incremental',\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n logConfigDetails(configOptions);\n\n const appLogger = getAppLogger(configuration);\n\n // 1. GLOBAL QUEUE SETUP\n // We use pLimit to create a single bottleneck for AI requests.\n // This queue is shared across all files and locales.\n const maxConcurrentChunks = nbSimultaneousFileProcessed;\n const globalChunkLimiter = pLimit(maxConcurrentChunks);\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n if (!aiResult?.hasAIAccess) return;\n const { aiClient, aiConfig } = aiResult;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n if (gitChangedFiles) {\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n const batchStartTime = performance.now();\n\n appLogger(\n `Translating ${colorizeNumber(docList.length)} files to ${colorizeNumber(locales.length)} locales. \\n` +\n `Global Concurrency: ${colorizeNumber(maxConcurrentChunks)} chunks in parallel.`\n );\n\n const errorState: ErrorState = {\n count: 0,\n maxErrors: 5,\n shouldStop: false,\n };\n\n // 2. FLATTENED TASK LIST\n // We create a task for every File x Locale combination.\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n if (errorState.shouldStop) return;\n\n const absoluteBaseFilePath = join(configuration.system.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip logic\n if (skipIfExists && existsSync(outputFilePath)) return;\n\n if (flushStrategy === 'incremental' && !existsSync(outputFilePath)) {\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 // Execute translation using the SHARED limiter\n await translateFile({\n baseFilePath: absoluteBaseFilePath,\n outputFilePath,\n locale: locale as Locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy,\n limit: globalChunkLimiter, // Pass the global queue\n });\n })\n );\n\n // 3. HIGH-THROUGHPUT FILE OPENER\n // We open many files simultaneously (e.g., 50) to ensure the global chunk queue\n // is always saturated with work.\n // If we open too few files, the chunk queue might drain faster than we can read new files.\n const FILE_OPEN_LIMIT = 50;\n\n await parallelize(allTasks, (task) => task(), FILE_OPEN_LIMIT);\n\n const batchEndTime = performance.now();\n const batchDuration = ((batchEndTime - batchStartTime) / 1000).toFixed(2);\n\n if (errorState.count > 0) {\n appLogger(`Finished with ${errorState.count} errors in ${batchDuration}s.`);\n } else {\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} Batch completed successfully in ${colorizeNumber(batchDuration)}s.`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,eAAe,OAAO,EACjC,YACA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Q;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,OAAO;GACR,CAAC;GACF,CACH,GAQ4B,SAAS,MAAM,EAFpB,GAEsC;CAG9D,MAAM,kBADeH,4BAAY,KAAK,GACC,kBAAkB,KAAM,QAAQ,EAAE;AAEzE,KAAI,WAAW,QAAQ,EACrB,WAAU,iBAAiB,WAAW,MAAM,aAAa,cAAc,IAAI;KAE3E,WACE,yCAAY,KAAKI,wBAAW,MAAM,CAAC,+EAAkD,cAAc,CAAC,IACrG"}
@@ -1,3 +1,107 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../chunk-Bmb41Sf3.cjs`),t=require(`../_utils_asset-ghp_Cjwk.cjs`),n=require(`./validation.cjs`),r=require(`../utils/chunkInference.cjs`),i=require(`../utils/fixChunkStartEndChars.cjs`),a=require(`../utils/calculateChunks.cjs`);let o=require(`node:fs`),s=require(`node:path`),c=require(`@intlayer/chokidar/utils`),l=require(`@intlayer/config/colors`);l=e.t(l);let u=require(`@intlayer/config/logger`),d=require(`@intlayer/config/utils`),f=require(`node:fs/promises`),p=require(`node:perf_hooks`);const m=async({baseFilePath:e,outputFilePath:m,locale:h,baseLocale:g,configuration:_,errorState:v,aiOptions:y,customInstructions:b,aiClient:x,aiConfig:S,flushStrategy:C=`incremental`,onChunkReceive:w,limit:T})=>{if(v.shouldStop)return null;let E=(0,u.getAppLogger)(_,{config:{prefix:``}}),D=p.performance.now();try{let O=a.chunkText(await(0,f.readFile)(e,`utf-8`)),k=O.length,A=`${(0,u.colon)(`${l.GREY_DARK}[${(0,c.formatPath)(e)}${l.GREY_DARK}] `,{colSize:40})}${l.RESET}`,j=`${(0,u.colon)(`${l.GREY_DARK}[${(0,c.formatPath)(e)}${l.GREY_DARK}][${(0,c.formatLocale)(h)}${l.GREY_DARK}] `,{colSize:40})}${l.RESET}`;E(`${A}Split into ${(0,u.colorizeNumber)(k)} chunks. Queuing...`);let M=t.t(`./prompts/TRANSLATE_PROMPT.md`,`utf-8`).replaceAll(`{{localeName}}`,`${(0,c.formatLocale)(h,!1)}`).replaceAll(`{{baseLocaleName}}`,`${(0,c.formatLocale)(g,!1)}`).replace(`{{applicationContext}}`,y?.applicationContext??`-`).replace(`{{customInstructions}}`,b??`-`),N=Array(k).fill(``),P=T??(e=>e()),F=O.map((e,t)=>P(async()=>{if(v.shouldStop)return null;let a=(0,u.getAppLogger)(_,{config:{prefix:`${j} ${l.GREY_DARK}[${t+1}/${k}] ${l.RESET}`}}),c=p.performance.now(),f=t===0,h=e.content,g=()=>">>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\n```\n"+(O[t-1]?.content??``)+"\n```\n>>> END PREVIOUS CONTEXT <<<",b=()=>">>> CONTEXT: NEXT CONTENT <<<\n```\n"+(O[t+1]?.content??``)+"\n```\n>>> END NEXT CONTEXT <<<";a(`Process started`);let{content:T,tokens:E}=await(0,d.retryManager)(async()=>{let e=await r.chunkInference([{role:`system`,content:M},...O[t+1]?[{role:`system`,content:b()}]:[],...f?[]:[{role:`system`,content:g()}],{role:`system`,content:[`You are translating TARGET CHUNK (${t+1}/${k}).`,`Translate ONLY the target chunk. Preserve frontmatter/code exactly.`].join(`
2
- `)},{role:`user`,content:`>>> TARGET CHUNK START <<<\n${h}\n>>> TARGET CHUNK END <<<`}],y,_,x,S),o=n.sanitizeChunk(e?.fileContent,h);if(o=i.fixChunkStartEndChars(o,h),!n.validateTranslation(h,o,a))throw Error(`Validation failed for chunk ${t+1}/${k}`);return{content:o,tokens:e.tokenUsed}})(),D=(p.performance.now()-c).toFixed(0);if(N[t]=T,w&&w(T,t,k),C===`incremental`&&N.slice(0,t+1).every(e=>e&&e!==``)){let e=0;for(;e<k&&N[e]&&N[e]!==``;)e++;let t=N.slice(0,e).join(``);(0,o.mkdirSync)((0,s.dirname)(m),{recursive:!0}),(0,o.writeFileSync)(m,t)}a([`${(0,u.colorizeNumber)(E)} tokens used `,`${l.GREY_DARK}in ${(0,u.colorizeNumber)(D)}ms${l.RESET}`].join(``))}));await Promise.all(F);let I=N.join(``);(C===`end`||C===`incremental`)&&((0,o.mkdirSync)((0,s.dirname)(m),{recursive:!0}),(0,o.writeFileSync)(m,I));let L=((p.performance.now()-D)/1e3).toFixed(2),R=(0,s.relative)(_.system.baseDir,m);return E(`${(0,u.colorize)(`✔`,l.GREEN)} File ${(0,c.formatPath)(R)} completed in ${(0,u.colorizeNumber)(L)}s.`),I}catch(e){v.count++;let t=e?.message??JSON.stringify(e);return E(`${(0,u.colorize)(`✖`,l.RED)} Error: ${t}`),v.count>=v.maxErrors&&(v.shouldStop=!0),null}};exports.translateFile=m;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require__utils_asset = require('../_virtual/_utils_asset.cjs');
4
+ const require_translateDoc_validation = require('./validation.cjs');
5
+ const require_utils_chunkInference = require('../utils/chunkInference.cjs');
6
+ const require_utils_fixChunkStartEndChars = require('../utils/fixChunkStartEndChars.cjs');
7
+ const require_utils_calculateChunks = require('../utils/calculateChunks.cjs');
8
+ let node_fs = require("node:fs");
9
+ let node_path = require("node:path");
10
+ let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
11
+ let _intlayer_config_colors = require("@intlayer/config/colors");
12
+ _intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
13
+ let _intlayer_config_logger = require("@intlayer/config/logger");
14
+ let _intlayer_config_utils = require("@intlayer/config/utils");
15
+ let node_fs_promises = require("node:fs/promises");
16
+ let node_perf_hooks = require("node:perf_hooks");
17
+
18
+ //#region src/translateDoc/translateFile.ts
19
+ const translateFile = async ({ baseFilePath, outputFilePath, locale, baseLocale, configuration, errorState, aiOptions, customInstructions, aiClient, aiConfig, flushStrategy = "incremental", onChunkReceive, limit }) => {
20
+ if (errorState.shouldStop) return null;
21
+ const appLogger = (0, _intlayer_config_logger.getAppLogger)(configuration, { config: { prefix: "" } });
22
+ const fileStartTime = node_perf_hooks.performance.now();
23
+ try {
24
+ const chunks = require_utils_calculateChunks.chunkText(await (0, node_fs_promises.readFile)(baseFilePath, "utf-8"));
25
+ const totalChunks = chunks.length;
26
+ const filePrefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_chokidar_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
27
+ const prefix = `${(0, _intlayer_config_logger.colon)(`${_intlayer_config_colors.GREY_DARK}[${(0, _intlayer_chokidar_utils.formatPath)(baseFilePath)}${_intlayer_config_colors.GREY_DARK}][${(0, _intlayer_chokidar_utils.formatLocale)(locale)}${_intlayer_config_colors.GREY_DARK}] `, { colSize: 40 })}${_intlayer_config_colors.RESET}`;
28
+ appLogger(`${filePrefix}Split into ${(0, _intlayer_config_logger.colorizeNumber)(totalChunks)} chunks. Queuing...`);
29
+ const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_chokidar_utils.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_chokidar_utils.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
30
+ const translatedParts = new Array(totalChunks).fill("");
31
+ const runTask = limit ?? ((fn) => fn());
32
+ const tasks = chunks.map((chunk, i) => runTask(async () => {
33
+ if (errorState.shouldStop) return null;
34
+ const chunkLogger = (0, _intlayer_config_logger.getAppLogger)(configuration, { config: { prefix: `${prefix} ${_intlayer_config_colors.GREY_DARK}[${i + 1}/${totalChunks}] ${_intlayer_config_colors.RESET}` } });
35
+ const chunkStartTime = node_perf_hooks.performance.now();
36
+ const isFirstChunk = i === 0;
37
+ const fileToTranslateCurrentChunk = chunk.content;
38
+ const getPrevChunkPrompt = () => `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\n\`\`\`\n` + (chunks[i - 1]?.content ?? "") + `\n\`\`\`\n>>> END PREVIOUS CONTEXT <<<`;
39
+ const getBaseChunkContextPrompt = () => `>>> CONTEXT: NEXT CONTENT <<<\n\`\`\`\n` + (chunks[i + 1]?.content ?? "") + `\n\`\`\`\n>>> END NEXT CONTEXT <<<`;
40
+ chunkLogger("Process started");
41
+ const { content: translatedChunk, tokens } = await (0, _intlayer_config_utils.retryManager)(async () => {
42
+ const result = await require_utils_chunkInference.chunkInference([
43
+ {
44
+ role: "system",
45
+ content: basePrompt
46
+ },
47
+ ...chunks[i + 1] ? [{
48
+ role: "system",
49
+ content: getBaseChunkContextPrompt()
50
+ }] : [],
51
+ ...isFirstChunk ? [] : [{
52
+ role: "system",
53
+ content: getPrevChunkPrompt()
54
+ }],
55
+ {
56
+ role: "system",
57
+ content: [`You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`, `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`].join("\n")
58
+ },
59
+ {
60
+ role: "user",
61
+ content: `>>> TARGET CHUNK START <<<\n${fileToTranslateCurrentChunk}\n>>> TARGET CHUNK END <<<`
62
+ }
63
+ ], aiOptions, configuration, aiClient, aiConfig);
64
+ let processedChunk = require_translateDoc_validation.sanitizeChunk(result?.fileContent, fileToTranslateCurrentChunk);
65
+ processedChunk = require_utils_fixChunkStartEndChars.fixChunkStartEndChars(processedChunk, fileToTranslateCurrentChunk);
66
+ if (!require_translateDoc_validation.validateTranslation(fileToTranslateCurrentChunk, processedChunk, chunkLogger)) throw new Error(`Validation failed for chunk ${i + 1}/${totalChunks}`);
67
+ return {
68
+ content: processedChunk,
69
+ tokens: result.tokenUsed
70
+ };
71
+ })();
72
+ const chunkDuration = (node_perf_hooks.performance.now() - chunkStartTime).toFixed(0);
73
+ translatedParts[i] = translatedChunk;
74
+ if (onChunkReceive) onChunkReceive(translatedChunk, i, totalChunks);
75
+ if (flushStrategy === "incremental") {
76
+ if (translatedParts.slice(0, i + 1).every((p) => p && p !== "")) {
77
+ let endIdx = 0;
78
+ while (endIdx < totalChunks && translatedParts[endIdx] && translatedParts[endIdx] !== "") endIdx++;
79
+ const currentContent = translatedParts.slice(0, endIdx).join("");
80
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
81
+ (0, node_fs.writeFileSync)(outputFilePath, currentContent);
82
+ }
83
+ }
84
+ chunkLogger([`${(0, _intlayer_config_logger.colorizeNumber)(tokens)} tokens used `, `${_intlayer_config_colors.GREY_DARK}in ${(0, _intlayer_config_logger.colorizeNumber)(chunkDuration)}ms${_intlayer_config_colors.RESET}`].join(""));
85
+ }));
86
+ await Promise.all(tasks);
87
+ const fullContent = translatedParts.join("");
88
+ if (flushStrategy === "end" || flushStrategy === "incremental") {
89
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
90
+ (0, node_fs.writeFileSync)(outputFilePath, fullContent);
91
+ }
92
+ const totalDuration = ((node_perf_hooks.performance.now() - fileStartTime) / 1e3).toFixed(2);
93
+ const relativePath = (0, node_path.relative)(configuration.system.baseDir, outputFilePath);
94
+ appLogger(`${(0, _intlayer_config_logger.colorize)("✔", _intlayer_config_colors.GREEN)} File ${(0, _intlayer_chokidar_utils.formatPath)(relativePath)} completed in ${(0, _intlayer_config_logger.colorizeNumber)(totalDuration)}s.`);
95
+ return fullContent;
96
+ } catch (error) {
97
+ errorState.count++;
98
+ const errorMessage = error?.message ?? JSON.stringify(error);
99
+ appLogger(`${(0, _intlayer_config_logger.colorize)("✖", _intlayer_config_colors.RED)} Error: ${errorMessage}`);
100
+ if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;
101
+ return null;
102
+ }
103
+ };
104
+
105
+ //#endregion
106
+ exports.translateFile = translateFile;
3
107
  //# sourceMappingURL=translateFile.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateFile.cjs","names":["performance","chunkText","ANSIColors","readAsset","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\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 translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":"mkBAoBA,MAAa,EAAgB,MAAO,CAClC,eACA,iBACA,SACA,aACA,gBACA,aACA,YACA,qBACA,WACA,WACA,gBAAgB,cAChB,iBACA,WACkD,CAClD,GAAI,EAAW,WAAY,OAAO,KAElC,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAe,CAAE,OAAQ,CAAE,OAAQ,GAAI,CAAE,CAAC,CACnE,EAAgBA,EAAAA,YAAY,KAAK,CAEvC,GAAI,CAEF,IAAM,EAASC,EAAAA,UADK,MAAA,EAAA,EAAA,UAAe,EAAc,QAAQ,CACpB,CAC/B,EAAc,EAAO,OAGrB,EAAa,IAAA,EAAA,EAAA,OADI,GAAGC,EAAW,UAAU,IAAA,EAAA,EAAA,YAAc,EAAa,GAAGA,EAAW,UAAU,IACtD,CAAE,QAAS,GAAI,CAAC,GAAGA,EAAW,QAEpE,EAAS,IAAA,EAAA,EAAA,OADI,GAAGA,EAAW,UAAU,IAAA,EAAA,EAAA,YAAc,EAAa,GAAGA,EAAW,UAAU,KAAA,EAAA,EAAA,cAAiB,EAAO,GAAGA,EAAW,UAAU,IAC1G,CAAE,QAAS,GAAI,CAAC,GAAGA,EAAW,QAElE,EACE,GAAG,EAAW,cAAA,EAAA,EAAA,gBAA4B,EAAY,CAAC,qBACxD,CAED,IAAM,EAAaC,EAAAA,EAAU,gCAAiC,QAAQ,CACnE,WAAW,iBAAkB,IAAA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C,SAAA,EAAA,EAAA,YAAmB,EAAa,CAAC,iBAAA,EAAA,EAAA,gBAA+B,EAAc,CAAC,IACnH,CAEM,QACA,EAAY,CACnB,EAAW,QACX,IAAM,EAAe,GAAO,SAAW,KAAK,UAAU,EAAM,CAG5D,OAFA,EAAU,IAAA,EAAA,EAAA,UAAY,IAAKA,EAAW,IAAI,CAAC,UAAU,IAAe,CAChE,EAAW,OAAS,EAAW,YAAW,EAAW,WAAa,IAC/D"}
1
+ {"version":3,"file":"translateFile.cjs","names":["performance","chunkText","ANSIColors","readAsset","chunkInference","sanitizeChunk","fixChunkStartEndChars","validateTranslation"],"sources":["../../../src/translateDoc/translateFile.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, relative } from 'node:path';\nimport { performance } from 'node:perf_hooks';\nimport { readAsset } from 'utils:asset';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport * as ANSIColors from '@intlayer/config/colors';\nimport {\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport { chunkText } from '../utils/calculateChunks';\nimport { chunkInference } from '../utils/chunkInference';\nimport { fixChunkStartEndChars } from '../utils/fixChunkStartEndChars';\nimport type { TranslateFileOptions } from './types';\nimport { sanitizeChunk, validateTranslation } from './validation';\n\nexport const translateFile = async ({\n baseFilePath,\n outputFilePath,\n locale,\n baseLocale,\n configuration,\n errorState,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig,\n flushStrategy = 'incremental',\n onChunkReceive,\n limit, // The Global Limiter\n}: TranslateFileOptions): Promise<string | null> => {\n if (errorState.shouldStop) return null;\n\n const appLogger = getAppLogger(configuration, { config: { prefix: '' } });\n const fileStartTime = performance.now();\n\n try {\n const fileContent = await readFile(baseFilePath, 'utf-8');\n const chunks = chunkText(fileContent);\n const totalChunks = chunks.length;\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = `${colon(filePrefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = `${colon(prefixText, { colSize: 40 })}${ANSIColors.RESET}`;\n\n appLogger(\n `${filePrefix}Split into ${colorizeNumber(totalChunks)} chunks. Queuing...`\n );\n\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 translatedParts: string[] = new Array(totalChunks).fill('');\n\n // Fallback if no limiter is provided (runs immediately)\n const runTask = limit ?? ((fn) => fn());\n\n // MAP CHUNKS TO GLOBAL TASKS\n // This pushes ALL chunks for this file into the Global Queue immediately.\n // They will execute whenever the global concurrency slots open up.\n const tasks = chunks.map((chunk, i) =>\n runTask(async () => {\n if (errorState.shouldStop) return null;\n\n const chunkLogger = getAppLogger(configuration, {\n config: {\n prefix: `${prefix} ${ANSIColors.GREY_DARK}[${i + 1}/${totalChunks}] ${ANSIColors.RESET}`,\n },\n });\n\n const chunkStartTime = performance.now();\n const isFirstChunk = i === 0;\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Context Preparation\n const getPrevChunkPrompt = () =>\n `>>> CONTEXT: PREVIOUS SOURCE CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i - 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END PREVIOUS CONTEXT <<<`;\n\n const getBaseChunkContextPrompt = () =>\n `>>> CONTEXT: NEXT CONTENT <<<\\n\\`\\`\\`\\n` +\n (chunks[i + 1]?.content ?? '') +\n `\\n\\`\\`\\`\\n>>> END NEXT CONTEXT <<<`;\n\n chunkLogger('Process started');\n\n const chunkTranslation = retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n ...(chunks[i + 1]\n ? [\n {\n role: 'system',\n content: getBaseChunkContextPrompt(),\n } as const,\n ]\n : []),\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: [\n `You are translating TARGET CHUNK (${i + 1}/${totalChunks}).`,\n `Translate ONLY the target chunk. Preserve frontmatter/code exactly.`,\n ].join('\\n'),\n },\n {\n role: 'user',\n content: `>>> TARGET CHUNK START <<<\\n${fileToTranslateCurrentChunk}\\n>>> TARGET CHUNK END <<<`,\n },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n let processedChunk = sanitizeChunk(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n processedChunk = fixChunkStartEndChars(\n processedChunk,\n fileToTranslateCurrentChunk\n );\n\n const isValid = validateTranslation(\n fileToTranslateCurrentChunk,\n processedChunk,\n chunkLogger\n );\n\n if (!isValid) {\n // Throwing an error here signals retryManager to try again\n throw new Error(\n `Validation failed for chunk ${i + 1}/${totalChunks}`\n );\n }\n\n return { content: processedChunk, tokens: result.tokenUsed };\n });\n\n const { content: translatedChunk, tokens } = await chunkTranslation();\n const chunkEndTime = performance.now();\n const chunkDuration = (chunkEndTime - chunkStartTime).toFixed(0);\n\n // Store Result\n translatedParts[i] = translatedChunk;\n\n if (onChunkReceive) {\n onChunkReceive(translatedChunk, i, totalChunks);\n }\n\n // Incremental Flush Strategy\n if (flushStrategy === 'incremental') {\n const isContiguous = translatedParts\n .slice(0, i + 1)\n .every((p) => p && p !== '');\n\n if (isContiguous) {\n let endIdx = 0;\n while (\n endIdx < totalChunks &&\n translatedParts[endIdx] &&\n translatedParts[endIdx] !== ''\n ) {\n endIdx++;\n }\n const currentContent = translatedParts.slice(0, endIdx).join('');\n // Write asynchronously/sync is fine here as node handles file locks reasonably well for single process\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, currentContent);\n }\n }\n\n chunkLogger(\n [\n `${colorizeNumber(tokens)} tokens used `,\n `${ANSIColors.GREY_DARK}in ${colorizeNumber(chunkDuration)}ms${ANSIColors.RESET}`,\n ].join('')\n );\n })\n );\n\n // Wait for all chunks for this specific file/locale to finish\n await Promise.all(tasks);\n\n // Final Flush\n const fullContent = translatedParts.join('');\n if (flushStrategy === 'end' || flushStrategy === 'incremental') {\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fullContent);\n }\n\n const fileEndTime = performance.now();\n const totalDuration = ((fileEndTime - fileStartTime) / 1000).toFixed(2);\n const relativePath = relative(configuration.system.baseDir, outputFilePath);\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} completed in ${colorizeNumber(totalDuration)}s.`\n );\n\n return fullContent;\n } catch (error: any) {\n errorState.count++;\n const errorMessage = error?.message ?? JSON.stringify(error);\n appLogger(`${colorize('✖', ANSIColors.RED)} Error: ${errorMessage}`);\n if (errorState.count >= errorState.maxErrors) errorState.shouldStop = true;\n return null;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAoBA,MAAa,gBAAgB,OAAO,EAClC,cACA,gBACA,QACA,YACA,eACA,YACA,WACA,oBACA,UACA,UACA,gBAAgB,eAChB,gBACA,YACkD;AAClD,KAAI,WAAW,WAAY,QAAO;CAElC,MAAM,sDAAyB,eAAe,EAAE,QAAQ,EAAE,QAAQ,IAAI,EAAE,CAAC;CACzE,MAAM,gBAAgBA,4BAAY,KAAK;AAEvC,KAAI;EAEF,MAAM,SAASC,wCADK,qCAAe,cAAc,QAAQ,CACpB;EACrC,MAAM,cAAc,OAAO;EAG3B,MAAM,aAAa,sCADI,GAAGC,wBAAW,UAAU,4CAAc,aAAa,GAAGA,wBAAW,UAAU,KACtD,EAAE,SAAS,IAAI,CAAC,GAAGA,wB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AgB,YAAY;;EAI5C,MAAM,kBADcF,4BAAY,KAAK,GACC,iBAAiB,KAAM,QAAQ,EAAE;EACvE,MAAM,uCAAwB,cAAc,OAAO,SAAS,eAAe;AAE3E,YACE,yCAAY,KAAKE,wBAAW,MAAM,CAAC,iDAAmB,aAAa,CAAC,4DAA+B,cAAc,CAAC,IACnH;AAED,SAAO;UACA,OAAY;AACnB,aAAW;EACX,MAAM,eAAe,OAAO,WAAW,KAAK,UAAU,MAAM;AAC5D,YAAU,yCAAY,KAAKA,wBAAW,IAAI,CAAC,UAAU,eAAe;AACpE,MAAI,WAAW,SAAS,WAAW,UAAW,YAAW,aAAa;AACtE,SAAO"}
@@ -1,6 +1,50 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=(e,t,n)=>{let r=[];if(e.trimStart().startsWith(`---`)){t.trimStart().startsWith(`---`)||r.push(`YAML Frontmatter missing: Input starts with "---", output does not.`);let n=(e.match(/^---$/gm)||[]).length,i=(t.match(/^---$/gm)||[]).length;n>=2&&i<2&&r.push(`YAML Frontmatter unclosed: Input has closing "---", output is missing it.`)}let i=/^\s*```/gm,a=(e.match(i)||[]).length,o=(t.match(i)||[]).length;a!==o&&r.push(`Code fence mismatch: Input has ${a}, output has ${o}`);let s=t.length/(e.length||1),c=s>2.5,l=e.length>50;c&&l&&r.push(`Length deviation: Output is ${t.length} chars vs Input ${e.length} (${s.toFixed(1)}x). Likely included context.`);let u=e.split(`
2
- `).length,d=t.split(`
3
- `).length;return u>5&&d<u*.4&&r.push(`Line count deviation: Output has ${d} lines, Input has ${u}. Likely content deletion.`),r.length>0?(n(`Validation Failed: ${r.join(`, `)}`),!1):!0},t=(e,t)=>{let n=e,r=n.match(/^```(?:markdown|md|txt)?\n([\s\S]*?)\n```$/i);return r&&(n=r[1]),!t.startsWith(`
4
- `)&&n.startsWith(`
5
- `)&&(n=n.replace(/^\n+/,``)),!t.startsWith(` `)&&n.startsWith(` `)&&(n=n.trimStart()),n};exports.sanitizeChunk=t,exports.validateTranslation=e;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/translateDoc/validation.ts
4
+ /**
5
+ * Validates that the translated content matches the structure of the original.
6
+ * Throws an error if a mismatch is found, triggering a retry.
7
+ */
8
+ const validateTranslation = (original, translated, logger) => {
9
+ const errors = [];
10
+ if (original.trimStart().startsWith("---")) {
11
+ if (!translated.trimStart().startsWith("---")) errors.push("YAML Frontmatter missing: Input starts with \"---\", output does not.");
12
+ const originalDashes = (original.match(/^---$/gm) || []).length;
13
+ const translatedDashes = (translated.match(/^---$/gm) || []).length;
14
+ if (originalDashes >= 2 && translatedDashes < 2) errors.push("YAML Frontmatter unclosed: Input has closing \"---\", output is missing it.");
15
+ }
16
+ const fenceRegex = /^\s*```/gm;
17
+ const originalFences = (original.match(fenceRegex) || []).length;
18
+ const translatedFences = (translated.match(fenceRegex) || []).length;
19
+ if (originalFences !== translatedFences) errors.push(`Code fence mismatch: Input has ${originalFences}, output has ${translatedFences}`);
20
+ const ratio = translated.length / (original.length || 1);
21
+ const isTooLong = ratio > 2.5;
22
+ const isSignificantLength = original.length > 50;
23
+ if (isTooLong && isSignificantLength) errors.push(`Length deviation: Output is ${translated.length} chars vs Input ${original.length} (${ratio.toFixed(1)}x). Likely included context.`);
24
+ const originalLines = original.split("\n").length;
25
+ const translatedLines = translated.split("\n").length;
26
+ if (originalLines > 5) {
27
+ if (translatedLines < originalLines * .4) errors.push(`Line count deviation: Output has ${translatedLines} lines, Input has ${originalLines}. Likely content deletion.`);
28
+ }
29
+ if (errors.length > 0) {
30
+ logger(`Validation Failed: ${errors.join(", ")}`);
31
+ return false;
32
+ }
33
+ return true;
34
+ };
35
+ /**
36
+ * Clean common AI artifacts
37
+ */
38
+ const sanitizeChunk = (translated, original) => {
39
+ let cleaned = translated;
40
+ const match = cleaned.match(/^```(?:markdown|md|txt)?\n([\s\S]*?)\n```$/i);
41
+ if (match) cleaned = match[1];
42
+ if (!original.startsWith("\n") && cleaned.startsWith("\n")) cleaned = cleaned.replace(/^\n+/, "");
43
+ if (!original.startsWith(" ") && cleaned.startsWith(" ")) cleaned = cleaned.trimStart();
44
+ return cleaned;
45
+ };
46
+
47
+ //#endregion
48
+ exports.sanitizeChunk = sanitizeChunk;
49
+ exports.validateTranslation = validateTranslation;
6
50
  //# sourceMappingURL=validation.cjs.map