@intlayer/cli 8.1.2 → 8.1.3-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 (301) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +1 -186
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
  4. package/dist/cjs/_virtual/_utils_asset.cjs +2 -98
  5. package/dist/cjs/auth/login.cjs +2 -85
  6. package/dist/cjs/auth/login.cjs.map +1 -1
  7. package/dist/cjs/build.cjs +1 -27
  8. package/dist/cjs/build.cjs.map +1 -1
  9. package/dist/cjs/ci.cjs +1 -73
  10. package/dist/cjs/ci.cjs.map +1 -1
  11. package/dist/cjs/cli.cjs +1 -476
  12. package/dist/cjs/cli.cjs.map +1 -1
  13. package/dist/cjs/config.cjs +1 -12
  14. package/dist/cjs/config.cjs.map +1 -1
  15. package/dist/cjs/editor.cjs +1 -50
  16. package/dist/cjs/editor.cjs.map +1 -1
  17. package/dist/cjs/extract.cjs +1 -96
  18. package/dist/cjs/extract.cjs.map +1 -1
  19. package/dist/cjs/fill/deepMergeContent.cjs +1 -27
  20. package/dist/cjs/fill/deepMergeContent.cjs.map +1 -1
  21. package/dist/cjs/fill/fill.cjs +1 -78
  22. package/dist/cjs/fill/fill.cjs.map +1 -1
  23. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +1 -29
  24. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  25. package/dist/cjs/fill/formatFillData.cjs +1 -50
  26. package/dist/cjs/fill/formatFillData.cjs.map +1 -1
  27. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs +1 -26
  28. package/dist/cjs/fill/getAvailableLocalesInDictionary.cjs.map +1 -1
  29. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs +1 -50
  30. package/dist/cjs/fill/getFilterMissingContentPerLocale.cjs.map +1 -1
  31. package/dist/cjs/fill/index.cjs +1 -6
  32. package/dist/cjs/fill/listTranslationsTasks.cjs +1 -70
  33. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -1
  34. package/dist/cjs/fill/mergeChunks.cjs +1 -28
  35. package/dist/cjs/fill/mergeChunks.cjs.map +1 -1
  36. package/dist/cjs/fill/translateDictionary.cjs +1 -205
  37. package/dist/cjs/fill/translateDictionary.cjs.map +1 -1
  38. package/dist/cjs/fill/writeFill.cjs +1 -54
  39. package/dist/cjs/fill/writeFill.cjs.map +1 -1
  40. package/dist/cjs/getTargetDictionary.cjs +1 -36
  41. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  42. package/dist/cjs/index.cjs +1 -39
  43. package/dist/cjs/init.cjs +1 -322
  44. package/dist/cjs/init.cjs.map +1 -1
  45. package/dist/cjs/listContentDeclaration.cjs +1 -41
  46. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  47. package/dist/cjs/listProjects.cjs +1 -28
  48. package/dist/cjs/listProjects.cjs.map +1 -1
  49. package/dist/cjs/liveSync.cjs +8 -151
  50. package/dist/cjs/liveSync.cjs.map +1 -1
  51. package/dist/cjs/pull.cjs +1 -146
  52. package/dist/cjs/pull.cjs.map +1 -1
  53. package/dist/cjs/push/pullLog.cjs +3 -102
  54. package/dist/cjs/push/pullLog.cjs.map +1 -1
  55. package/dist/cjs/push/push.cjs +1 -206
  56. package/dist/cjs/push/push.cjs.map +1 -1
  57. package/dist/cjs/pushConfig.cjs +1 -19
  58. package/dist/cjs/pushConfig.cjs.map +1 -1
  59. package/dist/cjs/pushLog.cjs +3 -84
  60. package/dist/cjs/pushLog.cjs.map +1 -1
  61. package/dist/cjs/reviewDoc/reviewDoc.cjs +1 -68
  62. package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -1
  63. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs +1 -94
  64. package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -1
  65. package/dist/cjs/searchDoc.cjs +1 -38
  66. package/dist/cjs/searchDoc.cjs.map +1 -1
  67. package/dist/cjs/test/index.cjs +1 -7
  68. package/dist/cjs/test/listMissingTranslations.cjs +1 -49
  69. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  70. package/dist/cjs/test/test.cjs +1 -53
  71. package/dist/cjs/test/test.cjs.map +1 -1
  72. package/dist/cjs/translateDoc/index.cjs +1 -9
  73. package/dist/cjs/translateDoc/translateDoc.cjs +1 -74
  74. package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -1
  75. package/dist/cjs/translateDoc/translateFile.cjs +2 -103
  76. package/dist/cjs/translateDoc/translateFile.cjs.map +1 -1
  77. package/dist/cjs/translateDoc/validation.cjs +5 -49
  78. package/dist/cjs/translateDoc/validation.cjs.map +1 -1
  79. package/dist/cjs/translation-alignment/alignBlocks.cjs +1 -67
  80. package/dist/cjs/translation-alignment/alignBlocks.cjs.map +1 -1
  81. package/dist/cjs/translation-alignment/computeSimilarity.cjs +1 -25
  82. package/dist/cjs/translation-alignment/computeSimilarity.cjs.map +1 -1
  83. package/dist/cjs/translation-alignment/fingerprintBlock.cjs +1 -23
  84. package/dist/cjs/translation-alignment/fingerprintBlock.cjs.map +1 -1
  85. package/dist/cjs/translation-alignment/index.cjs +1 -22
  86. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs +1 -18
  87. package/dist/cjs/translation-alignment/mapChangedLinesToBlocks.cjs.map +1 -1
  88. package/dist/cjs/translation-alignment/normalizeBlock.cjs +1 -22
  89. package/dist/cjs/translation-alignment/normalizeBlock.cjs.map +1 -1
  90. package/dist/cjs/translation-alignment/pipeline.cjs +1 -37
  91. package/dist/cjs/translation-alignment/pipeline.cjs.map +1 -1
  92. package/dist/cjs/translation-alignment/planActions.cjs +1 -46
  93. package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
  94. package/dist/cjs/translation-alignment/rebuildDocument.cjs +2 -49
  95. package/dist/cjs/translation-alignment/rebuildDocument.cjs.map +1 -1
  96. package/dist/cjs/translation-alignment/segmentDocument.cjs +5 -66
  97. package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
  98. package/dist/cjs/utils/calculateChunks.cjs +2 -89
  99. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  100. package/dist/cjs/utils/checkAccess.cjs +1 -81
  101. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  102. package/dist/cjs/utils/checkConfigConsistency.cjs +1 -16
  103. package/dist/cjs/utils/checkConfigConsistency.cjs.map +1 -1
  104. package/dist/cjs/utils/checkFileModifiedRange.cjs +1 -81
  105. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  106. package/dist/cjs/utils/checkLastUpdateTime.cjs +1 -19
  107. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  108. package/dist/cjs/utils/chunkInference.cjs +1 -45
  109. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  110. package/dist/cjs/utils/fixChunkStartEndChars.cjs +3 -27
  111. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  112. package/dist/cjs/utils/formatTimeDiff.cjs +1 -20
  113. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  114. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +1 -16
  115. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  116. package/dist/cjs/utils/getOutputFilePath.cjs +1 -74
  117. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  118. package/dist/cjs/utils/getParentPackageJSON.cjs +1 -20
  119. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  120. package/dist/cjs/utils/listSpecialChars.cjs +2 -54
  121. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  122. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +1 -102
  123. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  124. package/dist/cjs/utils/openBrowser.cjs +1 -19
  125. package/dist/cjs/utils/openBrowser.cjs.map +1 -1
  126. package/dist/cjs/utils/reorderParagraphs.cjs +3 -91
  127. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  128. package/dist/cjs/utils/setupAI.cjs +1 -64
  129. package/dist/cjs/utils/setupAI.cjs.map +1 -1
  130. package/dist/cjs/watch.cjs +1 -43
  131. package/dist/cjs/watch.cjs.map +1 -1
  132. package/dist/esm/IntlayerEventListener.mjs +1 -183
  133. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  134. package/dist/esm/_virtual/_rolldown/runtime.mjs +1 -8
  135. package/dist/esm/_virtual/_utils_asset.mjs +2 -97
  136. package/dist/esm/auth/login.mjs +2 -82
  137. package/dist/esm/auth/login.mjs.map +1 -1
  138. package/dist/esm/build.mjs +1 -25
  139. package/dist/esm/build.mjs.map +1 -1
  140. package/dist/esm/ci.mjs +1 -71
  141. package/dist/esm/ci.mjs.map +1 -1
  142. package/dist/esm/cli.mjs +1 -473
  143. package/dist/esm/cli.mjs.map +1 -1
  144. package/dist/esm/config.mjs +1 -10
  145. package/dist/esm/config.mjs.map +1 -1
  146. package/dist/esm/editor.mjs +1 -49
  147. package/dist/esm/editor.mjs.map +1 -1
  148. package/dist/esm/extract.mjs +1 -93
  149. package/dist/esm/extract.mjs.map +1 -1
  150. package/dist/esm/fill/deepMergeContent.mjs +1 -25
  151. package/dist/esm/fill/deepMergeContent.mjs.map +1 -1
  152. package/dist/esm/fill/fill.mjs +1 -76
  153. package/dist/esm/fill/fill.mjs.map +1 -1
  154. package/dist/esm/fill/formatAutoFilledFilePath.mjs +1 -27
  155. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  156. package/dist/esm/fill/formatFillData.mjs +1 -49
  157. package/dist/esm/fill/formatFillData.mjs.map +1 -1
  158. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs +1 -24
  159. package/dist/esm/fill/getAvailableLocalesInDictionary.mjs.map +1 -1
  160. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs +1 -48
  161. package/dist/esm/fill/getFilterMissingContentPerLocale.mjs.map +1 -1
  162. package/dist/esm/fill/index.mjs +1 -4
  163. package/dist/esm/fill/listTranslationsTasks.mjs +1 -68
  164. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -1
  165. package/dist/esm/fill/mergeChunks.mjs +1 -26
  166. package/dist/esm/fill/mergeChunks.mjs.map +1 -1
  167. package/dist/esm/fill/translateDictionary.mjs +1 -203
  168. package/dist/esm/fill/translateDictionary.mjs.map +1 -1
  169. package/dist/esm/fill/writeFill.mjs +1 -52
  170. package/dist/esm/fill/writeFill.mjs.map +1 -1
  171. package/dist/esm/getTargetDictionary.mjs +1 -33
  172. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  173. package/dist/esm/index.mjs +1 -18
  174. package/dist/esm/init.mjs +1 -317
  175. package/dist/esm/init.mjs.map +1 -1
  176. package/dist/esm/listContentDeclaration.mjs +1 -38
  177. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  178. package/dist/esm/listProjects.mjs +1 -26
  179. package/dist/esm/listProjects.mjs.map +1 -1
  180. package/dist/esm/liveSync.mjs +8 -148
  181. package/dist/esm/liveSync.mjs.map +1 -1
  182. package/dist/esm/pull.mjs +1 -144
  183. package/dist/esm/pull.mjs.map +1 -1
  184. package/dist/esm/push/pullLog.mjs +3 -100
  185. package/dist/esm/push/pullLog.mjs.map +1 -1
  186. package/dist/esm/push/push.mjs +1 -203
  187. package/dist/esm/push/push.mjs.map +1 -1
  188. package/dist/esm/pushConfig.mjs +1 -17
  189. package/dist/esm/pushConfig.mjs.map +1 -1
  190. package/dist/esm/pushLog.mjs +3 -82
  191. package/dist/esm/pushLog.mjs.map +1 -1
  192. package/dist/esm/reviewDoc/reviewDoc.mjs +1 -65
  193. package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -1
  194. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs +1 -92
  195. package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -1
  196. package/dist/esm/searchDoc.mjs +1 -36
  197. package/dist/esm/searchDoc.mjs.map +1 -1
  198. package/dist/esm/test/index.mjs +1 -4
  199. package/dist/esm/test/listMissingTranslations.mjs +1 -46
  200. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  201. package/dist/esm/test/test.mjs +1 -51
  202. package/dist/esm/test/test.mjs.map +1 -1
  203. package/dist/esm/translateDoc/index.mjs +1 -5
  204. package/dist/esm/translateDoc/translateDoc.mjs +1 -71
  205. package/dist/esm/translateDoc/translateDoc.mjs.map +1 -1
  206. package/dist/esm/translateDoc/translateFile.mjs +2 -101
  207. package/dist/esm/translateDoc/translateFile.mjs.map +1 -1
  208. package/dist/esm/translateDoc/validation.mjs +5 -46
  209. package/dist/esm/translateDoc/validation.mjs.map +1 -1
  210. package/dist/esm/translation-alignment/alignBlocks.mjs +1 -66
  211. package/dist/esm/translation-alignment/alignBlocks.mjs.map +1 -1
  212. package/dist/esm/translation-alignment/computeSimilarity.mjs +1 -22
  213. package/dist/esm/translation-alignment/computeSimilarity.mjs.map +1 -1
  214. package/dist/esm/translation-alignment/fingerprintBlock.mjs +1 -20
  215. package/dist/esm/translation-alignment/fingerprintBlock.mjs.map +1 -1
  216. package/dist/esm/translation-alignment/index.mjs +1 -11
  217. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs +1 -16
  218. package/dist/esm/translation-alignment/mapChangedLinesToBlocks.mjs.map +1 -1
  219. package/dist/esm/translation-alignment/normalizeBlock.mjs +1 -20
  220. package/dist/esm/translation-alignment/normalizeBlock.mjs.map +1 -1
  221. package/dist/esm/translation-alignment/pipeline.mjs +1 -35
  222. package/dist/esm/translation-alignment/pipeline.mjs.map +1 -1
  223. package/dist/esm/translation-alignment/planActions.mjs +1 -44
  224. package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
  225. package/dist/esm/translation-alignment/rebuildDocument.mjs +2 -46
  226. package/dist/esm/translation-alignment/rebuildDocument.mjs.map +1 -1
  227. package/dist/esm/translation-alignment/segmentDocument.mjs +5 -64
  228. package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
  229. package/dist/esm/utils/calculateChunks.mjs +2 -87
  230. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  231. package/dist/esm/utils/checkAccess.mjs +1 -78
  232. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  233. package/dist/esm/utils/checkConfigConsistency.mjs +1 -14
  234. package/dist/esm/utils/checkConfigConsistency.mjs.map +1 -1
  235. package/dist/esm/utils/checkFileModifiedRange.mjs +1 -80
  236. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  237. package/dist/esm/utils/checkLastUpdateTime.mjs +1 -17
  238. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  239. package/dist/esm/utils/chunkInference.mjs +1 -43
  240. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  241. package/dist/esm/utils/fixChunkStartEndChars.mjs +3 -25
  242. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  243. package/dist/esm/utils/formatTimeDiff.mjs +1 -18
  244. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  245. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +1 -14
  246. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  247. package/dist/esm/utils/getOutputFilePath.mjs +1 -72
  248. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  249. package/dist/esm/utils/getParentPackageJSON.mjs +1 -18
  250. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  251. package/dist/esm/utils/listSpecialChars.mjs +2 -52
  252. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  253. package/dist/esm/utils/mapChunksBetweenFiles.mjs +1 -100
  254. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  255. package/dist/esm/utils/openBrowser.mjs +1 -17
  256. package/dist/esm/utils/openBrowser.mjs.map +1 -1
  257. package/dist/esm/utils/reorderParagraphs.mjs +3 -90
  258. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  259. package/dist/esm/utils/setupAI.mjs +1 -62
  260. package/dist/esm/utils/setupAI.mjs.map +1 -1
  261. package/dist/esm/watch.mjs +1 -41
  262. package/dist/esm/watch.mjs.map +1 -1
  263. package/dist/types/auth/login.d.ts +1 -1
  264. package/dist/types/auth/login.d.ts.map +1 -1
  265. package/dist/types/build.d.ts +1 -1
  266. package/dist/types/build.d.ts.map +1 -1
  267. package/dist/types/config.d.ts +1 -1
  268. package/dist/types/extract.d.ts +1 -1
  269. package/dist/types/extract.d.ts.map +1 -1
  270. package/dist/types/fill/fill.d.ts +1 -1
  271. package/dist/types/fill/fill.d.ts.map +1 -1
  272. package/dist/types/fill/translateDictionary.d.ts +2 -2
  273. package/dist/types/fill/translateDictionary.d.ts.map +1 -1
  274. package/dist/types/fill/writeFill.d.ts.map +1 -1
  275. package/dist/types/getTargetDictionary.d.ts +2 -2
  276. package/dist/types/index.d.ts +4 -1
  277. package/dist/types/listContentDeclaration.d.ts +1 -1
  278. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  279. package/dist/types/liveSync.d.ts +1 -1
  280. package/dist/types/pull.d.ts +1 -1
  281. package/dist/types/pull.d.ts.map +1 -1
  282. package/dist/types/push/pullLog.d.ts +1 -1
  283. package/dist/types/push/pullLog.d.ts.map +1 -1
  284. package/dist/types/push/push.d.ts +2 -2
  285. package/dist/types/pushConfig.d.ts +1 -1
  286. package/dist/types/reviewDoc/reviewDoc.d.ts +2 -2
  287. package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -1
  288. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts +1 -1
  289. package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -1
  290. package/dist/types/searchDoc.d.ts +1 -1
  291. package/dist/types/searchDoc.d.ts.map +1 -1
  292. package/dist/types/test/listMissingTranslations.d.ts +1 -1
  293. package/dist/types/test/test.d.ts +1 -1
  294. package/dist/types/test/test.d.ts.map +1 -1
  295. package/dist/types/translateDoc/translateDoc.d.ts.map +1 -1
  296. package/dist/types/translateDoc/types.d.ts +2 -2
  297. package/dist/types/translateDoc/validation.d.ts +1 -1
  298. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  299. package/dist/types/watch.d.ts +1 -1
  300. package/dist/types/watch.d.ts.map +1 -1
  301. package/package.json +11 -11
