@intlayer/cli 6.1.6 → 7.0.0-canary.0

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 (287) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +187 -239
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  4. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/cjs/build.cjs +23 -42
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/cli.cjs +370 -431
  8. package/dist/cjs/cli.cjs.map +1 -1
  9. package/dist/cjs/config.cjs +10 -35
  10. package/dist/cjs/config.cjs.map +1 -1
  11. package/dist/cjs/editor.cjs +51 -66
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/fill/fill.cjs +73 -301
  14. package/dist/cjs/fill/fill.cjs.map +1 -1
  15. package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
  16. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
  18. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  19. package/dist/cjs/fill/formatFillData.cjs +50 -0
  20. package/dist/cjs/fill/formatFillData.cjs.map +1 -0
  21. package/dist/cjs/fill/groupLimiter.cjs +42 -0
  22. package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
  23. package/dist/cjs/fill/index.cjs +5 -25
  24. package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
  25. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
  26. package/dist/cjs/fill/test-original-case.cjs +10 -0
  27. package/dist/cjs/fill/test-original-case.cjs.map +1 -0
  28. package/dist/cjs/fill/translateDictionary.cjs +148 -0
  29. package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
  30. package/dist/cjs/fill/writeAutoFill.cjs +48 -0
  31. package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
  32. package/dist/cjs/fill/writeFill.cjs +50 -0
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -0
  34. package/dist/cjs/getTargetDictionary.cjs +36 -76
  35. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  36. package/dist/cjs/index.cjs +31 -45
  37. package/dist/cjs/listContentDeclaration.cjs +36 -64
  38. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  39. package/dist/cjs/liveSync.cjs +146 -221
  40. package/dist/cjs/liveSync.cjs.map +1 -1
  41. package/dist/cjs/pull.cjs +132 -195
  42. package/dist/cjs/pull.cjs.map +1 -1
  43. package/dist/cjs/push/pullLog.cjs +101 -144
  44. package/dist/cjs/push/pullLog.cjs.map +1 -1
  45. package/dist/cjs/push/push.cjs +159 -249
  46. package/dist/cjs/push/push.cjs.map +1 -1
  47. package/dist/cjs/pushConfig.cjs +18 -45
  48. package/dist/cjs/pushConfig.cjs.map +1 -1
  49. package/dist/cjs/pushLog.cjs +87 -128
  50. package/dist/cjs/pushLog.cjs.map +1 -1
  51. package/dist/cjs/reviewDoc.cjs +183 -291
  52. package/dist/cjs/reviewDoc.cjs.map +1 -1
  53. package/dist/cjs/test/index.cjs +52 -91
  54. package/dist/cjs/test/index.cjs.map +1 -1
  55. package/dist/cjs/test/listMissingTranslations.cjs +35 -62
  56. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  57. package/dist/cjs/translateDoc.cjs +127 -221
  58. package/dist/cjs/translateDoc.cjs.map +1 -1
  59. package/dist/cjs/utils/calculateChunks.cjs +85 -115
  60. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  61. package/dist/cjs/utils/checkAccess.cjs +33 -72
  62. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  63. package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
  64. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  65. package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
  66. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  67. package/dist/cjs/utils/chunkInference.cjs +28 -47
  68. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  69. package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
  70. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  71. package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
  72. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  73. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
  74. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  75. package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
  76. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  77. package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
  78. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  79. package/dist/cjs/utils/listSpecialChars.cjs +49 -73
  80. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  81. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
  82. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  83. package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
  84. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  85. package/dist/cjs/watch.cjs +21 -39
  86. package/dist/cjs/watch.cjs.map +1 -1
  87. package/dist/esm/IntlayerEventListener.mjs +178 -201
  88. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  89. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  90. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  91. package/dist/esm/build.mjs +20 -23
  92. package/dist/esm/build.mjs.map +1 -1
  93. package/dist/esm/cli.mjs +349 -380
  94. package/dist/esm/cli.mjs.map +1 -1
  95. package/dist/esm/config.mjs +8 -14
  96. package/dist/esm/config.mjs.map +1 -1
  97. package/dist/esm/editor.mjs +47 -41
  98. package/dist/esm/editor.mjs.map +1 -1
  99. package/dist/esm/fill/fill.mjs +68 -300
  100. package/dist/esm/fill/fill.mjs.map +1 -1
  101. package/dist/esm/fill/formatAutoFillData.mjs +47 -81
  102. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
  103. package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
  104. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  105. package/dist/esm/fill/formatFillData.mjs +50 -0
  106. package/dist/esm/fill/formatFillData.mjs.map +1 -0
  107. package/dist/esm/fill/groupLimiter.mjs +40 -0
  108. package/dist/esm/fill/groupLimiter.mjs.map +1 -0
  109. package/dist/esm/fill/index.mjs +4 -3
  110. package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
  111. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
  112. package/dist/esm/fill/test-original-case.mjs +10 -0
  113. package/dist/esm/fill/test-original-case.mjs.map +1 -0
  114. package/dist/esm/fill/translateDictionary.mjs +141 -0
  115. package/dist/esm/fill/translateDictionary.mjs.map +1 -0
  116. package/dist/esm/fill/writeAutoFill.mjs +44 -0
  117. package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
  118. package/dist/esm/fill/writeFill.mjs +45 -0
  119. package/dist/esm/fill/writeFill.mjs.map +1 -0
  120. package/dist/esm/getTargetDictionary.mjs +27 -48
  121. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  122. package/dist/esm/index.mjs +15 -13
  123. package/dist/esm/listContentDeclaration.mjs +28 -43
  124. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/liveSync.mjs +135 -187
  126. package/dist/esm/liveSync.mjs.map +1 -1
  127. package/dist/esm/pull.mjs +125 -178
  128. package/dist/esm/pull.mjs.map +1 -1
  129. package/dist/esm/push/pullLog.mjs +99 -125
  130. package/dist/esm/push/pullLog.mjs.map +1 -1
  131. package/dist/esm/push/push.mjs +149 -221
  132. package/dist/esm/push/push.mjs.map +1 -1
  133. package/dist/esm/pushConfig.mjs +14 -23
  134. package/dist/esm/pushConfig.mjs.map +1 -1
  135. package/dist/esm/pushLog.mjs +85 -109
  136. package/dist/esm/pushLog.mjs.map +1 -1
  137. package/dist/esm/reviewDoc.mjs +167 -264
  138. package/dist/esm/reviewDoc.mjs.map +1 -1
  139. package/dist/esm/test/index.mjs +47 -73
  140. package/dist/esm/test/index.mjs.map +1 -1
  141. package/dist/esm/test/listMissingTranslations.mjs +30 -41
  142. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  143. package/dist/esm/translateDoc.mjs +114 -193
  144. package/dist/esm/translateDoc.mjs.map +1 -1
  145. package/dist/esm/utils/calculateChunks.mjs +83 -91
  146. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  147. package/dist/esm/utils/checkAccess.mjs +28 -46
  148. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  149. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
  150. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  151. package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
  152. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  153. package/dist/esm/utils/chunkInference.mjs +24 -24
  154. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  155. package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
  156. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  157. package/dist/esm/utils/formatTimeDiff.mjs +16 -19
  158. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  159. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
  160. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  161. package/dist/esm/utils/getOutputFilePath.mjs +70 -62
  162. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  163. package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
  164. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  165. package/dist/esm/utils/listSpecialChars.mjs +48 -49
  166. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  167. package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
  168. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  169. package/dist/esm/utils/reorderParagraphs.mjs +85 -93
  170. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  171. package/dist/esm/watch.mjs +17 -17
  172. package/dist/esm/watch.mjs.map +1 -1
  173. package/dist/types/IntlayerEventListener.d.ts +63 -59
  174. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  175. package/dist/types/build.d.ts +10 -7
  176. package/dist/types/build.d.ts.map +1 -1
  177. package/dist/types/cli.d.ts +13 -10
  178. package/dist/types/cli.d.ts.map +1 -1
  179. package/dist/types/config.d.ts +7 -4
  180. package/dist/types/config.d.ts.map +1 -1
  181. package/dist/types/editor.d.ts +6 -4
  182. package/dist/types/editor.d.ts.map +1 -1
  183. package/dist/types/fill/fill.d.ts +20 -14
  184. package/dist/types/fill/fill.d.ts.map +1 -1
  185. package/dist/types/fill/formatAutoFillData.d.ts +10 -7
  186. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
  187. package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
  188. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
  189. package/dist/types/fill/formatFillData.d.ts +12 -0
  190. package/dist/types/fill/formatFillData.d.ts.map +1 -0
  191. package/dist/types/fill/groupLimiter.d.ts +15 -0
  192. package/dist/types/fill/groupLimiter.d.ts.map +1 -0
  193. package/dist/types/fill/index.d.ts +3 -3
  194. package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
  195. package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
  196. package/dist/types/fill/test-original-case.d.ts +1 -0
  197. package/dist/types/fill/translateDictionary.d.ts +19 -0
  198. package/dist/types/fill/translateDictionary.d.ts.map +1 -0
  199. package/dist/types/fill/writeAutoFill.d.ts +7 -0
  200. package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
  201. package/dist/types/fill/writeFill.d.ts +7 -0
  202. package/dist/types/fill/writeFill.d.ts.map +1 -0
  203. package/dist/types/getTargetDictionary.d.ts +17 -13
  204. package/dist/types/getTargetDictionary.d.ts.map +1 -1
  205. package/dist/types/index.d.ts +15 -14
  206. package/dist/types/listContentDeclaration.d.ts +10 -7
  207. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  208. package/dist/types/liveSync.d.ts +8 -3
  209. package/dist/types/liveSync.d.ts.map +1 -1
  210. package/dist/types/pull.d.ts +9 -6
  211. package/dist/types/pull.d.ts.map +1 -1
  212. package/dist/types/push/pullLog.d.ts +25 -21
  213. package/dist/types/push/pullLog.d.ts.map +1 -1
  214. package/dist/types/push/push.d.ts +13 -9
  215. package/dist/types/push/push.d.ts.map +1 -1
  216. package/dist/types/pushConfig.d.ts +7 -4
  217. package/dist/types/pushConfig.d.ts.map +1 -1
  218. package/dist/types/pushLog.d.ts +23 -20
  219. package/dist/types/pushLog.d.ts.map +1 -1
  220. package/dist/types/reviewDoc.d.ts +34 -17
  221. package/dist/types/reviewDoc.d.ts.map +1 -1
  222. package/dist/types/test/index.d.ts +9 -5
  223. package/dist/types/test/index.d.ts.map +1 -1
  224. package/dist/types/test/listMissingTranslations.d.ts +14 -10
  225. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  226. package/dist/types/translateDoc.d.ts +34 -17
  227. package/dist/types/translateDoc.d.ts.map +1 -1
  228. package/dist/types/utils/calculateChunks.d.ts +10 -7
  229. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  230. package/dist/types/utils/checkAccess.d.ts +8 -4
  231. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  232. package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
  233. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  234. package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
  235. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  236. package/dist/types/utils/chunkInference.d.ts +9 -6
  237. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  238. package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
  239. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  240. package/dist/types/utils/formatTimeDiff.d.ts +4 -1
  241. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  242. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
  243. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  244. package/dist/types/utils/getOutputFilePath.d.ts +7 -2
  245. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  246. package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
  247. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  248. package/dist/types/utils/listSpecialChars.d.ts +9 -7
  249. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  250. package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
  251. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  252. package/dist/types/utils/reorderParagraphs.d.ts +4 -1
  253. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  254. package/dist/types/watch.d.ts +9 -6
  255. package/dist/types/watch.d.ts.map +1 -1
  256. package/package.json +42 -47
  257. package/LICENSE +0 -202
  258. package/dist/cjs/fill/autoFill.cjs +0 -105
  259. package/dist/cjs/fill/autoFill.cjs.map +0 -1
  260. package/dist/cjs/fill/index.cjs.map +0 -1
  261. package/dist/cjs/index.cjs.map +0 -1
  262. package/dist/cjs/utils/getChunk.cjs +0 -77
  263. package/dist/cjs/utils/getChunk.cjs.map +0 -1
  264. package/dist/cjs/utils/splitTextByLine.cjs +0 -35
  265. package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
  266. package/dist/esm/fill/autoFill.mjs +0 -92
  267. package/dist/esm/fill/autoFill.mjs.map +0 -1
  268. package/dist/esm/fill/index.mjs.map +0 -1
  269. package/dist/esm/index.mjs.map +0 -1
  270. package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
  271. package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
  272. package/dist/esm/utils/calculrateChunkTest.md +0 -9
  273. package/dist/esm/utils/getChunk.mjs +0 -53
  274. package/dist/esm/utils/getChunk.mjs.map +0 -1
  275. package/dist/esm/utils/splitTextByLine.mjs +0 -11
  276. package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
  277. package/dist/types/fill/autoFill.d.ts +0 -4
  278. package/dist/types/fill/autoFill.d.ts.map +0 -1
  279. package/dist/types/fill/index.d.ts.map +0 -1
  280. package/dist/types/index.d.ts.map +0 -1
  281. package/dist/types/utils/getChunk.d.ts +0 -9
  282. package/dist/types/utils/getChunk.d.ts.map +0 -1
  283. package/dist/types/utils/splitTextByLine.d.ts +0 -2
  284. package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
  285. /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
  286. /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
  287. /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