@@ -1,206 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_fill_deepMergeContent = require('./deepMergeContent.cjs');
4
- const require_fill_getFilterMissingContentPerLocale = require('./getFilterMissingContentPerLocale.cjs');
5
- const require_fill_mergeChunks = require('./mergeChunks.cjs');
6
- let _intlayer_api = require("@intlayer/api");
7
- let _intlayer_chokidar = require("@intlayer/chokidar");
8
- let _intlayer_config = require("@intlayer/config");
9
- let node_path = require("node:path");
10
- let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
11
- let _intlayer_core = require("@intlayer/core");
12
-
13
- //#region src/fill/translateDictionary.ts
14
- const hasMissingMetadata = (dictionary) => !dictionary.description || !dictionary.title || !dictionary.tags;
15
- const CHUNK_SIZE = 7e3;
16
- const GROUP_MAX_RETRY = 2;
17
- const MAX_RETRY = 3;
18
- const RETRY_DELAY = 1e3 * 10;
19
- const MAX_FOLLOWING_ERRORS = 10;
20
- let followingErrors = 0;
21
- const translateDictionary = async (task, configuration, options) => {
22
- const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
23
- const intlayerAPI = (0, _intlayer_api.getIntlayerAPIProxy)(void 0, configuration);
24
- const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {
25
- mode: "complete",
26
- fillMetadata: true,
27
- ...options
28
- };
29
- const notifySuccess = () => {
30
- followingErrors = 0;
31
- options?.onSuccess?.();
32
- };
33
- return await (0, _intlayer_config.retryManager)(async () => {
34
- const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
35
- const baseUnmergedDictionary = unmergedDictionariesRecord[task.dictionaryKey].find((dict) => dict.localId === task.dictionaryLocalId);
36
- if (!baseUnmergedDictionary) {
37
- appLogger(`${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`, { level: "warn" });
38
- return {
39
- ...task,
40
- dictionaryOutput: null
41
- };
42
- }
43
- let metadata;
44
- if (fillMetadata && (hasMissingMetadata(baseUnmergedDictionary) || mode === "review")) {
45
- const defaultLocaleDictionary = (0, _intlayer_core.getPerLocaleDictionary)(baseUnmergedDictionary, configuration.internationalization.defaultLocale);
46
- appLogger(`${task.dictionaryPreset} Filling missing metadata for ${(0, _intlayer_config.colorizePath)((0, node_path.basename)(baseUnmergedDictionary.filePath))}`, { level: "info" });
47
- const runAudit = async () => {
48
- if (aiClient && aiConfig) return { data: await aiClient.auditDictionaryMetadata({
49
- fileContent: JSON.stringify(defaultLocaleDictionary),
50
- aiConfig
51
- }) };
52
- return await intlayerAPI.ai.auditContentDeclarationMetadata({
53
- fileContent: JSON.stringify(defaultLocaleDictionary),
54
- aiOptions
55
- });
56
- };
57
- metadata = (options?.onHandle ? await options.onHandle(runAudit) : await runAudit()).data?.fileContent;
58
- }
59
- const translatedContentResults = await Promise.all(task.targetLocales.map(async (targetLocale) => {
60
- /**
61
- * In complete mode, for large dictionaries, we want to filter all content that is already translated
62
- *
63
- * targetLocale: fr
64
- *
65
- * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}
66
- * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }
67
- *
68
- */
69
- let dictionaryToProcess = structuredClone(baseUnmergedDictionary);
70
- let targetLocaleDictionary;
71
- if (typeof baseUnmergedDictionary.locale === "string") {
72
- const targetLocaleFilePath = baseUnmergedDictionary.filePath?.replace(new RegExp(`/${task.sourceLocale}/`, "g"), `/${targetLocale}/`);
73
- const targetUnmergedDictionary = targetLocaleFilePath ? unmergedDictionariesRecord[task.dictionaryKey]?.find((dict) => dict.filePath === targetLocaleFilePath && dict.locale === targetLocale) : void 0;
74
- targetLocaleDictionary = targetUnmergedDictionary ?? {
75
- key: baseUnmergedDictionary.key,
76
- content: {},
77
- filePath: targetLocaleFilePath,
78
- locale: targetLocale
79
- };
80
- if (mode === "complete") dictionaryToProcess = require_fill_getFilterMissingContentPerLocale.getFilterMissingContentPerLocale(dictionaryToProcess, targetUnmergedDictionary);
81
- } else {
82
- if (mode === "complete") dictionaryToProcess = (0, _intlayer_core.getFilterMissingTranslationsDictionary)(dictionaryToProcess, targetLocale);
83
- dictionaryToProcess = (0, _intlayer_core.getPerLocaleDictionary)(dictionaryToProcess, task.sourceLocale);
84
- targetLocaleDictionary = (0, _intlayer_core.getPerLocaleDictionary)(baseUnmergedDictionary, targetLocale);
85
- }
86
- const localePreset = (0, _intlayer_config.colon)([
87
- (0, _intlayer_config.colorize)("[", _intlayer_config.ANSIColors.GREY_DARK),
88
- (0, _intlayer_chokidar.formatLocale)(targetLocale),
89
- (0, _intlayer_config.colorize)("]", _intlayer_config.ANSIColors.GREY_DARK)
90
- ].join(""), { colSize: 18 });
91
- const createChunkPreset = (chunkIndex, totalChunks) => {
92
- if (totalChunks <= 1) return "";
93
- return (0, _intlayer_config.colon)([
94
- (0, _intlayer_config.colorize)("[", _intlayer_config.ANSIColors.GREY_DARK),
95
- (0, _intlayer_config.colorizeNumber)(chunkIndex + 1),
96
- (0, _intlayer_config.colorize)(`/${totalChunks}`, _intlayer_config.ANSIColors.GREY_DARK),
97
- (0, _intlayer_config.colorize)("]", _intlayer_config.ANSIColors.GREY_DARK)
98
- ].join(""), { colSize: 5 });
99
- };
100
- appLogger(`${task.dictionaryPreset}${localePreset} Preparing ${(0, _intlayer_config.colorizePath)((0, node_path.basename)(targetLocaleDictionary.filePath))}`, { level: "info" });
101
- const isContentStructured = typeof dictionaryToProcess.content === "object" && dictionaryToProcess.content !== null || Array.isArray(dictionaryToProcess.content);
102
- const chunkedJsonContent = (0, _intlayer_chokidar.chunkJSON)(isContentStructured ? dictionaryToProcess.content : { __INTLAYER_ROOT_PRIMITIVE_CONTENT__: dictionaryToProcess.content }, CHUNK_SIZE);
103
- const nbOfChunks = chunkedJsonContent.length;
104
- if (nbOfChunks > 1) appLogger(`${task.dictionaryPreset}${localePreset} Split into ${(0, _intlayer_config.colorizeNumber)(nbOfChunks)} chunks for translation`, { level: "info" });
105
- const chunkResult = [];
106
- const chunkPromises = chunkedJsonContent.map((chunk) => {
107
- const chunkPreset = createChunkPreset(chunk.index, chunk.total);
108
- if (nbOfChunks > 1) appLogger(`${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`, { level: "info" });
109
- const chunkContent = (0, _intlayer_chokidar.reconstructFromSingleChunk)(chunk);
110
- const presetOutputContent = (0, _intlayer_chokidar.reduceObjectFormat)(isContentStructured ? targetLocaleDictionary.content : { __INTLAYER_ROOT_PRIMITIVE_CONTENT__: targetLocaleDictionary.content }, chunkContent);
111
- const executeTranslation = async () => {
112
- return await (0, _intlayer_config.retryManager)(async () => {
113
- let translationResult;
114
- if (aiClient && aiConfig) translationResult = await aiClient.translateJSON({
115
- entryFileContent: chunkContent,
116
- presetOutputContent,
117
- dictionaryDescription: dictionaryToProcess.description ?? metadata?.description ?? "",
118
- entryLocale: task.sourceLocale,
119
- outputLocale: targetLocale,
120
- mode,
121
- aiConfig
122
- });
123
- else translationResult = await intlayerAPI.ai.translateJSON({
124
- entryFileContent: chunkContent,
125
- presetOutputContent,
126
- dictionaryDescription: dictionaryToProcess.description ?? metadata?.description ?? "",
127
- entryLocale: task.sourceLocale,
128
- outputLocale: targetLocale,
129
- mode,
130
- aiOptions
131
- }).then((result) => result.data);
132
- if (!translationResult?.fileContent) throw new Error("No content result");
133
- const { isIdentic } = (0, _intlayer_chokidar.verifyIdenticObjectFormat)(translationResult.fileContent, chunkContent);
134
- if (!isIdentic) throw new Error("Translation result does not match expected format");
135
- notifySuccess();
136
- return translationResult.fileContent;
137
- }, {
138
- maxRetry: MAX_RETRY,
139
- delay: RETRY_DELAY,
140
- onError: ({ error, attempt, maxRetry }) => {
141
- const chunkPreset = createChunkPreset(chunk.index, chunk.total);
142
- appLogger(`${task.dictionaryPreset}${localePreset}${chunkPreset} ${(0, _intlayer_config.colorize)("Error filling:", _intlayer_config.ANSIColors.RED)} ${(0, _intlayer_config.colorize)(typeof error === "string" ? error : JSON.stringify(error), _intlayer_config.ANSIColors.GREY_DARK)} - Attempt ${(0, _intlayer_config.colorizeNumber)(attempt + 1)} of ${(0, _intlayer_config.colorizeNumber)(maxRetry)}`, { level: "error" });
143
- followingErrors += 1;
144
- if (followingErrors >= MAX_FOLLOWING_ERRORS) {
145
- appLogger(`There is something wrong.`, { level: "error" });
146
- process.exit(1);
147
- }
148
- }
149
- })();
150
- };
151
- return (options?.onHandle ? options.onHandle(executeTranslation) : executeTranslation()).then((result) => ({
152
- chunk,
153
- result
154
- }));
155
- });
156
- (await Promise.all(chunkPromises)).sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index).forEach(({ result }) => {
157
- chunkResult.push(result);
158
- });
159
- const mergedContent = require_fill_mergeChunks.mergeChunks(chunkResult);
160
- let finalContent = {
161
- ...dictionaryToProcess,
162
- content: mergedContent
163
- }.content;
164
- if (!isContentStructured) finalContent = finalContent?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;
165
- if (typeof baseUnmergedDictionary.locale === "string") finalContent = require_fill_deepMergeContent.deepMergeContent(targetLocaleDictionary.content ?? {}, finalContent);
166
- return [targetLocale, finalContent];
167
- }));
168
- const translatedContent = Object.fromEntries(translatedContentResults);
169
- let dictionaryOutput = {
170
- ...(0, _intlayer_core.getMultilingualDictionary)(baseUnmergedDictionary.locale ? {
171
- ...baseUnmergedDictionary,
172
- key: baseUnmergedDictionary.key,
173
- content: {}
174
- } : baseUnmergedDictionary),
175
- locale: void 0,
176
- ...metadata
177
- };
178
- for (const targetLocale of task.targetLocales) if (translatedContent[targetLocale]) dictionaryOutput = (0, _intlayer_core.insertContentInDictionary)(dictionaryOutput, translatedContent[targetLocale], targetLocale);
179
- appLogger(`${task.dictionaryPreset} ${(0, _intlayer_config.colorize)("Translation completed successfully", _intlayer_config.ANSIColors.GREEN)} for ${(0, _intlayer_config.colorizePath)((0, node_path.basename)(dictionaryOutput.filePath))}`, { level: "info" });
180
- if (baseUnmergedDictionary.locale && (baseUnmergedDictionary.fill === true || baseUnmergedDictionary.fill === void 0) && baseUnmergedDictionary.location === "local") {
181
- const dictionaryFilePath = baseUnmergedDictionary.filePath.split(".").slice(0, -1);
182
- const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];
183
- return JSON.parse(JSON.stringify({
184
- ...task,
185
- dictionaryOutput: {
186
- ...dictionaryOutput,
187
- fill: void 0,
188
- filled: true
189
- }
190
- }).replaceAll(new RegExp(`\\.${contentIndex}\\.[a-zA-Z0-9]+`, "g"), `.filled.${contentIndex}.json`));
191
- }
192
- return {
193
- ...task,
194
- dictionaryOutput
195
- };
196
- }, {
197
- maxRetry: GROUP_MAX_RETRY,
198
- delay: RETRY_DELAY,
199
- onError: ({ error, attempt, maxRetry }) => appLogger(`${task.dictionaryPreset} ${(0, _intlayer_config.colorize)("Error:", _intlayer_config.ANSIColors.RED)} ${(0, _intlayer_config.colorize)(typeof error === "string" ? error : JSON.stringify(error), _intlayer_config.ANSIColors.GREY_DARK)} - Attempt ${(0, _intlayer_config.colorizeNumber)(attempt + 1)} of ${(0, _intlayer_config.colorizeNumber)(maxRetry)}`, { level: "error" }),
200
- onMaxTryReached: ({ error }) => appLogger(`${task.dictionaryPreset} ${(0, _intlayer_config.colorize)("Maximum number of retries reached:", _intlayer_config.ANSIColors.RED)} ${(0, _intlayer_config.colorize)(typeof error === "string" ? error : JSON.stringify(error), _intlayer_config.ANSIColors.GREY_DARK)}`, { level: "error" })
201
- })();
202
- };
203
-
204
- //#endregion
205
- exports.translateDictionary = translateDictionary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./deepMergeContent.cjs`),t=require(`./getFilterMissingContentPerLocale.cjs`),n=require(`./mergeChunks.cjs`);let r=require(`@intlayer/api`),i=require(`@intlayer/chokidar/utils`),a=require(`node:path`),o=require(`@intlayer/config/logger`),s=require(`@intlayer/config/utils`),c=require(`@intlayer/unmerged-dictionaries-entry`),l=require(`@intlayer/core/plugins`);const u=e=>!e.description||!e.title||!e.tags,d=1e3*10;let f=0;const p=async(p,m,h)=>{let g=(0,o.getAppLogger)(m),_=(0,r.getIntlayerAPIProxy)(void 0,m),{mode:v,aiOptions:y,fillMetadata:b,aiClient:x,aiConfig:S}={mode:`complete`,fillMetadata:!0,...h},C=()=>{f=0,h?.onSuccess?.()};return await(0,s.retryManager)(async()=>{let r=(0,c.getUnmergedDictionaries)(m),w=r[p.dictionaryKey].find(e=>e.localId===p.dictionaryLocalId);if(!w)return g(`${p.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,{level:`warn`}),{...p,dictionaryOutput:null};let T;if(b&&(u(w)||v===`review`)){let e=(0,l.getPerLocaleDictionary)(w,m.internationalization.defaultLocale);g(`${p.dictionaryPreset} Filling missing metadata for ${(0,o.colorizePath)((0,a.basename)(w.filePath))}`,{level:`info`});let t=async()=>x&&S?{data:await x.auditDictionaryMetadata({fileContent:JSON.stringify(e),aiConfig:S})}:await _.ai.auditContentDeclarationMetadata({fileContent:JSON.stringify(e),aiOptions:y});T=(h?.onHandle?await h.onHandle(t):await t()).data?.fileContent}let E=await Promise.all(p.targetLocales.map(async c=>{let u=structuredClone(w),m;if(typeof w.locale==`string`){let e=w.filePath?.replace(RegExp(`/${p.sourceLocale}/`,`g`),`/${c}/`),n=e?r[p.dictionaryKey]?.find(t=>t.filePath===e&&t.locale===c):void 0;m=n??{key:w.key,content:{},filePath:e,locale:c},v===`complete`&&(u=t.getFilterMissingContentPerLocale(u,n))}else v===`complete`&&(u=(0,l.getFilterMissingTranslationsDictionary)(u,c)),u=(0,l.getPerLocaleDictionary)(u,p.sourceLocale),m=(0,l.getPerLocaleDictionary)(w,c);let b=(0,o.colon)([(0,o.colorize)(`[`,o.ANSIColors.GREY_DARK),(0,i.formatLocale)(c),(0,o.colorize)(`]`,o.ANSIColors.GREY_DARK)].join(``),{colSize:18}),E=(e,t)=>t<=1?``:(0,o.colon)([(0,o.colorize)(`[`,o.ANSIColors.GREY_DARK),(0,o.colorizeNumber)(e+1),(0,o.colorize)(`/${t}`,o.ANSIColors.GREY_DARK),(0,o.colorize)(`]`,o.ANSIColors.GREY_DARK)].join(``),{colSize:5});g(`${p.dictionaryPreset}${b} Preparing ${(0,o.colorizePath)((0,a.basename)(m.filePath))}`,{level:`info`});let D=typeof u.content==`object`&&u.content!==null||Array.isArray(u.content),O=(0,i.chunkJSON)(D?u.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:u.content},7e3),k=O.length;k>1&&g(`${p.dictionaryPreset}${b} Split into ${(0,o.colorizeNumber)(k)} chunks for translation`,{level:`info`});let A=[],j=O.map(e=>{let t=E(e.index,e.total);k>1&&g(`${p.dictionaryPreset}${b}${t} Translating chunk`,{level:`info`});let n=(0,i.reconstructFromSingleChunk)(e),r=(0,i.reduceObjectFormat)(D?m.content:{__INTLAYER_ROOT_PRIMITIVE_CONTENT__:m.content},n),a=async()=>await(0,s.retryManager)(async()=>{let e;if(e=x&&S?await x.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:u.description??T?.description??``,entryLocale:p.sourceLocale,outputLocale:c,mode:v,aiConfig:S}):await _.ai.translateJSON({entryFileContent:n,presetOutputContent:r,dictionaryDescription:u.description??T?.description??``,entryLocale:p.sourceLocale,outputLocale:c,mode:v,aiOptions:y}).then(e=>e.data),!e?.fileContent)throw Error(`No content result`);let{isIdentic:t}=(0,i.verifyIdenticObjectFormat)(e.fileContent,n);if(!t)throw Error(`Translation result does not match expected format`);return C(),e.fileContent},{maxRetry:3,delay:d,onError:({error:t,attempt:n,maxRetry:r})=>{let i=E(e.index,e.total);g(`${p.dictionaryPreset}${b}${i} ${(0,o.colorize)(`Error filling:`,o.ANSIColors.RED)} ${(0,o.colorize)(typeof t==`string`?t:JSON.stringify(t),o.ANSIColors.GREY_DARK)} - Attempt ${(0,o.colorizeNumber)(n+1)} of ${(0,o.colorizeNumber)(r)}`,{level:`error`}),f+=1,f>=10&&(g(`There is something wrong.`,{level:`error`}),process.exit(1))}})();return(h?.onHandle?h.onHandle(a):a()).then(t=>({chunk:e,result:t}))});(await Promise.all(j)).sort((e,t)=>e.chunk.index-t.chunk.index).forEach(({result:e})=>{A.push(e)});let M=n.mergeChunks(A),N={...u,content:M}.content;return D||(N=N?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__),typeof w.locale==`string`&&(N=e.deepMergeContent(m.content??{},N)),[c,N]})),D=Object.fromEntries(E),O={...(0,l.getMultilingualDictionary)(w.locale?{...w,key:w.key,content:{}}:w),locale:void 0,...T};for(let e of p.targetLocales)D[e]&&(O=(0,l.insertContentInDictionary)(O,D[e],e));if(g(`${p.dictionaryPreset} ${(0,o.colorize)(`Translation completed successfully`,o.ANSIColors.GREEN)} for ${(0,o.colorizePath)((0,a.basename)(O.filePath))}`,{level:`info`}),w.locale&&(w.fill===!0||w.fill===void 0)&&w.location===`local`){let e=w.filePath.split(`.`).slice(0,-1),t=e[e.length-1];return JSON.parse(JSON.stringify({...p,dictionaryOutput:{...O,fill:void 0,filled:!0}}).replaceAll(RegExp(`\\.${t}\\.[a-zA-Z0-9]+`,`g`),`.filled.${t}.json`))}return{...p,dictionaryOutput:O}},{maxRetry:2,delay:d,onError:({error:e,attempt:t,maxRetry:n})=>g(`${p.dictionaryPreset} ${(0,o.colorize)(`Error:`,o.ANSIColors.RED)} ${(0,o.colorize)(typeof e==`string`?e:JSON.stringify(e),o.ANSIColors.GREY_DARK)} - Attempt ${(0,o.colorizeNumber)(t+1)} of ${(0,o.colorizeNumber)(n)}`,{level:`error`}),onMaxTryReached:({error:e})=>g(`${p.dictionaryPreset} ${(0,o.colorize)(`Maximum number of retries reached:`,o.ANSIColors.RED)} ${(0,o.colorize)(typeof e==`string`?e:JSON.stringify(e),o.ANSIColors.GREY_DARK)}`,{level:`error`})})()};exports.translateDictionary=p;
206
2
  //# sourceMappingURL=translateDictionary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"translateDictionary.cjs","names":["getFilterMissingContentPerLocale","ANSIColors","mergeChunks","deepMergeContent"],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n retryManager,\n} from '@intlayer/config';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\nimport { mergeChunks } from './mergeChunks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<typeof import('@intlayer/chokidar').getGlobalLimiter>;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const contentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n const mergedContent = mergeChunks(chunkResult);\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":";;;;;;;;;;;;;AAkDA,MAAM,sBAAsB,eAC1B,CAAC,WAAW,eAAe,CAAC,WAAW,SAAS,CAAC,WAAW;AAE9D,MAAM,aAAa;AACnB,MAAM,kBAAkB;AACxB,MAAM,YAAY;AAClB,MAAM,cAAc,MAAO;AAE3B,MAAM,uBAAuB;AAC7B,IAAI,kBAAkB;AAEtB,MAAa,sBAAsB,OACjC,MACA,eACA,YACuC;CACvC,MAAM,+CAAyB,cAAc;CAC7C,MAAM,qDAAkC,QAAW,cAAc;CAEjE,MAAM,EAAE,MAAM,WAAW,cAAc,UAAU,aAAa;EAC5D,MAAM;EACN,cAAc;EACd,GAAG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IAEH;EACE,UAAU;EACV,OAAO;EACP,UAAU,EAAE,OAAO,SAAS,eAC1B,UACE,GAAG,KAAK,iBAAiB,kCAAY,UAAUA,4BAAW,IAAI,CAAC,kCAAY,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM,EAAEA,4BAAW,UAAU,CAAC,kDAA4B,UAAU,EAAE,CAAC,2CAAqB,SAAS,IACnO,EACE,OAAO,SACR,CACF;EACH,kBAAkB,EAAE,YAClB,UACE,GAAG,KAAK,iBAAiB,kCAAY,sCAAsCA,4BAAW,IAAI,CAAC,kCAAY,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,MAAM,EAAEA,4BAAW,UAAU,IACvL,EACE,OAAO,SACR,CACF;EACJ,CACF,EAAE"}
1
+ {"version":3,"file":"translateDictionary.cjs","names":["getFilterMissingContentPerLocale","ANSIColors","mergeChunks","deepMergeContent"],"sources":["../../../src/fill/translateDictionary.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport type { AIConfig } from '@intlayer/ai';\nimport { type AIOptions, getIntlayerAPIProxy } from '@intlayer/api';\nimport {\n chunkJSON,\n formatLocale,\n type JsonChunk,\n reconstructFromSingleChunk,\n reduceObjectFormat,\n verifyIdenticObjectFormat,\n} from '@intlayer/chokidar/utils';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n colorizePath,\n getAppLogger,\n} from '@intlayer/config/logger';\nimport { retryManager } from '@intlayer/config/utils';\nimport {\n getFilterMissingTranslationsDictionary,\n getMultilingualDictionary,\n getPerLocaleDictionary,\n insertContentInDictionary,\n} from '@intlayer/core/plugins';\nimport type { Dictionary, IntlayerConfig, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\nimport type { AIClient } from '../utils/setupAI';\nimport { deepMergeContent } from './deepMergeContent';\nimport { getFilterMissingContentPerLocale } from './getFilterMissingContentPerLocale';\nimport type { TranslationTask } from './listTranslationsTasks';\nimport { mergeChunks } from './mergeChunks';\n\ntype TranslateDictionaryResult = TranslationTask & {\n dictionaryOutput: Dictionary | null;\n};\n\ntype TranslateDictionaryOptions = {\n mode: 'complete' | 'review';\n aiOptions?: AIOptions;\n fillMetadata?: boolean;\n onHandle?: ReturnType<\n typeof import('@intlayer/chokidar/utils').getGlobalLimiter\n >;\n onSuccess?: () => void;\n onError?: (error: unknown) => void;\n getAbortError?: () => Error | null;\n aiClient?: AIClient;\n aiConfig?: AIConfig;\n};\n\nconst hasMissingMetadata = (dictionary: Dictionary) =>\n !dictionary.description || !dictionary.title || !dictionary.tags;\n\nconst CHUNK_SIZE = 7000; // GPT-5 Mini safe input size\nconst GROUP_MAX_RETRY = 2;\nconst MAX_RETRY = 3;\nconst RETRY_DELAY = 1000 * 10; // 10 seconds\n\nconst MAX_FOLLOWING_ERRORS = 10; // 10 errors in a row, hard exit the process\nlet followingErrors = 0;\n\nexport const translateDictionary = async (\n task: TranslationTask,\n configuration: IntlayerConfig,\n options?: TranslateDictionaryOptions\n): Promise<TranslateDictionaryResult> => {\n const appLogger = getAppLogger(configuration);\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const { mode, aiOptions, fillMetadata, aiClient, aiConfig } = {\n mode: 'complete',\n fillMetadata: true,\n ...options,\n } as const;\n\n const notifySuccess = () => {\n followingErrors = 0;\n options?.onSuccess?.();\n };\n\n const result = await retryManager(\n async () => {\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n\n const baseUnmergedDictionary: Dictionary | undefined =\n unmergedDictionariesRecord[task.dictionaryKey].find(\n (dict) => dict.localId === task.dictionaryLocalId\n );\n\n if (!baseUnmergedDictionary) {\n appLogger(\n `${task.dictionaryPreset}Dictionary not found in unmergedDictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n return { ...task, dictionaryOutput: null };\n }\n\n let metadata:\n | Pick<Dictionary, 'description' | 'title' | 'tags'>\n | undefined;\n\n if (\n fillMetadata &&\n (hasMissingMetadata(baseUnmergedDictionary) || mode === 'review')\n ) {\n const defaultLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n configuration.internationalization.defaultLocale\n );\n\n appLogger(\n `${task.dictionaryPreset} Filling missing metadata for ${colorizePath(basename(baseUnmergedDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const runAudit = async () => {\n if (aiClient && aiConfig) {\n const result = await aiClient.auditDictionaryMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiConfig,\n });\n\n return {\n data: result,\n };\n }\n\n return await intlayerAPI.ai.auditContentDeclarationMetadata({\n fileContent: JSON.stringify(defaultLocaleDictionary),\n aiOptions,\n });\n };\n\n const metadataResult = options?.onHandle\n ? await options.onHandle(runAudit)\n : await runAudit();\n\n metadata = metadataResult.data?.fileContent;\n }\n\n const translatedContentResults = await Promise.all(\n task.targetLocales.map(async (targetLocale) => {\n /**\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * targetLocale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\n // Reset to base dictionary for each locale to ensure we filter from the original\n let dictionaryToProcess = structuredClone(baseUnmergedDictionary);\n\n let targetLocaleDictionary: Dictionary;\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // For per-locale files, the content is already in simple JSON format (not translation nodes)\n // The base dictionary is already the source locale content\n\n // Load the existing target locale dictionary\n const targetLocaleFilePath =\n baseUnmergedDictionary.filePath?.replace(\n new RegExp(`/${task.sourceLocale}/`, 'g'),\n `/${targetLocale}/`\n );\n\n // Find the target locale dictionary in unmerged dictionaries\n const targetUnmergedDictionary = targetLocaleFilePath\n ? unmergedDictionariesRecord[task.dictionaryKey]?.find(\n (dict) =>\n dict.filePath === targetLocaleFilePath &&\n dict.locale === targetLocale\n )\n : undefined;\n\n targetLocaleDictionary = targetUnmergedDictionary ?? {\n key: baseUnmergedDictionary.key,\n content: {},\n filePath: targetLocaleFilePath,\n locale: targetLocale,\n };\n\n // In complete mode, filter out already translated content\n if (mode === 'complete') {\n dictionaryToProcess = getFilterMissingContentPerLocale(\n dictionaryToProcess,\n targetUnmergedDictionary\n );\n }\n } else {\n // For multilingual dictionaries\n if (mode === 'complete') {\n // Remove all nodes that don't have any content to translate\n dictionaryToProcess = getFilterMissingTranslationsDictionary(\n dictionaryToProcess,\n targetLocale\n );\n }\n\n dictionaryToProcess = getPerLocaleDictionary(\n dictionaryToProcess,\n task.sourceLocale\n );\n\n targetLocaleDictionary = getPerLocaleDictionary(\n baseUnmergedDictionary,\n targetLocale\n );\n }\n\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 18 }\n );\n\n const createChunkPreset = (\n chunkIndex: number,\n totalChunks: number\n ) => {\n if (totalChunks <= 1) return '';\n return colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n colorizeNumber(chunkIndex + 1),\n colorize(`/${totalChunks}`, ANSIColors.GREY_DARK),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 5 }\n );\n };\n\n appLogger(\n `${task.dictionaryPreset}${localePreset} Preparing ${colorizePath(basename(targetLocaleDictionary.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n const isContentStructured =\n (typeof dictionaryToProcess.content === 'object' &&\n dictionaryToProcess.content !== null) ||\n Array.isArray(dictionaryToProcess.content);\n\n const contentToProcess = isContentStructured\n ? dictionaryToProcess.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n dictionaryToProcess.content,\n };\n\n const chunkedJsonContent: JsonChunk[] = chunkJSON(\n contentToProcess as unknown as Record<string, any>,\n CHUNK_SIZE\n );\n\n const nbOfChunks = chunkedJsonContent.length;\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset} Split into ${colorizeNumber(nbOfChunks)} chunks for translation`,\n {\n level: 'info',\n }\n );\n }\n\n const chunkResult: JsonChunk[] = [];\n\n // Process chunks in parallel (globally throttled) to allow concurrent translation\n const chunkPromises = chunkedJsonContent.map((chunk) => {\n const chunkPreset = createChunkPreset(chunk.index, chunk.total);\n\n if (nbOfChunks > 1) {\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} Translating chunk`,\n {\n level: 'info',\n }\n );\n }\n\n // Reconstruct partial JSON content from this chunk's patches\n const chunkContent = reconstructFromSingleChunk(chunk);\n const presetOutputContent = reduceObjectFormat(\n isContentStructured\n ? targetLocaleDictionary.content\n : {\n __INTLAYER_ROOT_PRIMITIVE_CONTENT__:\n targetLocaleDictionary.content,\n },\n chunkContent\n ) as unknown as JSON;\n\n const executeTranslation = async () => {\n return await retryManager(\n async () => {\n let translationResult: any;\n\n if (aiClient && aiConfig) {\n translationResult = await aiClient.translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiConfig,\n });\n } else {\n translationResult = await intlayerAPI.ai\n .translateJSON({\n entryFileContent: chunkContent as unknown as JSON,\n presetOutputContent,\n dictionaryDescription:\n dictionaryToProcess.description ??\n metadata?.description ??\n '',\n entryLocale: task.sourceLocale,\n outputLocale: targetLocale,\n mode,\n aiOptions,\n })\n .then((result) => result.data);\n }\n\n if (!translationResult?.fileContent) {\n throw new Error('No content result');\n }\n\n const { isIdentic } = verifyIdenticObjectFormat(\n translationResult.fileContent,\n chunkContent\n );\n\n if (!isIdentic) {\n throw new Error(\n 'Translation result does not match expected format'\n );\n }\n\n notifySuccess();\n return translationResult.fileContent;\n },\n {\n maxRetry: MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) => {\n const chunkPreset = createChunkPreset(\n chunk.index,\n chunk.total\n );\n appLogger(\n `${task.dictionaryPreset}${localePreset}${chunkPreset} ${colorize('Error filling:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n );\n\n followingErrors += 1;\n\n if (followingErrors >= MAX_FOLLOWING_ERRORS) {\n appLogger(`There is something wrong.`, {\n level: 'error',\n });\n process.exit(1); // 1 for error\n }\n },\n }\n )();\n };\n\n const wrapped = options?.onHandle\n ? options.onHandle(executeTranslation) // queued in global limiter\n : executeTranslation(); // no global limiter\n\n return wrapped.then((result) => ({ chunk, result }));\n });\n\n // Wait for all chunks for this locale in parallel (still capped by global limiter)\n const chunkResults = await Promise.all(chunkPromises);\n\n // Maintain order\n chunkResults\n .sort((chunkA, chunkB) => chunkA.chunk.index - chunkB.chunk.index)\n .forEach(({ result }) => {\n chunkResult.push(result);\n });\n\n // Merge partial JSON objects produced from each chunk into a single object\n const mergedContent = mergeChunks(chunkResult);\n\n const merged = {\n ...dictionaryToProcess,\n content: mergedContent,\n };\n\n // For per-locale files, merge the newly translated content with existing target content\n let finalContent = merged.content;\n\n if (!isContentStructured) {\n finalContent = (finalContent as any)\n ?.__INTLAYER_ROOT_PRIMITIVE_CONTENT__;\n }\n\n if (typeof baseUnmergedDictionary.locale === 'string') {\n // Deep merge: existing content + newly translated content\n finalContent = deepMergeContent(\n targetLocaleDictionary.content ?? {},\n finalContent\n );\n }\n\n return [targetLocale, finalContent] as const;\n })\n );\n\n const translatedContent: Partial<Record<Locale, Dictionary['content']>> =\n Object.fromEntries(translatedContentResults);\n\n const baseDictionary = baseUnmergedDictionary.locale\n ? {\n ...baseUnmergedDictionary,\n key: baseUnmergedDictionary.key!,\n content: {},\n }\n : baseUnmergedDictionary;\n\n let dictionaryOutput: Dictionary = {\n ...getMultilingualDictionary(baseDictionary),\n locale: undefined, // Ensure the dictionary is multilingual\n ...metadata,\n };\n\n for (const targetLocale of task.targetLocales) {\n if (translatedContent[targetLocale]) {\n dictionaryOutput = insertContentInDictionary(\n dictionaryOutput,\n translatedContent[targetLocale],\n targetLocale\n );\n }\n }\n\n appLogger(\n `${task.dictionaryPreset} ${colorize('Translation completed successfully', ANSIColors.GREEN)} for ${colorizePath(basename(dictionaryOutput.filePath!))}`,\n {\n level: 'info',\n }\n );\n\n if (\n baseUnmergedDictionary.locale &&\n (baseUnmergedDictionary.fill === true ||\n baseUnmergedDictionary.fill === undefined) &&\n baseUnmergedDictionary.location === 'local'\n ) {\n const dictionaryFilePath = baseUnmergedDictionary\n .filePath!.split('.')\n .slice(0, -1);\n\n const contentIndex = dictionaryFilePath[dictionaryFilePath.length - 1];\n\n return JSON.parse(\n JSON.stringify({\n ...task,\n dictionaryOutput: {\n ...dictionaryOutput,\n fill: undefined,\n filled: true,\n },\n }).replaceAll(\n new RegExp(`\\\\.${contentIndex}\\\\.[a-zA-Z0-9]+`, 'g'),\n `.filled.${contentIndex}.json`\n )\n );\n }\n\n return {\n ...task,\n dictionaryOutput,\n };\n },\n {\n maxRetry: GROUP_MAX_RETRY,\n delay: RETRY_DELAY,\n onError: ({ error, attempt, maxRetry }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Error:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)} - Attempt ${colorizeNumber(attempt + 1)} of ${colorizeNumber(maxRetry)}`,\n {\n level: 'error',\n }\n ),\n onMaxTryReached: ({ error }) =>\n appLogger(\n `${task.dictionaryPreset} ${colorize('Maximum number of retries reached:', ANSIColors.RED)} ${colorize(typeof error === 'string' ? error : JSON.stringify(error), ANSIColors.GREY_DARK)}`,\n {\n level: 'error',\n }\n ),\n }\n )();\n\n return result as TranslateDictionaryResult;\n};\n"],"mappings":"yeAoDA,MAAM,EAAsB,GAC1B,CAAC,EAAW,aAAe,CAAC,EAAW,OAAS,CAAC,EAAW,KAKxD,EAAc,IAAO,GAG3B,IAAI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CAGC,EAAuB,SACtB,EAAuB,OAAS,IAC/B,EAAuB,OAAS,IAAA,KAClC,EAAuB,WAAa,QACpC,CACA,IAAM,EAAqB,EACxB,SAAU,MAAM,IAAI,CACpB,MAAM,EAAG,GAAG,CAET,EAAe,EAAmB,EAAmB,OAAS,GAEpE,OAAO,KAAK,MACV,KAAK,UAAU,CACb,GAAG,EACH,iBAAkB,CAChB,GAAG,EACH,KAAM,IAAA,GACN,OAAQ,GACT,CACF,CAAC,CAAC,WACG,OAAO,MAAM,EAAa,iBAAkB,IAAI,CACpD,WAAW,EAAa,OACzB,CACF,CAGH,MAAO,CACL,GAAG,EACH,mBACD,EAEH,CACE,SAAU,EACV,MAAO,EACP,SAAU,CAAE,QAAO,UAAS,cAC1B,EACE,GAAG,EAAK,iBAAiB,IAAA,EAAA,EAAA,UAAY,SAAUA,EAAAA,WAAW,IAAI,CAAC,IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,CAAC,cAAA,EAAA,EAAA,gBAA4B,EAAU,EAAE,CAAC,OAAA,EAAA,EAAA,gBAAqB,EAAS,GACnO,CACE,MAAO,QACR,CACF,CACH,iBAAkB,CAAE,WAClB,EACE,GAAG,EAAK,iBAAiB,IAAA,EAAA,EAAA,UAAY,qCAAsCA,EAAAA,WAAW,IAAI,CAAC,IAAA,EAAA,EAAA,UAAY,OAAO,GAAU,SAAW,EAAQ,KAAK,UAAU,EAAM,CAAEA,EAAAA,WAAW,UAAU,GACvL,CACE,MAAO,QACR,CACF,CACJ,CACF,EAAE"}
@@ -1,55 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_fill_formatFillData = require('./formatFillData.cjs');
4
- const require_fill_getAvailableLocalesInDictionary = require('./getAvailableLocalesInDictionary.cjs');
5
- let _intlayer_chokidar = require("@intlayer/chokidar");
6
- let _intlayer_config = require("@intlayer/config");
7
- let node_path = require("node:path");
8
- let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
9
-
10
- //#region src/fill/writeFill.ts
11
- const writeFill = async (contentDeclarationFile, outputLocales, parentLocales, configuration) => {
12
- const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
13
- const fullDictionary = (0, _intlayer_dictionaries_entry.getDictionaries)(configuration)[contentDeclarationFile.key];
14
- const { filePath } = contentDeclarationFile;
15
- if (!filePath) {
16
- appLogger("No file path found for dictionary", { level: "error" });
17
- return;
18
- }
19
- const fillOptions = contentDeclarationFile.fill ?? configuration.dictionary?.fill ?? true;
20
- if (fillOptions === false) {
21
- appLogger(`Auto fill is disabled for '${(0, _intlayer_config.colorizeKey)(fullDictionary.key)}'`, { level: "info" });
22
- return;
23
- }
24
- const requestedLocales = (outputLocales ?? configuration.internationalization.locales).filter((locale) => !parentLocales?.includes(locale));
25
- const availableLocales = require_fill_getAvailableLocalesInDictionary.getAvailableLocalesInDictionary(contentDeclarationFile);
26
- const localeList = requestedLocales.filter((locale) => availableLocales.includes(locale));
27
- if (localeList.length === 0) {
28
- appLogger(`No translations available for dictionary '${(0, _intlayer_config.colorizeKey)(fullDictionary.key)}'`, { level: "info" });
29
- return;
30
- }
31
- const fillData = require_fill_formatFillData.formatFillData(fillOptions, localeList, filePath, fullDictionary.key, configuration);
32
- for await (const output of fillData) {
33
- if (!output.filePath) {
34
- appLogger(`No file path found for auto filled content declaration for '${(0, _intlayer_config.colorizeKey)(fullDictionary.key)}'`, { level: "error" });
35
- continue;
36
- }
37
- const { fill, ...rest } = contentDeclarationFile;
38
- const relativeFilePath = (0, node_path.relative)(configuration.content.baseDir, output.filePath);
39
- await (0, _intlayer_chokidar.writeContentDeclaration)({
40
- ...rest,
41
- filled: true,
42
- locale: output.isPerLocale ? output.localeList[0] : void 0,
43
- localId: `${contentDeclarationFile.key}::local::${relativeFilePath}`,
44
- filePath: relativeFilePath
45
- }, configuration, { localeList: output.localeList });
46
- if (output.isPerLocale) {
47
- const sourceLocale = output.localeList[0];
48
- appLogger(`Auto filled per-locale content declaration for '${(0, _intlayer_config.colorizeKey)(fullDictionary.key)}' written to ${(0, _intlayer_chokidar.formatPath)(output.filePath)} for locale ${(0, _intlayer_chokidar.formatLocale)(sourceLocale)}`, { level: "info" });
49
- } else appLogger(`Auto filled content declaration for '${(0, _intlayer_config.colorizeKey)(fullDictionary.key)}' written to ${(0, _intlayer_chokidar.formatPath)(output.filePath)}`, { level: "info" });
50
- }
51
- };
52
-
53
- //#endregion
54
- exports.writeFill = writeFill;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./formatFillData.cjs`),t=require(`./getAvailableLocalesInDictionary.cjs`);let n=require(`@intlayer/chokidar/utils`),r=require(`node:path`),i=require(`@intlayer/config/logger`),a=require(`@intlayer/chokidar/build`),o=require(`@intlayer/dictionaries-entry`);const s=async(s,c,l,u)=>{let d=(0,i.getAppLogger)(u),f=(0,o.getDictionaries)(u)[s.key],{filePath:p}=s;if(!p){d(`No file path found for dictionary`,{level:`error`});return}let m=s.fill??u.dictionary?.fill??!0;if(m===!1){d(`Auto fill is disabled for '${(0,i.colorizeKey)(f.key)}'`,{level:`info`});return}let h=(c??u.internationalization.locales).filter(e=>!l?.includes(e)),g=t.getAvailableLocalesInDictionary(s),_=h.filter(e=>g.includes(e));if(_.length===0){d(`No translations available for dictionary '${(0,i.colorizeKey)(f.key)}'`,{level:`info`});return}let v=e.formatFillData(m,_,p,f.key,u);for await(let e of v){if(!e.filePath){d(`No file path found for auto filled content declaration for '${(0,i.colorizeKey)(f.key)}'`,{level:`error`});continue}let{fill:t,...o}=s,c=(0,r.relative)(u.content.baseDir,e.filePath);if(await(0,a.writeContentDeclaration)({...o,filled:!0,locale:e.isPerLocale?e.localeList[0]:void 0,localId:`${s.key}::local::${c}`,filePath:c},u,{localeList:e.localeList}),e.isPerLocale){let t=e.localeList[0];d(`Auto filled per-locale content declaration for '${(0,i.colorizeKey)(f.key)}' written to ${(0,n.formatPath)(e.filePath)} for locale ${(0,n.formatLocale)(t)}`,{level:`info`})}else d(`Auto filled content declaration for '${(0,i.colorizeKey)(f.key)}' written to ${(0,n.formatPath)(e.filePath)}`,{level:`info`})}};exports.writeFill=s;
55
2
  //# sourceMappingURL=writeFill.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeFill.cjs","names":["getAvailableLocalesInDictionary","formatFillData"],"sources":["../../../src/fill/writeFill.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport {\n formatLocale,\n formatPath,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport { colorizeKey, getAppLogger } from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Fill, IntlayerConfig, Locale } from '@intlayer/types';\nimport { type FillData, formatFillData } from './formatFillData';\nimport { getAvailableLocalesInDictionary } from './getAvailableLocalesInDictionary';\n\nexport const writeFill = async (\n contentDeclarationFile: Dictionary,\n outputLocales: Locale[],\n parentLocales: Locale[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n const dictionaries = getDictionaries(configuration);\n\n const fullDictionary = dictionaries[contentDeclarationFile.key];\n\n const { filePath } = contentDeclarationFile;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const fillOptions: Fill | undefined =\n contentDeclarationFile.fill ?? configuration.dictionary?.fill ?? true;\n\n if ((fillOptions as boolean) === false) {\n appLogger(\n `Auto fill is disabled for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const requestedLocales: Locale[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n // Get locales that actually have translations in the content\n const availableLocales = getAvailableLocalesInDictionary(\n contentDeclarationFile\n );\n\n // Only write files for locales that have actual translations\n const localeList = requestedLocales.filter((locale) =>\n availableLocales.includes(locale)\n );\n\n if (localeList.length === 0) {\n appLogger(\n `No translations available for dictionary '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const fillData: FillData[] = formatFillData(\n fillOptions as Fill,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n for await (const output of fillData) {\n if (!output.filePath) {\n appLogger(\n `No file path found for auto filled content declaration for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n // biome-ignore lint/correctness/noUnusedVariables: Just filtering out the fill property\n const { fill, ...rest } = contentDeclarationFile;\n\n const relativeFilePath = relative(\n configuration.content.baseDir,\n output.filePath\n );\n\n // write file\n await writeContentDeclaration(\n {\n ...rest,\n filled: true,\n locale: output.isPerLocale ? output.localeList[0] : undefined,\n localId: `${contentDeclarationFile.key}::local::${relativeFilePath}`,\n filePath: relativeFilePath,\n },\n configuration,\n {\n localeList: output.localeList,\n }\n );\n\n if (output.isPerLocale) {\n const sourceLocale = output.localeList[0];\n\n appLogger(\n `Auto filled per-locale content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)} for locale ${formatLocale(sourceLocale)}`,\n {\n level: 'info',\n }\n );\n } else {\n appLogger(\n `Auto filled content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n};\n"],"mappings":";;;;;;;;;;AAYA,MAAa,YAAY,OACvB,wBACA,eACA,eACA,kBACG;CACH,MAAM,+CAAyB,cAAc;CAG7C,MAAM,mEAF+B,cAAc,CAEf,uBAAuB;CAE3D,MAAM,EAAE,aAAa;AAErB,KAAI,CAAC,UAAU;AACb,YAAU,qCAAqC,EAC7C,OAAO,SACR,CAAC;AACF;;CAGF,MAAM,cACJ,uBAAuB,QAAQ,cAAc,YAAY,QAAQ;AAEnE,KAAK,gBAA4B,OAAO;AACtC,YACE,gEAA0C,eAAe,IAAI,CAAC,IAC9D,EACE,OAAO,QACR,CACF;AACD;;CAGF,MAAM,oBACJ,iBAAiB,cAAc,qBAAqB,SACpD,QAAQ,WAAW,CAAC,eAAe,SAAS,OAAO,CAAC;CAGtD,MAAM,mBAAmBA,6EACvB,uBACD;CAGD,MAAM,aAAa,iBAAiB,QAAQ,WAC1C,iBAAiB,SAAS,OAAO,CAClC;AAED,KAAI,WAAW,WAAW,GAAG;AAC3B,YACE,+EAAyD,eAAe,IAAI,CAAC,IAC7E,EACE,OAAO,QACR,CACF;AACD;;CAGF,MAAM,WAAuBC,2CAC3B,aACA,YACA,UACA,eAAe,KACf,cACD;AAED,YAAW,MAAM,UAAU,UAAU;AACnC,MAAI,CAAC,OAAO,UAAU;AACpB,aACE,iGAA2E,eAAe,IAAI,CAAC,IAC/F,EACE,OAAO,SACR,CACF;AACD;;EAIF,MAAM,EAAE,MAAM,GAAG,SAAS;EAE1B,MAAM,2CACJ,cAAc,QAAQ,SACtB,OAAO,SACR;AAGD,wDACE;GACE,GAAG;GACH,QAAQ;GACR,QAAQ,OAAO,cAAc,OAAO,WAAW,KAAK;GACpD,SAAS,GAAG,uBAAuB,IAAI,WAAW;GAClD,UAAU;GACX,EACD,eACA,EACE,YAAY,OAAO,YACpB,CACF;AAED,MAAI,OAAO,aAAa;GACtB,MAAM,eAAe,OAAO,WAAW;AAEvC,aACE,qFAA+D,eAAe,IAAI,CAAC,kDAA0B,OAAO,SAAS,CAAC,mDAA2B,aAAa,IACtK,EACE,OAAO,QACR,CACF;QAED,WACE,0EAAoD,eAAe,IAAI,CAAC,kDAA0B,OAAO,SAAS,IAClH,EACE,OAAO,QACR,CACF"}
1
+ {"version":3,"file":"writeFill.cjs","names":["getAvailableLocalesInDictionary","formatFillData"],"sources":["../../../src/fill/writeFill.ts"],"sourcesContent":["import { relative } from 'node:path';\nimport { writeContentDeclaration } from '@intlayer/chokidar/build';\nimport { formatLocale, formatPath } from '@intlayer/chokidar/utils';\nimport { colorizeKey, getAppLogger } from '@intlayer/config/logger';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, Fill, IntlayerConfig, Locale } from '@intlayer/types';\nimport { type FillData, formatFillData } from './formatFillData';\nimport { getAvailableLocalesInDictionary } from './getAvailableLocalesInDictionary';\n\nexport const writeFill = async (\n contentDeclarationFile: Dictionary,\n outputLocales: Locale[],\n parentLocales: Locale[],\n configuration: IntlayerConfig\n) => {\n const appLogger = getAppLogger(configuration);\n const dictionaries = getDictionaries(configuration);\n\n const fullDictionary = dictionaries[contentDeclarationFile.key];\n\n const { filePath } = contentDeclarationFile;\n\n if (!filePath) {\n appLogger('No file path found for dictionary', {\n level: 'error',\n });\n return;\n }\n\n const fillOptions: Fill | undefined =\n contentDeclarationFile.fill ?? configuration.dictionary?.fill ?? true;\n\n if ((fillOptions as boolean) === false) {\n appLogger(\n `Auto fill is disabled for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const requestedLocales: Locale[] = (\n outputLocales ?? configuration.internationalization.locales\n ).filter((locale) => !parentLocales?.includes(locale));\n\n // Get locales that actually have translations in the content\n const availableLocales = getAvailableLocalesInDictionary(\n contentDeclarationFile\n );\n\n // Only write files for locales that have actual translations\n const localeList = requestedLocales.filter((locale) =>\n availableLocales.includes(locale)\n );\n\n if (localeList.length === 0) {\n appLogger(\n `No translations available for dictionary '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'info',\n }\n );\n return;\n }\n\n const fillData: FillData[] = formatFillData(\n fillOptions as Fill,\n localeList,\n filePath,\n fullDictionary.key,\n configuration\n );\n\n for await (const output of fillData) {\n if (!output.filePath) {\n appLogger(\n `No file path found for auto filled content declaration for '${colorizeKey(fullDictionary.key)}'`,\n {\n level: 'error',\n }\n );\n continue;\n }\n\n // biome-ignore lint/correctness/noUnusedVariables: Just filtering out the fill property\n const { fill, ...rest } = contentDeclarationFile;\n\n const relativeFilePath = relative(\n configuration.content.baseDir,\n output.filePath\n );\n\n // write file\n await writeContentDeclaration(\n {\n ...rest,\n filled: true,\n locale: output.isPerLocale ? output.localeList[0] : undefined,\n localId: `${contentDeclarationFile.key}::local::${relativeFilePath}`,\n filePath: relativeFilePath,\n },\n configuration,\n {\n localeList: output.localeList,\n }\n );\n\n if (output.isPerLocale) {\n const sourceLocale = output.localeList[0];\n\n appLogger(\n `Auto filled per-locale content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)} for locale ${formatLocale(sourceLocale)}`,\n {\n level: 'info',\n }\n );\n } else {\n appLogger(\n `Auto filled content declaration for '${colorizeKey(fullDictionary.key)}' written to ${formatPath(output.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n};\n"],"mappings":"iYASA,MAAa,EAAY,MACvB,EACA,EACA,EACA,IACG,CACH,IAAM,GAAA,EAAA,EAAA,cAAyB,EAAc,CAGvC,GAAA,EAAA,EAAA,iBAF+B,EAAc,CAEf,EAAuB,KAErD,CAAE,YAAa,EAErB,GAAI,CAAC,EAAU,CACb,EAAU,oCAAqC,CAC7C,MAAO,QACR,CAAC,CACF,OAGF,IAAM,EACJ,EAAuB,MAAQ,EAAc,YAAY,MAAQ,GAEnE,GAAK,IAA4B,GAAO,CACtC,EACE,+BAAA,EAAA,EAAA,aAA0C,EAAe,IAAI,CAAC,GAC9D,CACE,MAAO,OACR,CACF,CACD,OAGF,IAAM,GACJ,GAAiB,EAAc,qBAAqB,SACpD,OAAQ,GAAW,CAAC,GAAe,SAAS,EAAO,CAAC,CAGhD,EAAmBA,EAAAA,gCACvB,EACD,CAGK,EAAa,EAAiB,OAAQ,GAC1C,EAAiB,SAAS,EAAO,CAClC,CAED,GAAI,EAAW,SAAW,EAAG,CAC3B,EACE,8CAAA,EAAA,EAAA,aAAyD,EAAe,IAAI,CAAC,GAC7E,CACE,MAAO,OACR,CACF,CACD,OAGF,IAAM,EAAuBC,EAAAA,eAC3B,EACA,EACA,EACA,EAAe,IACf,EACD,CAED,UAAW,IAAM,KAAU,EAAU,CACnC,GAAI,CAAC,EAAO,SAAU,CACpB,EACE,gEAAA,EAAA,EAAA,aAA2E,EAAe,IAAI,CAAC,GAC/F,CACE,MAAO,QACR,CACF,CACD,SAIF,GAAM,CAAE,OAAM,GAAG,GAAS,EAEpB,GAAA,EAAA,EAAA,UACJ,EAAc,QAAQ,QACtB,EAAO,SACR,CAiBD,GAdA,MAAA,EAAA,EAAA,yBACE,CACE,GAAG,EACH,OAAQ,GACR,OAAQ,EAAO,YAAc,EAAO,WAAW,GAAK,IAAA,GACpD,QAAS,GAAG,EAAuB,IAAI,WAAW,IAClD,SAAU,EACX,CACD,EACA,CACE,WAAY,EAAO,WACpB,CACF,CAEG,EAAO,YAAa,CACtB,IAAM,EAAe,EAAO,WAAW,GAEvC,EACE,oDAAA,EAAA,EAAA,aAA+D,EAAe,IAAI,CAAC,gBAAA,EAAA,EAAA,YAA0B,EAAO,SAAS,CAAC,eAAA,EAAA,EAAA,cAA2B,EAAa,GACtK,CACE,MAAO,OACR,CACF,MAED,EACE,yCAAA,EAAA,EAAA,aAAoD,EAAe,IAAI,CAAC,gBAAA,EAAA,EAAA,YAA0B,EAAO,SAAS,GAClH,CACE,MAAO,OACR,CACF"}
@@ -1,37 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_chokidar = require("@intlayer/chokidar");
4
- let _intlayer_config = require("@intlayer/config");
5
- let node_path = require("node:path");
6
- let _intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
7
-
8
- //#region src/getTargetDictionary.ts
9
- const ensureArray = (value) => [value].flat();
10
- const getTargetUnmergedDictionaries = async (options) => {
11
- const configuration = (0, _intlayer_config.getConfiguration)(options?.configOptions);
12
- const { baseDir } = configuration.content;
13
- const unmergedDictionariesRecord = (0, _intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
14
- let result = Object.values(unmergedDictionariesRecord).flat();
15
- if (typeof options?.file !== "undefined") {
16
- const relativeFilePaths = ensureArray(options?.file).map((file) => file.startsWith("/") ? (0, node_path.relative)(baseDir, file) : (0, node_path.join)("./", file));
17
- result = result.filter((dict) => dict.filePath && relativeFilePaths.includes(dict.filePath));
18
- }
19
- if (typeof options?.keys !== "undefined") result = result.filter((dict) => ensureArray(options?.keys)?.includes(dict.key));
20
- if (typeof options?.excludedKeys !== "undefined") result = result.filter((dict) => !ensureArray(options?.excludedKeys)?.includes(dict.key));
21
- if (typeof options?.pathFilter !== "undefined") result = result.filter((dict) => ensureArray(options?.pathFilter)?.includes(dict.filePath ?? ""));
22
- if (typeof options?.filter !== "undefined") result = result.filter(options?.filter);
23
- const gitOptions = options?.gitOptions;
24
- if (gitOptions) {
25
- const gitChangedFiles = await (0, _intlayer_chokidar.listGitFiles)(gitOptions);
26
- if (gitChangedFiles) result = result.filter((dict) => {
27
- if (!dict.filePath) return false;
28
- return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);
29
- });
30
- }
31
- return result;
32
- };
33
-
34
- //#endregion
35
- exports.ensureArray = ensureArray;
36
- exports.getTargetUnmergedDictionaries = getTargetUnmergedDictionaries;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`./_virtual/_rolldown/runtime.cjs`);let e=require(`@intlayer/config/node`),t=require(`node:path`),n=require(`@intlayer/chokidar/cli`),r=require(`@intlayer/unmerged-dictionaries-entry`);const i=e=>[e].flat(),a=async a=>{let o=(0,e.getConfiguration)(a?.configOptions),{baseDir:s}=o.content,c=(0,r.getUnmergedDictionaries)(o),l=Object.values(c).flat();if(a?.file!==void 0){let e=i(a?.file).map(e=>e.startsWith(`/`)?(0,t.relative)(s,e):(0,t.join)(`./`,e));l=l.filter(t=>t.filePath&&e.includes(t.filePath))}a?.keys!==void 0&&(l=l.filter(e=>i(a?.keys)?.includes(e.key))),a?.excludedKeys!==void 0&&(l=l.filter(e=>!i(a?.excludedKeys)?.includes(e.key))),a?.pathFilter!==void 0&&(l=l.filter(e=>i(a?.pathFilter)?.includes(e.filePath??``))),a?.filter!==void 0&&(l=l.filter(a?.filter));let u=a?.gitOptions;if(u){let e=await(0,n.listGitFiles)(u);e&&(l=l.filter(t=>t.filePath?e.some(e=>t.filePath===e):!1))}return l};exports.ensureArray=i,exports.getTargetUnmergedDictionaries=a;
37
2
  //# sourceMappingURL=getTargetDictionary.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTargetDictionary.cjs","names":[],"sources":["../../src/getTargetDictionary.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport { type ListGitFilesOptions, listGitFiles } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\n// Arguments for the fill function\nexport type GetTargetDictionaryOptions = {\n file?: string | string[];\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const getTargetUnmergedDictionaries = async (\n options?: GetTargetDictionaryOptions\n): Promise<Dictionary[]> => {\n const configuration = getConfiguration(options?.configOptions);\n\n const { baseDir } = configuration.content;\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options?.file !== 'undefined') {\n const fileArray = ensureArray(options?.file);\n const relativeFilePaths = fileArray.map((file) =>\n file.startsWith('/') ? relative(baseDir, file) : join('./', file)\n );\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n // Check for absolute path\n relativeFilePaths.includes(dict.filePath)\n );\n }\n\n if (typeof options?.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options?.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options?.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options?.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options?.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options?.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options?.filter !== 'undefined') {\n result = result.filter(options?.filter);\n }\n\n const gitOptions = options?.gitOptions;\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 result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,eAAkB,UAAwB,CAAC,MAAM,CAAC,MAAM;AAarE,MAAa,gCAAgC,OAC3C,YAC0B;CAC1B,MAAM,uDAAiC,SAAS,cAAc;CAE9D,MAAM,EAAE,YAAY,cAAc;CAElC,MAAM,gGAAqD,cAAc;CACzE,IAAI,SAAS,OAAO,OAAO,2BAA2B,CAAC,MAAM;AAG7D,KAAI,OAAO,SAAS,SAAS,aAAa;EAExC,MAAM,oBADY,YAAY,SAAS,KAAK,CACR,KAAK,SACvC,KAAK,WAAW,IAAI,2BAAY,SAAS,KAAK,uBAAQ,MAAM,KAAK,CAClE;AAED,WAAS,OAAO,QACb,SACC,KAAK,YAEL,kBAAkB,SAAS,KAAK,SAAS,CAC5C;;AAGH,KAAI,OAAO,SAAS,SAAS,YAC3B,UAAS,OAAO,QAAQ,SACtB,YAAY,SAAS,KAAK,EAAE,SAAS,KAAK,IAAI,CAC/C;AAGH,KAAI,OAAO,SAAS,iBAAiB,YACnC,UAAS,OAAO,QACb,SAAS,CAAC,YAAY,SAAS,aAAa,EAAE,SAAS,KAAK,IAAI,CAClE;AAGH,KAAI,OAAO,SAAS,eAAe,YACjC,UAAS,OAAO,QAAQ,SACtB,YAAY,SAAS,WAAW,EAAE,SAAS,KAAK,YAAY,GAAG,CAChE;AAGH,KAAI,OAAO,SAAS,WAAW,YAC7B,UAAS,OAAO,OAAO,SAAS,OAAO;CAGzC,MAAM,aAAa,SAAS;AAC5B,KAAI,YAAY;EACd,MAAM,kBAAkB,2CAAmB,WAAW;AAEtD,MAAI,gBAIF,UAAS,OAAO,QAAQ,SAAS;AAC/B,OAAI,CAAC,KAAK,SAAU,QAAO;AAE3B,UAAO,gBAAgB,MAAM,YAAY,KAAK,aAAa,QAAQ;IACnE;;AAIN,QAAO"}