@@ -1,224 +1,130 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_utils_checkAccess = require('./utils/checkAccess.cjs');
3
+ const require__utils_asset = require('./_virtual/_utils_asset.cjs');
4
+ const require_utils_calculateChunks = require('./utils/calculateChunks.cjs');
5
+ const require_utils_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
6
+ const require_utils_chunkInference = require('./utils/chunkInference.cjs');
7
+ const require_utils_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
8
+ const require_utils_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
9
+ let __intlayer_chokidar = require("@intlayer/chokidar");
10
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
11
+ let __intlayer_config = require("@intlayer/config");
12
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
13
+ let node_path = require("node:path");
14
+ node_path = require_rolldown_runtime.__toESM(node_path);
15
+ let node_fs = require("node:fs");
16
+ node_fs = require_rolldown_runtime.__toESM(node_fs);
17
+ let node_fs_promises = require("node:fs/promises");
18
+ node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
19
+ let fast_glob = require("fast-glob");
20
+ fast_glob = require_rolldown_runtime.__toESM(fast_glob);
21
+
22
+ //#region src/translateDoc.ts
23
+ /**
24
+ * Translate a single file for a given locale
25
+ */
26
+ const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions) => {
27
+ try {
28
+ const appLogger = (0, __intlayer_config.getAppLogger)(configuration, { config: { prefix: "" } });
29
+ const fileContent = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
30
+ let fileResultContent = fileContent;
31
+ const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, __intlayer_chokidar.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, __intlayer_chokidar.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
32
+ const filePrefix = [(0, __intlayer_config.colon)(`${__intlayer_config.ANSIColors.GREY_DARK}[${(0, __intlayer_chokidar.formatPath)(baseFilePath)}${__intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${__intlayer_config.ANSIColors.RESET}`].join("");
33
+ const prefix = [(0, __intlayer_config.colon)(`${__intlayer_config.ANSIColors.GREY_DARK}[${(0, __intlayer_chokidar.formatPath)(baseFilePath)}${__intlayer_config.ANSIColors.GREY_DARK}][${(0, __intlayer_chokidar.formatLocale)(locale)}${__intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${__intlayer_config.ANSIColors.RESET}`].join("");
34
+ const chunks = require_utils_calculateChunks.chunkText(fileContent);
35
+ appLogger(`${filePrefix}Base file splitted into ${(0, __intlayer_config.colorizeNumber)(chunks.length)} chunks`);
36
+ for await (const [i, chunk] of chunks.entries()) {
37
+ const isFirstChunk = i === 0;
38
+ const getPrevChunkPrompt = () => `**CHUNK ${i} of ${chunks.length}** that has been translated in ${(0, __intlayer_chokidar.formatLocale)(locale)}:\n///chunkStart///` + (0, __intlayer_chokidar.getChunk)(fileResultContent, chunks[i - 1]) + `///chunkEnd///`;
39
+ const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${(0, __intlayer_chokidar.formatLocale)(baseLocale, false)} as reference.\n///chunksStart///` + (chunks[i - 1]?.content ?? "") + chunks[i].content + (chunks[i + 1]?.content ?? "") + `///chunksEnd///`;
40
+ const fileToTranslateCurrentChunk = chunk.content;
41
+ const chunkTranslation = await (0, __intlayer_config.retryManager)(async () => {
42
+ const result = await require_utils_chunkInference.chunkInference([
43
+ {
44
+ role: "system",
45
+ content: basePrompt
46
+ },
47
+ {
48
+ role: "system",
49
+ content: getBaseChunkContextPrompt()
50
+ },
51
+ ...isFirstChunk ? [] : [{
52
+ role: "system",
53
+ content: getPrevChunkPrompt()
54
+ }],
55
+ {
56
+ role: "system",
57
+ content: `The next user message will be the **CHUNK ${(0, __intlayer_config.colorizeNumber)(i + 1)} of ${(0, __intlayer_config.colorizeNumber)(chunks.length)}** in ${(0, __intlayer_chokidar.formatLocale)(baseLocale, false)} to translate in ${(0, __intlayer_chokidar.formatLocale)(locale, false)}:`
58
+ },
59
+ {
60
+ role: "user",
61
+ content: fileToTranslateCurrentChunk
62
+ }
63
+ ], aiOptions, configuration);
64
+ appLogger([
65
+ `${prefix}`,
66
+ `${__intlayer_config.ANSIColors.GREY_DARK}[Chunk `,
67
+ (0, __intlayer_config.colorizeNumber)(i + 1),
68
+ `${__intlayer_config.ANSIColors.GREY_DARK} of `,
69
+ (0, __intlayer_config.colorizeNumber)(chunks.length),
70
+ `${__intlayer_config.ANSIColors.GREY_DARK}] →${__intlayer_config.ANSIColors.RESET} `,
71
+ `${(0, __intlayer_config.colorizeNumber)(result.tokenUsed)} tokens used`
72
+ ].join(""));
73
+ return require_utils_fixChunkStartEndChars.fixChunkStartEndChars(result?.fileContent, fileToTranslateCurrentChunk);
74
+ })();
75
+ fileResultContent = fileResultContent.replace(fileToTranslateCurrentChunk, chunkTranslation);
76
+ }
77
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
78
+ (0, node_fs.writeFileSync)(outputFilePath, fileResultContent);
79
+ const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
80
+ appLogger(`${(0, __intlayer_config.colorize)("✔", __intlayer_config.ANSIColors.GREEN)} File ${(0, __intlayer_chokidar.formatPath)(relativePath)} created/updated successfully.`);
81
+ } catch (error) {
82
+ console.error(error);
83
+ }
11
84
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
85
+ /**
86
+ * Main translate function: scans all .md files in "en/" (unless you specified DOC_LIST),
87
+ * then translates them to each locale in LOCALE_LIST.
88
+ */
89
+ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, gitOptions }) => {
90
+ const configuration = (0, __intlayer_config.getConfiguration)(configOptions);
91
+ const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
92
+ if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
93
+ appLogger(`Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`);
94
+ nbSimultaneousFileProcessed = 10;
95
+ }
96
+ let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
97
+ if (!await require_utils_checkAccess.checkAIAccess(configuration, aiOptions)) return;
98
+ if (gitOptions) {
99
+ const gitChangedFiles = await (0, __intlayer_chokidar.listGitFiles)(gitOptions);
100
+ if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
101
+ }
102
+ appLogger(`Base locale is ${(0, __intlayer_chokidar.formatLocale)(baseLocale)}`);
103
+ appLogger(`Translating ${(0, __intlayer_config.colorizeNumber)(locales.length)} locales: [ ${(0, __intlayer_chokidar.formatLocale)(locales)} ]`);
104
+ appLogger(`Translating ${(0, __intlayer_config.colorizeNumber)(docList.length)} files:`);
105
+ appLogger(docList.map((path) => ` - ${(0, __intlayer_chokidar.formatPath)(path)}\n`));
106
+ await (0, __intlayer_chokidar.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
107
+ appLogger(`Translating file: ${(0, __intlayer_chokidar.formatPath)(docPath)} to ${(0, __intlayer_chokidar.formatLocale)(locale)}`);
108
+ const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
109
+ const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
110
+ if (!(0, node_fs.existsSync)(outputFilePath)) {
111
+ appLogger(`File ${outputFilePath} does not exist, creating it...`);
112
+ (0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
113
+ (0, node_fs.writeFileSync)(outputFilePath, "");
114
+ }
115
+ const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
116
+ skipIfModifiedBefore,
117
+ skipIfModifiedAfter
118
+ });
119
+ if (fileModificationData.isSkipped) {
120
+ appLogger(fileModificationData.message);
121
+ return;
122
+ }
123
+ await translateFile(absoluteBaseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions);
124
+ })), (task) => task(), nbSimultaneousFileProcessed ?? 3);
19
125
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var translateDoc_exports = {};
30
- __export(translateDoc_exports, {
31
- translateDoc: () => translateDoc,
32
- translateFile: () => translateFile
33
- });
34
- module.exports = __toCommonJS(translateDoc_exports);
35
- var import_chokidar = require("@intlayer/chokidar");
36
- var import_config = require("@intlayer/config");
37
- var import_fast_glob = __toESM(require("fast-glob"));
38
- var import_fs = require("fs");
39
- var import_promises = require("fs/promises");
40
- var import_path = require("path");
41
- var import_url = require("url");
42
- var import_calculateChunks = require('./utils/calculateChunks.cjs');
43
- var import_checkAccess = require('./utils/checkAccess.cjs');
44
- var import_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
45
- var import_chunkInference = require('./utils/chunkInference.cjs');
46
- var import_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
47
- var import_getChunk = require('./utils/getChunk.cjs');
48
- var import_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
49
- const import_meta = {};
50
- const isESModule = typeof import_meta.url === "string";
51
- const dir = isESModule ? (0, import_path.dirname)((0, import_url.fileURLToPath)(import_meta.url)) : __dirname;
52
- const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configuration = (0, import_config.getConfiguration)(), customInstructions) => {
53
- try {
54
- const appLogger = (0, import_config.getAppLogger)(configuration, {
55
- config: {
56
- prefix: ""
57
- }
58
- });
59
- const fileContent = await (0, import_promises.readFile)(baseFilePath, "utf-8");
60
- let fileResultContent = fileContent;
61
- const basePrompt = (await (0, import_promises.readFile)((0, import_path.join)(dir, "./prompts/TRANSLATE_PROMPT.md"), "utf-8")).replaceAll("{{localeName}}", `${(0, import_chokidar.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, import_chokidar.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
62
- const filePrexixText = `${import_config.ANSIColors.GREY_DARK}[${(0, import_chokidar.formatPath)(baseFilePath)}${import_config.ANSIColors.GREY_DARK}] `;
63
- const filePrefix = [
64
- (0, import_config.colon)(filePrexixText, { colSize: 40 }),
65
- `\u2192 ${import_config.ANSIColors.RESET}`
66
- ].join("");
67
- const prefixText = `${import_config.ANSIColors.GREY_DARK}[${(0, import_chokidar.formatPath)(baseFilePath)}${import_config.ANSIColors.GREY_DARK}][${(0, import_chokidar.formatLocale)(locale)}${import_config.ANSIColors.GREY_DARK}] `;
68
- const prefix = [
69
- (0, import_config.colon)(prefixText, { colSize: 40 }),
70
- `\u2192 ${import_config.ANSIColors.RESET}`
71
- ].join("");
72
- const chunks = (0, import_calculateChunks.chunkText)(fileContent);
73
- appLogger(
74
- `${filePrefix}Base file splitted into ${(0, import_config.colorizeNumber)(chunks.length)} chunks`
75
- );
76
- for await (const [i, chunk] of chunks.entries()) {
77
- const isFirstChunk = i === 0;
78
- const getPrevChunkPrompt = () => `**CHUNK ${i} of ${chunks.length}** that has been translated in ${(0, import_chokidar.formatLocale)(locale)}:
79
- ///chunkStart///` + (0, import_getChunk.getChunk)(fileResultContent, chunks[i - 1]) + `///chunkEnd///`;
80
- const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${(0, import_chokidar.formatLocale)(baseLocale, false)} as reference.
81
- ///chunksStart///` + (chunks[i - 1]?.content ?? "") + chunks[i].content + (chunks[i + 1]?.content ?? "") + `///chunksEnd///`;
82
- const fileToTranslateCurrentChunk = chunk.content;
83
- let chunkTranslation = await (0, import_config.retryManager)(async () => {
84
- const result = await (0, import_chunkInference.chunkInference)(
85
- [
86
- { role: "system", content: basePrompt },
87
- { role: "system", content: getBaseChunkContextPrompt() },
88
- ...isFirstChunk ? [] : [{ role: "system", content: getPrevChunkPrompt() }],
89
- {
90
- role: "system",
91
- content: `The next user message will be the **CHUNK ${(0, import_config.colorizeNumber)(i + 1)} of ${(0, import_config.colorizeNumber)(chunks.length)}** in ${(0, import_chokidar.formatLocale)(baseLocale, false)} to translate in ${(0, import_chokidar.formatLocale)(locale, false)}:`
92
- },
93
- { role: "user", content: fileToTranslateCurrentChunk }
94
- ],
95
- aiOptions,
96
- configuration
97
- );
98
- appLogger(
99
- [
100
- `${prefix}`,
101
- `${import_config.ANSIColors.GREY_DARK}[Chunk `,
102
- (0, import_config.colorizeNumber)(i + 1),
103
- `${import_config.ANSIColors.GREY_DARK} of `,
104
- (0, import_config.colorizeNumber)(chunks.length),
105
- `${import_config.ANSIColors.GREY_DARK}] \u2192${import_config.ANSIColors.RESET} `,
106
- `${(0, import_config.colorizeNumber)(result.tokenUsed)} tokens used`
107
- ].join("")
108
- );
109
- const fixedTranslatedChunkResult = (0, import_fixChunkStartEndChars.fixChunkStartEndChars)(
110
- result?.fileContent,
111
- fileToTranslateCurrentChunk
112
- );
113
- return fixedTranslatedChunkResult;
114
- })();
115
- fileResultContent = fileResultContent.replace(
116
- fileToTranslateCurrentChunk,
117
- chunkTranslation
118
- );
119
- }
120
- (0, import_fs.mkdirSync)((0, import_path.dirname)(outputFilePath), { recursive: true });
121
- (0, import_fs.writeFileSync)(outputFilePath, fileResultContent);
122
- const relativePath = (0, import_path.relative)(
123
- configuration.content.baseDir,
124
- outputFilePath
125
- );
126
- appLogger(
127
- `${(0, import_config.colorize)("\u2714", import_config.ANSIColors.GREEN)} File ${(0, import_chokidar.formatPath)(relativePath)} created/updated successfully.`
128
- );
129
- } catch (error) {
130
- console.error(error);
131
- }
132
- };
133
- const translateDoc = async ({
134
- docPattern,
135
- locales,
136
- excludedGlobPattern,
137
- baseLocale,
138
- aiOptions,
139
- nbSimultaneousFileProcessed,
140
- configOptions,
141
- customInstructions,
142
- skipIfModifiedBefore,
143
- skipIfModifiedAfter,
144
- gitOptions
145
- }) => {
146
- const configuration = (0, import_config.getConfiguration)(configOptions);
147
- const appLogger = (0, import_config.getAppLogger)(configuration, {
148
- config: {
149
- prefix: ""
150
- }
151
- });
152
- if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
153
- appLogger(
154
- `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`
155
- );
156
- nbSimultaneousFileProcessed = 10;
157
- }
158
- let docList = import_fast_glob.default.sync(docPattern, {
159
- ignore: excludedGlobPattern
160
- });
161
- const hasCMSAuth = await (0, import_checkAccess.checkAIAccess)(configuration, aiOptions);
162
- if (!hasCMSAuth) return;
163
- if (gitOptions) {
164
- const gitChangedFiles = await (0, import_chokidar.listGitFiles)(gitOptions);
165
- if (gitChangedFiles) {
166
- docList = docList.filter(
167
- (path) => gitChangedFiles.some((gitFile) => (0, import_path.join)(process.cwd(), path) === gitFile)
168
- );
169
- }
170
- }
171
- appLogger(`Base locale is ${(0, import_chokidar.formatLocale)(baseLocale)}`);
172
- appLogger(
173
- `Translating ${(0, import_config.colorizeNumber)(locales.length)} locales: [ ${(0, import_chokidar.formatLocale)(locales)} ]`
174
- );
175
- appLogger(`Translating ${(0, import_config.colorizeNumber)(docList.length)} files:`);
176
- appLogger(docList.map((path) => ` - ${(0, import_chokidar.formatPath)(path)}
177
- `));
178
- const allTasks = docList.flatMap(
179
- (docPath) => locales.map((locale) => async () => {
180
- appLogger(
181
- `Translating file: ${(0, import_chokidar.formatPath)(docPath)} to ${(0, import_chokidar.formatLocale)(locale)}`
182
- );
183
- const absoluteBaseFilePath = (0, import_path.join)(configuration.content.baseDir, docPath);
184
- const outputFilePath = (0, import_getOutputFilePath.getOutputFilePath)(
185
- absoluteBaseFilePath,
186
- locale,
187
- baseLocale
188
- );
189
- if (!(0, import_fs.existsSync)(outputFilePath)) {
190
- appLogger(`File ${outputFilePath} does not exist, creating it...`);
191
- (0, import_fs.mkdirSync)((0, import_path.dirname)(outputFilePath), { recursive: true });
192
- (0, import_fs.writeFileSync)(outputFilePath, "");
193
- }
194
- const fileModificationData = (0, import_checkFileModifiedRange.checkFileModifiedRange)(outputFilePath, {
195
- skipIfModifiedBefore,
196
- skipIfModifiedAfter
197
- });
198
- if (fileModificationData.isSkipped) {
199
- appLogger(fileModificationData.message);
200
- return;
201
- }
202
- await translateFile(
203
- absoluteBaseFilePath,
204
- outputFilePath,
205
- locale,
206
- baseLocale,
207
- aiOptions,
208
- configuration,
209
- customInstructions
210
- );
211
- })
212
- );
213
- await (0, import_chokidar.parallelize)(
214
- allTasks,
215
- (task) => task(),
216
- nbSimultaneousFileProcessed ?? 3
217
- );
218
- };
219
- // Annotate the CommonJS export names for ESM import in node:
220
- 0 && (module.exports = {
221
- translateDoc,
222
- translateFile
223
- });
126
+
127
+ //#endregion
128
+ exports.translateDoc = translateDoc;
129
+ exports.translateFile = translateFile;
224
130
  //# sourceMappingURL=translateDoc.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n listGitFiles,\n ListGitFilesOptions,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n IntlayerConfig,\n Locales,\n retryManager,\n} from '@intlayer/config';\nimport fg from 'fast-glob';\nimport { existsSync, mkdirSync, writeFileSync } from 'fs';\nimport { readFile } from 'fs/promises';\nimport { dirname, join, relative } from 'path';\nimport { fileURLToPath } from 'url';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getChunk } from './utils/getChunk';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\nconst isESModule = typeof import.meta.url === 'string';\n\nconst dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locales,\n baseLocale: Locales,\n aiOptions?: AIOptions,\n configuration: IntlayerConfig = getConfiguration(),\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = (\n await readFile(join(dir, './prompts/TRANSLATE_PROMPT.md'), 'utf-8')\n )\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrexixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n let chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locales[];\n excludedGlobPattern: string[];\n baseLocale: Locales;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = fg.sync(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locales,\n baseLocale,\n aiOptions,\n configuration,\n customInstructions\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAMO;AACP,oBAWO;AACP,uBAAe;AACf,gBAAqD;AACrD,sBAAyB;AACzB,kBAAwC;AACxC,iBAA8B;AAC9B,6BA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ACA,CAAC,SAAS,KAAK;AAAA,IACf,+BAA+B;AAAA,EACjC;AACF;","names":["fg"]}