1
+ {"version":3,"file":"getTargetDictionary.cjs","names":[],"sources":["../../src/getTargetDictionary.ts"],"sourcesContent":["import { join, relative } from 'node:path';\nimport { type ListGitFilesOptions, listGitFiles } from '@intlayer/chokidar/cli';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport type { Dictionary } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const ensureArray = <T>(value: T | T[]): T[] => [value].flat() as T[];\n\n// Arguments for the fill function\nexport type GetTargetDictionaryOptions = {\n file?: string | string[];\n keys?: string | string[];\n excludedKeys?: string | string[];\n filter?: (entry: Dictionary) => boolean; // DictionaryEntry needs to be defined\n pathFilter?: string | string[];\n gitOptions?: ListGitFilesOptions;\n configOptions?: GetConfigurationOptions;\n};\n\nexport const getTargetUnmergedDictionaries = async (\n options?: GetTargetDictionaryOptions\n): Promise<Dictionary[]> => {\n const configuration = getConfiguration(options?.configOptions);\n\n const { baseDir } = configuration.content;\n\n const unmergedDictionariesRecord = getUnmergedDictionaries(configuration);\n let result = Object.values(unmergedDictionariesRecord).flat();\n\n // 1. if filePath not defined, list all content declaration files based on unmerged dictionaries list\n if (typeof options?.file !== 'undefined') {\n const fileArray = ensureArray(options?.file);\n const relativeFilePaths = fileArray.map((file) =>\n file.startsWith('/') ? relative(baseDir, file) : join('./', file)\n );\n\n result = result.filter(\n (dict) =>\n dict.filePath &&\n // Check for absolute path\n relativeFilePaths.includes(dict.filePath)\n );\n }\n\n if (typeof options?.keys !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options?.keys)?.includes(dict.key)\n );\n }\n\n if (typeof options?.excludedKeys !== 'undefined') {\n result = result.filter(\n (dict) => !ensureArray(options?.excludedKeys)?.includes(dict.key)\n );\n }\n\n if (typeof options?.pathFilter !== 'undefined') {\n result = result.filter((dict) =>\n ensureArray(options?.pathFilter)?.includes(dict.filePath ?? '')\n );\n }\n\n if (typeof options?.filter !== 'undefined') {\n result = result.filter(options?.filter);\n }\n\n const gitOptions = options?.gitOptions;\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 result = result.filter((dict) => {\n if (!dict.filePath) return false;\n\n return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);\n });\n }\n }\n\n return result;\n};\n"],"mappings":"oQASA,MAAa,EAAkB,GAAwB,CAAC,EAAM,CAAC,MAAM,CAaxD,EAAgC,KAC3C,IAC0B,CAC1B,IAAM,GAAA,EAAA,EAAA,kBAAiC,GAAS,cAAc,CAExD,CAAE,WAAY,EAAc,QAE5B,GAAA,EAAA,EAAA,yBAAqD,EAAc,CACrE,EAAS,OAAO,OAAO,EAA2B,CAAC,MAAM,CAG7D,GAAW,GAAS,OAAS,OAAa,CAExC,IAAM,EADY,EAAY,GAAS,KAAK,CACR,IAAK,GACvC,EAAK,WAAW,IAAI,EAAA,EAAA,EAAA,UAAY,EAAS,EAAK,EAAA,EAAA,EAAA,MAAQ,KAAM,EAAK,CAClE,CAED,EAAS,EAAO,OACb,GACC,EAAK,UAEL,EAAkB,SAAS,EAAK,SAAS,CAC5C,CAGQ,GAAS,OAAS,SAC3B,EAAS,EAAO,OAAQ,GACtB,EAAY,GAAS,KAAK,EAAE,SAAS,EAAK,IAAI,CAC/C,EAGQ,GAAS,eAAiB,SACnC,EAAS,EAAO,OACb,GAAS,CAAC,EAAY,GAAS,aAAa,EAAE,SAAS,EAAK,IAAI,CAClE,EAGQ,GAAS,aAAe,SACjC,EAAS,EAAO,OAAQ,GACtB,EAAY,GAAS,WAAW,EAAE,SAAS,EAAK,UAAY,GAAG,CAChE,EAGQ,GAAS,SAAW,SAC7B,EAAS,EAAO,OAAO,GAAS,OAAO,EAGzC,IAAM,EAAa,GAAS,WAC5B,GAAI,EAAY,CACd,IAAM,EAAkB,MAAA,EAAA,EAAA,cAAmB,EAAW,CAElD,IAIF,EAAS,EAAO,OAAQ,GACjB,EAAK,SAEH,EAAgB,KAAM,GAAY,EAAK,WAAa,EAAQ,CAFxC,GAG3B,EAIN,OAAO"}
@@ -1,39 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_build = require('./build.cjs');
3
- const require_editor = require('./editor.cjs');
4
- const require_extract = require('./extract.cjs');
5
- const require_test_listMissingTranslations = require('./test/listMissingTranslations.cjs');
6
- const require_test_test = require('./test/test.cjs');
7
- const require_fill_fill = require('./fill/fill.cjs');
8
- const require_init = require('./init.cjs');
9
- const require_listContentDeclaration = require('./listContentDeclaration.cjs');
10
- const require_liveSync = require('./liveSync.cjs');
11
- const require_pull = require('./pull.cjs');
12
- const require_push_push = require('./push/push.cjs');
13
- const require_pushConfig = require('./pushConfig.cjs');
14
- const require_reviewDoc_reviewDoc = require('./reviewDoc/reviewDoc.cjs');
15
- const require_searchDoc = require('./searchDoc.cjs');
16
- const require_translateDoc_translateDoc = require('./translateDoc/translateDoc.cjs');
17
- const require_cli = require('./cli.cjs');
18
-
19
- exports.build = require_build.build;
20
- exports.dirname = require_cli.dirname;
21
- exports.extract = require_extract.extract;
22
- exports.fill = require_fill_fill.fill;
23
- exports.getDetectedPlatform = require_init.getDetectedPlatform;
24
- exports.init = require_init.init;
25
- exports.initSkills = require_init.initSkills;
26
- exports.listContentDeclaration = require_listContentDeclaration.listContentDeclaration;
27
- exports.listContentDeclarationRows = require_listContentDeclaration.listContentDeclarationRows;
28
- exports.listMissingTranslations = require_test_listMissingTranslations.listMissingTranslations;
29
- exports.listMissingTranslationsWithConfig = require_test_listMissingTranslations.listMissingTranslationsWithConfig;
30
- exports.liveSync = require_liveSync.liveSync;
31
- exports.pull = require_pull.pull;
32
- exports.push = require_push_push.push;
33
- exports.pushConfig = require_pushConfig.pushConfig;
34
- exports.reviewDoc = require_reviewDoc_reviewDoc.reviewDoc;
35
- exports.searchDoc = require_searchDoc.searchDoc;
36
- exports.setAPI = require_cli.setAPI;
37
- exports.startEditor = require_editor.startEditor;
38
- exports.testMissingTranslations = require_test_test.testMissingTranslations;
39
- exports.translateDoc = require_translateDoc_translateDoc.translateDoc;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./build.cjs`),t=require(`./editor.cjs`),n=require(`./extract.cjs`),r=require(`./test/listMissingTranslations.cjs`),i=require(`./test/test.cjs`),a=require(`./fill/fill.cjs`),o=require(`./init.cjs`),s=require(`./listContentDeclaration.cjs`),c=require(`./liveSync.cjs`),l=require(`./pull.cjs`),u=require(`./push/push.cjs`),d=require(`./pushConfig.cjs`),f=require(`./reviewDoc/reviewDoc.cjs`),p=require(`./searchDoc.cjs`),m=require(`./translateDoc/translateDoc.cjs`),h=require(`./cli.cjs`);exports.build=e.build,exports.dirname=h.dirname,exports.extract=n.extract,exports.fill=a.fill,exports.getDetectedPlatform=o.getDetectedPlatform,exports.init=o.init,exports.initSkills=o.initSkills,exports.listContentDeclaration=s.listContentDeclaration,exports.listContentDeclarationRows=s.listContentDeclarationRows,exports.listMissingTranslations=r.listMissingTranslations,exports.listMissingTranslationsWithConfig=r.listMissingTranslationsWithConfig,exports.liveSync=c.liveSync,exports.pull=l.pull,exports.push=u.push,exports.pushConfig=d.pushConfig,exports.reviewDoc=f.reviewDoc,exports.searchDoc=p.searchDoc,exports.setAPI=h.setAPI,exports.startEditor=t.startEditor,exports.testMissingTranslations=i.testMissingTranslations,exports.translateDoc=m.translateDoc;