1
+ {"version":3,"file":"translateDoc.cjs","names":["readAsset","ANSIColors","chunkText","chunkInference","fixChunkStartEndChars","docList: string[]","checkAIAccess","getOutputFilePath","checkFileModifiedRange"],"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n formatLocale,\n formatPath,\n getChunk,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport type { IntlayerConfig, Locale, Locales } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkAIAccess } from './utils/checkAccess';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n customInstructions?: string\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n const chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const hasCMSAuth = await checkAIAccess(configuration, aiOptions);\n\n if (!hasCMSAuth) return;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n appLogger(`File ${outputFilePath} does not exist, creating it...`);\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n configuration,\n aiOptions,\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+1,90 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var calculateChunks_exports = {};
20
- __export(calculateChunks_exports, {
21
- chunkText: () => chunkText
22
- });
23
- module.exports = __toCommonJS(calculateChunks_exports);
24
- var import_splitTextByLine = require('./splitTextByLine.cjs');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __intlayer_chokidar = require("@intlayer/chokidar");
3
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
4
+
5
+ //#region src/utils/calculateChunks.ts
25
6
  const DEFAULT_MAX_CHARS_PER_CHUNK = 800;
26
7
  const DEFAULT_OVERLAP_CHARS = 0;
27
8
  const chunkText = (text, maxCharsPerChunk = DEFAULT_MAX_CHARS_PER_CHUNK, overlapChars = DEFAULT_OVERLAP_CHARS) => {
28
- if (maxCharsPerChunk <= 0) {
29
- throw new Error("maxCharsPerChunk must be greater than 0");
30
- }
31
- const splittedText = (0, import_splitTextByLine.splitTextByLines)(text);
32
- const lines = [];
33
- let charStartAcc = 0;
34
- splittedText.forEach((line, index) => {
35
- lines.push({
36
- content: line,
37
- lineStart: index,
38
- lineLength: 1,
39
- charStart: charStartAcc,
40
- charLength: line.length
41
- });
42
- charStartAcc += line.length;
43
- });
44
- const groupedLines = lines.reduce(
45
- (acc, line) => {
46
- if (line.content.length > maxCharsPerChunk) {
47
- acc.push(line);
48
- return acc;
49
- }
50
- if (acc.length === 0) {
51
- acc.push(line);
52
- return acc;
53
- }
54
- const lastChunk = acc[acc.length - 1];
55
- const combinedLength = lastChunk.content.length + line.content.length;
56
- if (combinedLength > maxCharsPerChunk) {
57
- acc.push(line);
58
- return acc;
59
- }
60
- const combinedContent = lastChunk.content + line.content;
61
- const updatedChunk = {
62
- content: combinedContent,
63
- lineStart: lastChunk.lineStart,
64
- lineLength: lastChunk.lineLength + line.lineLength,
65
- charStart: lastChunk.charStart,
66
- charLength: combinedContent.length
67
- };
68
- acc[acc.length - 1] = updatedChunk;
69
- return acc;
70
- },
71
- []
72
- );
73
- const splittedLines = groupedLines.flatMap((line) => {
74
- const chunk = [];
75
- if (line.content.length <= maxCharsPerChunk) {
76
- chunk.push(line);
77
- return chunk;
78
- }
79
- for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {
80
- const slicedContent = line.content.slice(i, i + maxCharsPerChunk);
81
- chunk.push({
82
- content: slicedContent,
83
- lineStart: line.lineStart,
84
- lineLength: 1,
85
- charStart: line.charStart + i,
86
- charLength: slicedContent.length
87
- });
88
- }
89
- return chunk;
90
- });
91
- if (overlapChars === 0) return splittedLines;
92
- const overlapChunks = splittedLines.length > 0 ? [splittedLines[0]] : [];
93
- for (let i = 1; i < splittedLines.length; i++) {
94
- const previousChunk = splittedLines[i - 1];
95
- const chunk = splittedLines[i];
96
- const overlapContent = previousChunk.content.slice(-overlapChars);
97
- const overlapLineNb = (0, import_splitTextByLine.splitTextByLines)(overlapContent).length;
98
- const overlapContentWithoutPartialLine = overlapContent.slice(
99
- overlapLineNb > 1 ? overlapContent.indexOf("\n") + 1 : 0,
100
- overlapContent.length
101
- );
102
- const newContent = overlapContentWithoutPartialLine + chunk.content;
103
- const newLineLength = (0, import_splitTextByLine.splitTextByLines)(newContent).length;
104
- const lineDiff = chunk.lineLength - newLineLength;
105
- const overlappedChunk = {
106
- content: newContent,
107
- lineStart: chunk.lineStart + lineDiff,
108
- lineLength: chunk.lineLength - lineDiff,
109
- charStart: chunk.charStart - overlapContentWithoutPartialLine.length,
110
- charLength: newContent.length
111
- };
112
- overlapChunks.push(overlappedChunk);
113
- }
114
- return overlapChunks;
9
+ if (maxCharsPerChunk <= 0) throw new Error("maxCharsPerChunk must be greater than 0");
10
+ const splittedText = (0, __intlayer_chokidar.splitTextByLines)(text);
11
+ const lines = [];
12
+ let charStartAcc = 0;
13
+ splittedText.forEach((line, index) => {
14
+ lines.push({
15
+ content: line,
16
+ lineStart: index,
17
+ lineLength: 1,
18
+ charStart: charStartAcc,
19
+ charLength: line.length
20
+ });
21
+ charStartAcc += line.length;
22
+ });
23
+ const splittedLines = lines.reduce((acc, line) => {
24
+ if (line.content.length > maxCharsPerChunk) {
25
+ acc.push(line);
26
+ return acc;
27
+ }
28
+ if (acc.length === 0) {
29
+ acc.push(line);
30
+ return acc;
31
+ }
32
+ const lastChunk = acc[acc.length - 1];
33
+ if (lastChunk.content.length + line.content.length > maxCharsPerChunk) {
34
+ acc.push(line);
35
+ return acc;
36
+ }
37
+ const combinedContent = lastChunk.content + line.content;
38
+ const updatedChunk = {
39
+ content: combinedContent,
40
+ lineStart: lastChunk.lineStart,
41
+ lineLength: lastChunk.lineLength + line.lineLength,
42
+ charStart: lastChunk.charStart,
43
+ charLength: combinedContent.length
44
+ };
45
+ acc[acc.length - 1] = updatedChunk;
46
+ return acc;
47
+ }, []).flatMap((line) => {
48
+ const chunk = [];
49
+ if (line.content.length <= maxCharsPerChunk) {
50
+ chunk.push(line);
51
+ return chunk;
52
+ }
53
+ for (let i = 0; i < line.content.length; i += maxCharsPerChunk) {
54
+ const slicedContent = line.content.slice(i, i + maxCharsPerChunk);
55
+ chunk.push({
56
+ content: slicedContent,
57
+ lineStart: line.lineStart,
58
+ lineLength: 1,
59
+ charStart: line.charStart + i,
60
+ charLength: slicedContent.length
61
+ });
62
+ }
63
+ return chunk;
64
+ });
65
+ if (overlapChars === 0) return splittedLines;
66
+ const overlapChunks = splittedLines.length > 0 ? [splittedLines[0]] : [];
67
+ for (let i = 1; i < splittedLines.length; i++) {
68
+ const previousChunk = splittedLines[i - 1];
69
+ const chunk = splittedLines[i];
70
+ const overlapContent = previousChunk.content.slice(-overlapChars);
71
+ const overlapLineNb = (0, __intlayer_chokidar.splitTextByLines)(overlapContent).length;
72
+ const overlapContentWithoutPartialLine = overlapContent.slice(overlapLineNb > 1 ? overlapContent.indexOf("\n") + 1 : 0, overlapContent.length);
73
+ const newContent = overlapContentWithoutPartialLine + chunk.content;
74
+ const newLineLength = (0, __intlayer_chokidar.splitTextByLines)(newContent).length;
75
+ const lineDiff = chunk.lineLength - newLineLength;
76
+ const overlappedChunk = {
77
+ content: newContent,
78
+ lineStart: chunk.lineStart + lineDiff,
79
+ lineLength: chunk.lineLength - lineDiff,
80
+ charStart: chunk.charStart - overlapContentWithoutPartialLine.length,
81
+ charLength: newContent.length
82
+ };
83
+ overlapChunks.push(overlappedChunk);
84
+ }
85
+ return overlapChunks;
115
86
  };
116
- // Annotate the CommonJS export names for ESM import in node:
117
- 0 && (module.exports = {
118
- chunkText
119
- });
87
+
88
+ //#endregion
89
+ exports.chunkText = chunkText;
120
90
  //# sourceMappingURL=calculateChunks.cjs.map