@intlayer/cli 6.1.6 → 7.0.0-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/dist/cjs/IntlayerEventListener.cjs +187 -239
  2. package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
  3. package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
  4. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  5. package/dist/cjs/build.cjs +23 -42
  6. package/dist/cjs/build.cjs.map +1 -1
  7. package/dist/cjs/cli.cjs +370 -431
  8. package/dist/cjs/cli.cjs.map +1 -1
  9. package/dist/cjs/config.cjs +10 -35
  10. package/dist/cjs/config.cjs.map +1 -1
  11. package/dist/cjs/editor.cjs +51 -66
  12. package/dist/cjs/editor.cjs.map +1 -1
  13. package/dist/cjs/fill/fill.cjs +73 -301
  14. package/dist/cjs/fill/fill.cjs.map +1 -1
  15. package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
  16. package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
  17. package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
  18. package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
  19. package/dist/cjs/fill/formatFillData.cjs +50 -0
  20. package/dist/cjs/fill/formatFillData.cjs.map +1 -0
  21. package/dist/cjs/fill/groupLimiter.cjs +42 -0
  22. package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
  23. package/dist/cjs/fill/index.cjs +5 -25
  24. package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
  25. package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
  26. package/dist/cjs/fill/test-original-case.cjs +10 -0
  27. package/dist/cjs/fill/test-original-case.cjs.map +1 -0
  28. package/dist/cjs/fill/translateDictionary.cjs +148 -0
  29. package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
  30. package/dist/cjs/fill/writeAutoFill.cjs +48 -0
  31. package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
  32. package/dist/cjs/fill/writeFill.cjs +50 -0
  33. package/dist/cjs/fill/writeFill.cjs.map +1 -0
  34. package/dist/cjs/getTargetDictionary.cjs +36 -76
  35. package/dist/cjs/getTargetDictionary.cjs.map +1 -1
  36. package/dist/cjs/index.cjs +31 -45
  37. package/dist/cjs/listContentDeclaration.cjs +36 -64
  38. package/dist/cjs/listContentDeclaration.cjs.map +1 -1
  39. package/dist/cjs/liveSync.cjs +146 -221
  40. package/dist/cjs/liveSync.cjs.map +1 -1
  41. package/dist/cjs/pull.cjs +132 -195
  42. package/dist/cjs/pull.cjs.map +1 -1
  43. package/dist/cjs/push/pullLog.cjs +101 -144
  44. package/dist/cjs/push/pullLog.cjs.map +1 -1
  45. package/dist/cjs/push/push.cjs +159 -249
  46. package/dist/cjs/push/push.cjs.map +1 -1
  47. package/dist/cjs/pushConfig.cjs +18 -45
  48. package/dist/cjs/pushConfig.cjs.map +1 -1
  49. package/dist/cjs/pushLog.cjs +87 -128
  50. package/dist/cjs/pushLog.cjs.map +1 -1
  51. package/dist/cjs/reviewDoc.cjs +183 -291
  52. package/dist/cjs/reviewDoc.cjs.map +1 -1
  53. package/dist/cjs/test/index.cjs +52 -91
  54. package/dist/cjs/test/index.cjs.map +1 -1
  55. package/dist/cjs/test/listMissingTranslations.cjs +35 -62
  56. package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
  57. package/dist/cjs/translateDoc.cjs +127 -221
  58. package/dist/cjs/translateDoc.cjs.map +1 -1
  59. package/dist/cjs/utils/calculateChunks.cjs +85 -115
  60. package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
  61. package/dist/cjs/utils/checkAccess.cjs +33 -72
  62. package/dist/cjs/utils/checkAccess.cjs.map +1 -1
  63. package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
  64. package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
  65. package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
  66. package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
  67. package/dist/cjs/utils/chunkInference.cjs +28 -47
  68. package/dist/cjs/utils/chunkInference.cjs.map +1 -1
  69. package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
  70. package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
  71. package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
  72. package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
  73. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
  74. package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
  75. package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
  76. package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
  77. package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
  78. package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
  79. package/dist/cjs/utils/listSpecialChars.cjs +49 -73
  80. package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
  81. package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
  82. package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
  83. package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
  84. package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
  85. package/dist/cjs/watch.cjs +21 -39
  86. package/dist/cjs/watch.cjs.map +1 -1
  87. package/dist/esm/IntlayerEventListener.mjs +178 -201
  88. package/dist/esm/IntlayerEventListener.mjs.map +1 -1
  89. package/dist/esm/_virtual/_utils_asset.mjs +100 -0
  90. package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
  91. package/dist/esm/build.mjs +20 -23
  92. package/dist/esm/build.mjs.map +1 -1
  93. package/dist/esm/cli.mjs +349 -380
  94. package/dist/esm/cli.mjs.map +1 -1
  95. package/dist/esm/config.mjs +8 -14
  96. package/dist/esm/config.mjs.map +1 -1
  97. package/dist/esm/editor.mjs +47 -41
  98. package/dist/esm/editor.mjs.map +1 -1
  99. package/dist/esm/fill/fill.mjs +68 -300
  100. package/dist/esm/fill/fill.mjs.map +1 -1
  101. package/dist/esm/fill/formatAutoFillData.mjs +47 -81
  102. package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
  103. package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
  104. package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
  105. package/dist/esm/fill/formatFillData.mjs +50 -0
  106. package/dist/esm/fill/formatFillData.mjs.map +1 -0
  107. package/dist/esm/fill/groupLimiter.mjs +40 -0
  108. package/dist/esm/fill/groupLimiter.mjs.map +1 -0
  109. package/dist/esm/fill/index.mjs +4 -3
  110. package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
  111. package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
  112. package/dist/esm/fill/test-original-case.mjs +10 -0
  113. package/dist/esm/fill/test-original-case.mjs.map +1 -0
  114. package/dist/esm/fill/translateDictionary.mjs +141 -0
  115. package/dist/esm/fill/translateDictionary.mjs.map +1 -0
  116. package/dist/esm/fill/writeAutoFill.mjs +44 -0
  117. package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
  118. package/dist/esm/fill/writeFill.mjs +45 -0
  119. package/dist/esm/fill/writeFill.mjs.map +1 -0
  120. package/dist/esm/getTargetDictionary.mjs +27 -48
  121. package/dist/esm/getTargetDictionary.mjs.map +1 -1
  122. package/dist/esm/index.mjs +15 -13
  123. package/dist/esm/listContentDeclaration.mjs +28 -43
  124. package/dist/esm/listContentDeclaration.mjs.map +1 -1
  125. package/dist/esm/liveSync.mjs +135 -187
  126. package/dist/esm/liveSync.mjs.map +1 -1
  127. package/dist/esm/pull.mjs +125 -178
  128. package/dist/esm/pull.mjs.map +1 -1
  129. package/dist/esm/push/pullLog.mjs +99 -125
  130. package/dist/esm/push/pullLog.mjs.map +1 -1
  131. package/dist/esm/push/push.mjs +149 -221
  132. package/dist/esm/push/push.mjs.map +1 -1
  133. package/dist/esm/pushConfig.mjs +14 -23
  134. package/dist/esm/pushConfig.mjs.map +1 -1
  135. package/dist/esm/pushLog.mjs +85 -109
  136. package/dist/esm/pushLog.mjs.map +1 -1
  137. package/dist/esm/reviewDoc.mjs +167 -264
  138. package/dist/esm/reviewDoc.mjs.map +1 -1
  139. package/dist/esm/test/index.mjs +47 -73
  140. package/dist/esm/test/index.mjs.map +1 -1
  141. package/dist/esm/test/listMissingTranslations.mjs +30 -41
  142. package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
  143. package/dist/esm/translateDoc.mjs +114 -193
  144. package/dist/esm/translateDoc.mjs.map +1 -1
  145. package/dist/esm/utils/calculateChunks.mjs +83 -91
  146. package/dist/esm/utils/calculateChunks.mjs.map +1 -1
  147. package/dist/esm/utils/checkAccess.mjs +28 -46
  148. package/dist/esm/utils/checkAccess.mjs.map +1 -1
  149. package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
  150. package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
  151. package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
  152. package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
  153. package/dist/esm/utils/chunkInference.mjs +24 -24
  154. package/dist/esm/utils/chunkInference.mjs.map +1 -1
  155. package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
  156. package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
  157. package/dist/esm/utils/formatTimeDiff.mjs +16 -19
  158. package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
  159. package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
  160. package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
  161. package/dist/esm/utils/getOutputFilePath.mjs +70 -62
  162. package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
  163. package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
  164. package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
  165. package/dist/esm/utils/listSpecialChars.mjs +48 -49
  166. package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
  167. package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
  168. package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
  169. package/dist/esm/utils/reorderParagraphs.mjs +85 -93
  170. package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
  171. package/dist/esm/watch.mjs +17 -17
  172. package/dist/esm/watch.mjs.map +1 -1
  173. package/dist/types/IntlayerEventListener.d.ts +63 -59
  174. package/dist/types/IntlayerEventListener.d.ts.map +1 -1
  175. package/dist/types/build.d.ts +10 -7
  176. package/dist/types/build.d.ts.map +1 -1
  177. package/dist/types/cli.d.ts +13 -10
  178. package/dist/types/cli.d.ts.map +1 -1
  179. package/dist/types/config.d.ts +7 -4
  180. package/dist/types/config.d.ts.map +1 -1
  181. package/dist/types/editor.d.ts +6 -4
  182. package/dist/types/editor.d.ts.map +1 -1
  183. package/dist/types/fill/fill.d.ts +20 -14
  184. package/dist/types/fill/fill.d.ts.map +1 -1
  185. package/dist/types/fill/formatAutoFillData.d.ts +10 -7
  186. package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
  187. package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
  188. package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
  189. package/dist/types/fill/formatFillData.d.ts +12 -0
  190. package/dist/types/fill/formatFillData.d.ts.map +1 -0
  191. package/dist/types/fill/groupLimiter.d.ts +15 -0
  192. package/dist/types/fill/groupLimiter.d.ts.map +1 -0
  193. package/dist/types/fill/index.d.ts +3 -3
  194. package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
  195. package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
  196. package/dist/types/fill/test-original-case.d.ts +1 -0
  197. package/dist/types/fill/translateDictionary.d.ts +19 -0
  198. package/dist/types/fill/translateDictionary.d.ts.map +1 -0
  199. package/dist/types/fill/writeAutoFill.d.ts +7 -0
  200. package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
  201. package/dist/types/fill/writeFill.d.ts +7 -0
  202. package/dist/types/fill/writeFill.d.ts.map +1 -0
  203. package/dist/types/getTargetDictionary.d.ts +17 -13
  204. package/dist/types/getTargetDictionary.d.ts.map +1 -1
  205. package/dist/types/index.d.ts +15 -14
  206. package/dist/types/listContentDeclaration.d.ts +10 -7
  207. package/dist/types/listContentDeclaration.d.ts.map +1 -1
  208. package/dist/types/liveSync.d.ts +8 -3
  209. package/dist/types/liveSync.d.ts.map +1 -1
  210. package/dist/types/pull.d.ts +9 -6
  211. package/dist/types/pull.d.ts.map +1 -1
  212. package/dist/types/push/pullLog.d.ts +25 -21
  213. package/dist/types/push/pullLog.d.ts.map +1 -1
  214. package/dist/types/push/push.d.ts +13 -9
  215. package/dist/types/push/push.d.ts.map +1 -1
  216. package/dist/types/pushConfig.d.ts +7 -4
  217. package/dist/types/pushConfig.d.ts.map +1 -1
  218. package/dist/types/pushLog.d.ts +23 -20
  219. package/dist/types/pushLog.d.ts.map +1 -1
  220. package/dist/types/reviewDoc.d.ts +34 -17
  221. package/dist/types/reviewDoc.d.ts.map +1 -1
  222. package/dist/types/test/index.d.ts +9 -5
  223. package/dist/types/test/index.d.ts.map +1 -1
  224. package/dist/types/test/listMissingTranslations.d.ts +14 -10
  225. package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
  226. package/dist/types/translateDoc.d.ts +34 -17
  227. package/dist/types/translateDoc.d.ts.map +1 -1
  228. package/dist/types/utils/calculateChunks.d.ts +10 -7
  229. package/dist/types/utils/calculateChunks.d.ts.map +1 -1
  230. package/dist/types/utils/checkAccess.d.ts +8 -4
  231. package/dist/types/utils/checkAccess.d.ts.map +1 -1
  232. package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
  233. package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
  234. package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
  235. package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
  236. package/dist/types/utils/chunkInference.d.ts +9 -6
  237. package/dist/types/utils/chunkInference.d.ts.map +1 -1
  238. package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
  239. package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
  240. package/dist/types/utils/formatTimeDiff.d.ts +4 -1
  241. package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
  242. package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
  243. package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
  244. package/dist/types/utils/getOutputFilePath.d.ts +7 -2
  245. package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
  246. package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
  247. package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
  248. package/dist/types/utils/listSpecialChars.d.ts +9 -7
  249. package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
  250. package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
  251. package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
  252. package/dist/types/utils/reorderParagraphs.d.ts +4 -1
  253. package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
  254. package/dist/types/watch.d.ts +9 -6
  255. package/dist/types/watch.d.ts.map +1 -1
  256. package/package.json +42 -47
  257. package/LICENSE +0 -202
  258. package/dist/cjs/fill/autoFill.cjs +0 -105
  259. package/dist/cjs/fill/autoFill.cjs.map +0 -1
  260. package/dist/cjs/fill/index.cjs.map +0 -1
  261. package/dist/cjs/index.cjs.map +0 -1
  262. package/dist/cjs/utils/getChunk.cjs +0 -77
  263. package/dist/cjs/utils/getChunk.cjs.map +0 -1
  264. package/dist/cjs/utils/splitTextByLine.cjs +0 -35
  265. package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
  266. package/dist/esm/fill/autoFill.mjs +0 -92
  267. package/dist/esm/fill/autoFill.mjs.map +0 -1
  268. package/dist/esm/fill/index.mjs.map +0 -1
  269. package/dist/esm/index.mjs.map +0 -1
  270. package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
  271. package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
  272. package/dist/esm/utils/calculrateChunkTest.md +0 -9
  273. package/dist/esm/utils/getChunk.mjs +0 -53
  274. package/dist/esm/utils/getChunk.mjs.map +0 -1
  275. package/dist/esm/utils/splitTextByLine.mjs +0 -11
  276. package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
  277. package/dist/types/fill/autoFill.d.ts +0 -4
  278. package/dist/types/fill/autoFill.d.ts.map +0 -1
  279. package/dist/types/fill/index.d.ts.map +0 -1
  280. package/dist/types/index.d.ts.map +0 -1
  281. package/dist/types/utils/getChunk.d.ts +0 -9
  282. package/dist/types/utils/getChunk.d.ts.map +0 -1
  283. package/dist/types/utils/splitTextByLine.d.ts +0 -2
  284. package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
  285. /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
  286. /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
  287. /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
@@ -1,304 +1,76 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var fill_exports = {};
20
- __export(fill_exports, {
21
- fill: () => fill
22
- });
23
- module.exports = __toCommonJS(fill_exports);
24
- var import_api = require("@intlayer/api");
25
- var import_chokidar = require("@intlayer/chokidar");
26
- var import_config = require("@intlayer/config");
27
- var import_core = require("@intlayer/core");
28
- var import_dictionaries_entry = require("@intlayer/dictionaries-entry");
29
- var import_path = require("path");
30
- var import_getTargetDictionary = require('../getTargetDictionary.cjs');
31
- var import_checkAccess = require('../utils/checkAccess.cjs');
32
- var import_autoFill = require('./autoFill.cjs');
33
- const NB_CONCURRENT_TRANSLATIONS = 8;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_getTargetDictionary = require('../getTargetDictionary.cjs');
3
+ const require_utils_checkAccess = require('../utils/checkAccess.cjs');
4
+ const require_fill_listTranslationsTasks = require('./listTranslationsTasks.cjs');
5
+ const require_fill_translateDictionary = require('./translateDictionary.cjs');
6
+ const require_fill_writeFill = require('./writeFill.cjs');
7
+ let __intlayer_chokidar = require("@intlayer/chokidar");
8
+ __intlayer_chokidar = require_rolldown_runtime.__toESM(__intlayer_chokidar);
9
+ let __intlayer_config = require("@intlayer/config");
10
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
11
+ let node_path = require("node:path");
12
+ node_path = require_rolldown_runtime.__toESM(node_path);
13
+
14
+ //#region src/fill/fill.ts
15
+ const NB_CONCURRENT_TRANSLATIONS = 7;
16
+ /**
17
+ * Fill translations based on the provided options.
18
+ */
34
19
  const fill = async (options) => {
35
- const configuration = (0, import_config.getConfiguration)(options.configOptions);
36
- const appLogger = (0, import_config.getAppLogger)(configuration, {
37
- config: {
38
- prefix: ""
39
- }
40
- });
41
- if (options.build) {
42
- await (0, import_chokidar.prepareIntlayer)(configuration);
43
- }
44
- const { defaultLocale, locales } = configuration.internationalization;
45
- const mode = options.mode ?? "complete";
46
- const baseLocale = options.sourceLocale ?? defaultLocale;
47
- const outputLocales = (options.outputLocales ? (0, import_getTargetDictionary.ensureArray)(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
48
- const hasAIAccess = await (0, import_checkAccess.checkAIAccess)(configuration, options.aiOptions);
49
- if (!hasAIAccess) return;
50
- const intlayerAPI = (0, import_api.getIntlayerAPIProxy)(void 0, configuration);
51
- const targetUnmergedDictionaries = await (0, import_getTargetDictionary.getTargetUnmergedDictionaries)(options);
52
- const affectedDictionaryKeys = /* @__PURE__ */ new Set();
53
- targetUnmergedDictionaries.forEach((dict) => {
54
- affectedDictionaryKeys.add(dict.key);
55
- });
56
- appLogger([
57
- "Affected dictionary keys for processing:",
58
- Array.from(affectedDictionaryKeys).map((key) => (0, import_config.colorizeKey)(key)).join(", ")
59
- ]);
60
- const maxKeyLength = Math.max(
61
- ...targetUnmergedDictionaries.map((dict) => dict.key.length)
62
- );
63
- const maxLocaleLength = Math.max(
64
- ...locales.map((locale) => (0, import_chokidar.formatLocale)(locale).length)
65
- );
66
- const dictionariesRecord = (0, import_dictionaries_entry.getDictionaries)(configuration);
67
- const translationTasks = [];
68
- for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
69
- const dictionaryPreset = (0, import_config.colon)(
70
- [
71
- (0, import_config.colorize)(" - [", import_config.ANSIColors.GREY_DARK),
72
- (0, import_config.colorizeKey)(targetUnmergedDictionary.key),
73
- (0, import_config.colorize)("]", import_config.ANSIColors.GREY_DARK)
74
- ].join(""),
75
- { colSize: maxKeyLength + 6 }
76
- );
77
- const dictionaryKey = targetUnmergedDictionary.key;
78
- const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
79
- const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
80
- if (!mainDictionaryToProcess) {
81
- appLogger(
82
- `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,
83
- {
84
- level: "warn"
85
- }
86
- );
87
- continue;
88
- }
89
- if (!targetUnmergedDictionary.filePath) {
90
- appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {
91
- level: "warn"
92
- });
93
- continue;
94
- }
95
- const relativePath = (0, import_path.relative)(
96
- configuration.content.baseDir,
97
- targetUnmergedDictionary.filePath
98
- );
99
- appLogger(
100
- `${dictionaryPreset} Processing content declaration: ${(0, import_config.colorizePath)(relativePath)}`,
101
- {
102
- level: "info"
103
- }
104
- );
105
- const sourceLocaleContent = (0, import_core.getFilterTranslationsOnlyContent)(
106
- mainDictionaryToProcess,
107
- sourceLocale,
108
- { dictionaryKey, keyPath: [] }
109
- );
110
- if (Object.keys(sourceLocaleContent).length === 0) {
111
- appLogger(
112
- `${dictionaryPreset} No content found for dictionary in source locale ${(0, import_chokidar.formatLocale)(sourceLocale)}. Skipping translation for this dictionary.`,
113
- {
114
- level: "warn"
115
- }
116
- );
117
- continue;
118
- }
119
- let outputLocalesList = outputLocales;
120
- if (mode === "complete") {
121
- const missingLocales = (0, import_core.getMissingLocalesContent)(
122
- mainDictionaryToProcess,
123
- outputLocales,
124
- {
125
- dictionaryKey: mainDictionaryToProcess.key,
126
- keyPath: [],
127
- plugins: []
128
- }
129
- );
130
- outputLocalesList = missingLocales;
131
- }
132
- if (outputLocalesList.length === 0) {
133
- appLogger(
134
- `${dictionaryPreset} No locales to fill - Skipping dictionary`,
135
- {
136
- level: "warn"
137
- }
138
- );
139
- continue;
140
- }
141
- for (const targetLocale of outputLocalesList) {
142
- const localePreset = (0, import_config.colon)(
143
- [
144
- (0, import_config.colorize)("[", import_config.ANSIColors.GREY_DARK),
145
- (0, import_chokidar.formatLocale)(targetLocale),
146
- (0, import_config.colorize)("]", import_config.ANSIColors.GREY_DARK)
147
- ].join(""),
148
- { colSize: maxLocaleLength }
149
- );
150
- translationTasks.push({
151
- dictionaryKey,
152
- sourceLocale,
153
- targetLocale,
154
- dictionaryPreset,
155
- localePreset
156
- });
157
- }
158
- }
159
- const translationResults = await (0, import_chokidar.parallelize)(
160
- translationTasks,
161
- async (task) => {
162
- const mainDictionaryToProcess = dictionariesRecord[task.dictionaryKey];
163
- appLogger(
164
- `${task.dictionaryPreset}${task.localePreset} Preparing translation for dictionary from ${(0, import_chokidar.formatLocale)(task.sourceLocale)} to ${(0, import_chokidar.formatLocale)(task.targetLocale)}`,
165
- {
166
- level: "info"
167
- }
168
- );
169
- const sourceLocaleContent = (0, import_core.getFilterTranslationsOnlyContent)(
170
- mainDictionaryToProcess,
171
- task.sourceLocale,
172
- { dictionaryKey: task.dictionaryKey, keyPath: [] }
173
- );
174
- const presetOutputContent = (0, import_core.getLocalisedContent)(
175
- mainDictionaryToProcess,
176
- task.targetLocale,
177
- { dictionaryKey: task.dictionaryKey, keyPath: [] }
178
- );
179
- try {
180
- const translationResult = await intlayerAPI.ai.translateJSON({
181
- entryFileContent: sourceLocaleContent.content,
182
- presetOutputContent: presetOutputContent.content,
183
- dictionaryDescription: mainDictionaryToProcess.description ?? "",
184
- entryLocale: task.sourceLocale,
185
- outputLocale: task.targetLocale,
186
- mode,
187
- aiOptions: options.aiOptions
188
- });
189
- if (!translationResult.data?.fileContent) {
190
- appLogger(
191
- `${task.dictionaryPreset}${task.localePreset} No content result`,
192
- {
193
- level: "error"
194
- }
195
- );
196
- return { key: task.dictionaryKey, result: null };
197
- }
198
- const processedPerLocaleDictionary = (0, import_chokidar.processPerLocaleDictionary)({
199
- ...mainDictionaryToProcess,
200
- content: translationResult.data?.fileContent,
201
- locale: task.targetLocale
202
- });
203
- return {
204
- key: task.dictionaryKey,
205
- result: processedPerLocaleDictionary
206
- };
207
- } catch (error) {
208
- appLogger(
209
- `${task.dictionaryPreset}${task.localePreset} ${(0, import_config.colorize)("Error filling", import_config.ANSIColors.RED)}: ` + error,
210
- {
211
- level: "error"
212
- }
213
- );
214
- return { key: task.dictionaryKey, result: null };
215
- }
216
- },
217
- options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS
218
- );
219
- const resultsByDictionary = /* @__PURE__ */ new Map();
220
- for (const item of translationResults) {
221
- if (item?.result) {
222
- const list = resultsByDictionary.get(item.key) ?? [];
223
- list.push(item.result);
224
- resultsByDictionary.set(item.key, list);
225
- }
226
- }
227
- for (const targetUnmergedDictionary of targetUnmergedDictionaries) {
228
- const dictionaryKey = targetUnmergedDictionary.key;
229
- const mainDictionaryToProcess = dictionariesRecord[dictionaryKey];
230
- const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
231
- if (!mainDictionaryToProcess || !targetUnmergedDictionary.filePath) {
232
- continue;
233
- }
234
- let outputLocalesList = outputLocales;
235
- if (mode === "complete") {
236
- const missingLocales = (0, import_core.getMissingLocalesContent)(
237
- mainDictionaryToProcess,
238
- outputLocales,
239
- {
240
- dictionaryKey: mainDictionaryToProcess.key,
241
- keyPath: [],
242
- plugins: []
243
- }
244
- );
245
- outputLocalesList = missingLocales;
246
- }
247
- if (outputLocalesList.length === 0) {
248
- continue;
249
- }
250
- const perLocaleResults = resultsByDictionary.get(dictionaryKey) ?? [];
251
- const dictionaryToMerge = mode === "review" ? [...perLocaleResults, mainDictionaryToProcess] : [mainDictionaryToProcess, ...perLocaleResults];
252
- const mergedResults = (0, import_chokidar.mergeDictionaries)(dictionaryToMerge);
253
- let formattedDict = targetUnmergedDictionary;
254
- if (formattedDict.locale) {
255
- const presetOutputContent = (0, import_core.getLocalisedContent)(
256
- mainDictionaryToProcess,
257
- formattedDict.locale,
258
- { dictionaryKey, keyPath: [] }
259
- );
260
- formattedDict = {
261
- ...formattedDict,
262
- content: presetOutputContent.content
263
- };
264
- }
265
- const reducedResult = (0, import_chokidar.reduceDictionaryContent)(mergedResults, formattedDict);
266
- if (formattedDict.autoFill || configuration.content.autoFill) {
267
- await (0, import_autoFill.autoFill)(
268
- mergedResults,
269
- targetUnmergedDictionary,
270
- formattedDict.autoFill ?? configuration.content.autoFill,
271
- outputLocalesList,
272
- [sourceLocale],
273
- configuration
274
- );
275
- } else {
276
- await (0, import_chokidar.writeContentDeclaration)(
277
- { ...formattedDict, content: reducedResult.content },
278
- configuration,
279
- formattedDict.filePath
280
- );
281
- if (formattedDict.filePath) {
282
- const dictionaryPreset = (0, import_config.colon)(
283
- [
284
- (0, import_config.colorize)(" - [", import_config.ANSIColors.GREY_DARK),
285
- (0, import_config.colorizeKey)(targetUnmergedDictionary.key),
286
- (0, import_config.colorize)("]", import_config.ANSIColors.GREY_DARK)
287
- ].join(""),
288
- { colSize: maxKeyLength + 6 }
289
- );
290
- appLogger(
291
- `${dictionaryPreset} Content declaration written to ${(0, import_chokidar.formatPath)(formattedDict.filePath)}`,
292
- {
293
- level: "info"
294
- }
295
- );
296
- }
297
- }
298
- }
20
+ const configuration = (0, __intlayer_config.getConfiguration)(options?.configOptions);
21
+ const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
22
+ if (options?.build === true) await (0, __intlayer_chokidar.prepareIntlayer)(configuration, { forceRun: true });
23
+ else if (typeof options?.build === "undefined") await (0, __intlayer_chokidar.prepareIntlayer)(configuration);
24
+ const { defaultLocale, locales } = configuration.internationalization;
25
+ const mode = options?.mode ?? "complete";
26
+ const baseLocale = options?.sourceLocale ?? defaultLocale;
27
+ const outputLocales = (options?.outputLocales ? require_getTargetDictionary.ensureArray(options.outputLocales) : locales).filter((locale) => locale !== baseLocale);
28
+ if (!await require_utils_checkAccess.checkAIAccess(configuration, options?.aiOptions)) return;
29
+ const targetUnmergedDictionaries = await require_getTargetDictionary.getTargetUnmergedDictionaries(options);
30
+ const affectedDictionaryKeys = /* @__PURE__ */ new Set();
31
+ targetUnmergedDictionaries.forEach((dict) => {
32
+ affectedDictionaryKeys.add(dict.key);
33
+ });
34
+ const keysToProcess = Array.from(affectedDictionaryKeys);
35
+ appLogger(["Affected dictionary keys for processing:", keysToProcess.length > 0 ? keysToProcess.map((key) => (0, __intlayer_config.colorizeKey)(key)).join(", ") : (0, __intlayer_config.colorize)("No keys found", __intlayer_config.ANSIColors.YELLOW)]);
36
+ if (keysToProcess.length === 0) return;
37
+ /**
38
+ * List the translations tasks
39
+ *
40
+ * Create a list of per-locale dictionaries to translate
41
+ *
42
+ * In 'complete' mode, filter only the missing locales to translate
43
+ */
44
+ const translationTasks = require_fill_listTranslationsTasks.listTranslationsTasks(targetUnmergedDictionaries.map((dict) => dict.localId), outputLocales, mode, baseLocale, configuration);
45
+ const nbConcurrentTranslations = options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;
46
+ const globalLimiter = (0, __intlayer_chokidar.getGlobalLimiter)(nbConcurrentTranslations);
47
+ const taskLimiter = (0, __intlayer_chokidar.getTaskLimiter)(Math.min(options?.nbConcurrentTasks ?? nbConcurrentTranslations, translationTasks.length));
48
+ const runners = translationTasks.map((task) => taskLimiter(async () => {
49
+ const relativePath = (0, node_path.relative)(configuration?.content?.baseDir ?? process.cwd(), task?.dictionaryFilePath ?? "");
50
+ appLogger(`${task.dictionaryPreset} Processing ${(0, __intlayer_config.colorizePath)((0, node_path.basename)(relativePath))}`, { level: "info" });
51
+ const translationTaskResult = await require_fill_translateDictionary.translateDictionary(task, configuration, {
52
+ mode,
53
+ aiOptions: options?.aiOptions,
54
+ fillMetadata: !options?.skipMetadata,
55
+ onHandle: globalLimiter
56
+ });
57
+ if (!translationTaskResult?.dictionaryOutput) return;
58
+ const { dictionaryOutput, sourceLocale } = translationTaskResult;
59
+ if (typeof dictionaryOutput.fill === "string" || typeof dictionaryOutput.fill === "object") await require_fill_writeFill.writeFill(dictionaryOutput, outputLocales, [sourceLocale], configuration);
60
+ else {
61
+ await (0, __intlayer_chokidar.writeContentDeclaration)(dictionaryOutput, configuration);
62
+ if (dictionaryOutput.filePath) appLogger(`${(0, __intlayer_config.colon)([
63
+ " - ",
64
+ (0, __intlayer_config.colorize)("[", __intlayer_config.ANSIColors.GREY_DARK),
65
+ (0, __intlayer_config.colorizeKey)(dictionaryOutput.key),
66
+ (0, __intlayer_config.colorize)("]", __intlayer_config.ANSIColors.GREY_DARK)
67
+ ].join(""), { colSize: 15 })} Content declaration written to ${(0, __intlayer_chokidar.formatPath)((0, node_path.basename)(dictionaryOutput.filePath))}`, { level: "info" });
68
+ }
69
+ }));
70
+ await Promise.all(runners);
71
+ await globalLimiter.onIdle();
299
72
  };
300
- // Annotate the CommonJS export names for ESM import in node:
301
- 0 && (module.exports = {
302
- fill
303
- });
73
+
74
+ //#endregion
75
+ exports.fill = fill;
304
76
  //# sourceMappingURL=fill.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { AIOptions, getIntlayerAPIProxy } from '@intlayer/api'; // Importing only getAiAPI for now\nimport {\n formatLocale,\n formatPath,\n ListGitFilesOptions,\n mergeDictionaries,\n parallelize,\n prepareIntlayer,\n processPerLocaleDictionary,\n reduceDictionaryContent,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n Locales,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getFilterTranslationsOnlyContent,\n getLocalisedContent,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport { relative } from 'path';\nimport {\n ensureArray,\n GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { checkAIAccess } from '../utils/checkAccess';\nimport { autoFill } from './autoFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 8;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locales;\n outputLocales?: Locales | Locales[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n build?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options.configOptions);\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n if (options.build) {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options.mode ?? 'complete';\n const baseLocale = options.sourceLocale ?? defaultLocale;\n const outputLocales = (\n options.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n const hasAIAccess = await checkAIAccess(configuration, options.aiOptions);\n\n if (!hasAIAccess) return;\n\n const intlayerAPI = getIntlayerAPIProxy(undefined, configuration);\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n appLogger([\n 'Affected dictionary keys for processing:',\n Array.from(affectedDictionaryKeys)\n .map((key) => colorizeKey(key))\n .join(', '),\n ]);\n\n const maxKeyLength = Math.max(\n ...targetUnmergedDictionaries.map((dict) => dict.key.length)\n );\n const maxLocaleLength = Math.max(\n ...locales.map((locale) => formatLocale(locale).length)\n );\n const dictionariesRecord = getDictionaries(configuration);\n\n type TranslationTask = {\n dictionaryKey: string;\n sourceLocale: Locales;\n targetLocale: Locales;\n dictionaryPreset: string;\n localePreset: string;\n };\n\n const translationTasks: TranslationTask[] = [];\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryPreset = colon(\n [\n colorize(' - [', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[dictionaryKey];\n\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess) {\n appLogger(\n `${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n if (!targetUnmergedDictionary.filePath) {\n appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, {\n level: 'warn',\n });\n continue;\n }\n\n const relativePath = relative(\n configuration.content.baseDir,\n targetUnmergedDictionary.filePath\n );\n\n appLogger(\n `${dictionaryPreset} Processing content declaration: ${colorizePath(relativePath)}`,\n {\n level: 'info',\n }\n );\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n sourceLocale,\n { dictionaryKey, keyPath: [] }\n );\n\n if (Object.keys(sourceLocaleContent).length === 0) {\n appLogger(\n `${dictionaryPreset} No content found for dictionary in source locale ${formatLocale(sourceLocale)}. Skipping translation for this dictionary.`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n let outputLocalesList: Locales[] = outputLocales;\n\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n if (outputLocalesList.length === 0) {\n appLogger(\n `${dictionaryPreset} No locales to fill - Skipping dictionary`,\n {\n level: 'warn',\n }\n );\n continue;\n }\n\n for (const targetLocale of outputLocalesList) {\n const localePreset = colon(\n [\n colorize('[', ANSIColors.GREY_DARK),\n formatLocale(targetLocale),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxLocaleLength }\n );\n\n translationTasks.push({\n dictionaryKey,\n sourceLocale,\n targetLocale,\n dictionaryPreset,\n localePreset,\n });\n }\n }\n\n const translationResults = await parallelize(\n translationTasks,\n async (task) => {\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[task.dictionaryKey];\n\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} Preparing translation for dictionary from ${formatLocale(task.sourceLocale)} to ${formatLocale(task.targetLocale)}`,\n {\n level: 'info',\n }\n );\n\n const sourceLocaleContent = getFilterTranslationsOnlyContent(\n mainDictionaryToProcess as unknown as ContentNode,\n task.sourceLocale,\n { dictionaryKey: task.dictionaryKey, keyPath: [] }\n );\n\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n task.targetLocale,\n { dictionaryKey: task.dictionaryKey, keyPath: [] }\n );\n\n try {\n const translationResult = await intlayerAPI.ai.translateJSON({\n entryFileContent: sourceLocaleContent.content,\n presetOutputContent: presetOutputContent.content,\n dictionaryDescription: mainDictionaryToProcess.description ?? '',\n entryLocale: task.sourceLocale,\n outputLocale: task.targetLocale,\n mode,\n aiOptions: options.aiOptions,\n });\n\n if (!translationResult.data?.fileContent) {\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} No content result`,\n {\n level: 'error',\n }\n );\n return { key: task.dictionaryKey, result: null } as const;\n }\n\n const processedPerLocaleDictionary = processPerLocaleDictionary({\n ...mainDictionaryToProcess,\n content: translationResult.data?.fileContent,\n locale: task.targetLocale,\n });\n\n return {\n key: task.dictionaryKey,\n result: processedPerLocaleDictionary,\n } as const;\n } catch (error) {\n appLogger(\n `${task.dictionaryPreset}${task.localePreset} ${colorize('Error filling', ANSIColors.RED)}: ` +\n error,\n {\n level: 'error',\n }\n );\n return { key: task.dictionaryKey, result: null } as const;\n }\n },\n options.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS\n );\n\n const resultsByDictionary = new Map<string, Dictionary[]>();\n for (const item of translationResults) {\n if (item?.result) {\n const list = resultsByDictionary.get(item.key) ?? [];\n list.push(item.result);\n resultsByDictionary.set(item.key, list);\n }\n }\n\n for (const targetUnmergedDictionary of targetUnmergedDictionaries) {\n const dictionaryKey = targetUnmergedDictionary.key;\n const mainDictionaryToProcess: Dictionary =\n dictionariesRecord[dictionaryKey];\n\n const sourceLocale: Locales =\n (targetUnmergedDictionary.locale as Locales) ?? baseLocale;\n\n if (!mainDictionaryToProcess || !targetUnmergedDictionary.filePath) {\n continue;\n }\n\n let outputLocalesList: Locales[] = outputLocales;\n\n if (mode === 'complete') {\n const missingLocales = getMissingLocalesContent(\n mainDictionaryToProcess as unknown as ContentNode,\n outputLocales,\n {\n dictionaryKey: mainDictionaryToProcess.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n outputLocalesList = missingLocales;\n }\n\n if (outputLocalesList.length === 0) {\n continue;\n }\n\n const perLocaleResults = resultsByDictionary.get(dictionaryKey) ?? [];\n\n const dictionaryToMerge =\n mode === 'review'\n ? [...perLocaleResults, mainDictionaryToProcess]\n : [mainDictionaryToProcess, ...perLocaleResults];\n\n const mergedResults = mergeDictionaries(dictionaryToMerge);\n\n let formattedDict = targetUnmergedDictionary;\n\n if (formattedDict.locale) {\n const presetOutputContent = getLocalisedContent(\n mainDictionaryToProcess as unknown as ContentNode,\n formattedDict.locale,\n { dictionaryKey, keyPath: [] }\n );\n\n formattedDict = {\n ...formattedDict,\n content: presetOutputContent.content,\n };\n }\n\n const reducedResult = reduceDictionaryContent(mergedResults, formattedDict);\n\n if (formattedDict.autoFill || configuration.content.autoFill) {\n await autoFill(\n mergedResults,\n targetUnmergedDictionary,\n formattedDict.autoFill ?? configuration.content.autoFill,\n outputLocalesList,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(\n { ...formattedDict, content: reducedResult.content },\n configuration,\n formattedDict.filePath\n );\n\n if (formattedDict.filePath) {\n const dictionaryPreset = colon(\n [\n colorize(' - [', ANSIColors.GREY_DARK),\n colorizeKey(targetUnmergedDictionary.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: maxKeyLength + 6 }\n );\n appLogger(\n `${dictionaryPreset} Content declaration written to ${formatPath(formattedDict.filePath)}`,\n {\n level: 'info',\n }\n );\n }\n }\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+C;AAC/C,sBAUO;AACP,oBASO;AACP,kBAMO;AACP,gCAAgC;AAChC,kBAAyB;AACzB,iCAIO;AACP,yBAA8B;AAC9B,sBAAyB;AAEzB,MAAM,6BAA6B;AAiB5B,MAAM,OAAO,OAAO,YAAwC;AACjE,QAAM,oBAAgB,gCAAiB,QAAQ,aAAa;AAC5D,QAA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ors","translationTasks: TranslationTask[]","listTranslationsTasks","translateDictionary","writeFill"],"sources":["../../../src/fill/fill.ts"],"sourcesContent":["import { basename, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api';\nimport {\n formatPath,\n getGlobalLimiter,\n getTaskLimiter,\n type ListGitFilesOptions,\n prepareIntlayer,\n writeContentDeclaration,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizePath,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Locale } from '@intlayer/types';\nimport {\n ensureArray,\n type GetTargetDictionaryOptions,\n getTargetUnmergedDictionaries,\n} from '../getTargetDictionary';\nimport { checkAIAccess } from '../utils/checkAccess';\nimport {\n listTranslationsTasks,\n type TranslationTask,\n} from './listTranslationsTasks';\nimport { translateDictionary } from './translateDictionary';\nimport { writeFill } from './writeFill';\n\nconst NB_CONCURRENT_TRANSLATIONS = 7;\n\n// Arguments for the fill function\nexport type FillOptions = {\n sourceLocale?: Locale;\n outputLocales?: Locale | Locale[];\n mode?: 'complete' | 'review';\n gitOptions?: ListGitFilesOptions;\n aiOptions?: AIOptions; // Added aiOptions to be passed to translateJSON\n verbose?: boolean;\n nbConcurrentTranslations?: number;\n nbConcurrentTasks?: number; // NEW: number of tasks that may run at once\n build?: boolean;\n skipMetadata?: boolean;\n} & GetTargetDictionaryOptions;\n\n/**\n * Fill translations based on the provided options.\n */\nexport const fill = async (options?: FillOptions): Promise<void> => {\n const configuration = getConfiguration(options?.configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (options?.build === true) {\n await prepareIntlayer(configuration, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(configuration);\n }\n\n const { defaultLocale, locales } = configuration.internationalization;\n const mode = options?.mode ?? 'complete';\n const baseLocale = options?.sourceLocale ?? defaultLocale;\n const outputLocales = (\n options?.outputLocales ? ensureArray(options.outputLocales) : locales\n ).filter((locale) => locale !== baseLocale);\n\n const hasAIAccess = await checkAIAccess(configuration, options?.aiOptions);\n\n if (!hasAIAccess) return;\n\n const targetUnmergedDictionaries =\n await getTargetUnmergedDictionaries(options);\n\n const affectedDictionaryKeys = new Set<string>();\n targetUnmergedDictionaries.forEach((dict) => {\n affectedDictionaryKeys.add(dict.key);\n });\n\n const keysToProcess = Array.from(affectedDictionaryKeys);\n\n appLogger([\n 'Affected dictionary keys for processing:',\n keysToProcess.length > 0\n ? keysToProcess.map((key) => colorizeKey(key)).join(', ')\n : colorize('No keys found', ANSIColors.YELLOW),\n ]);\n\n if (keysToProcess.length === 0) return;\n\n /**\n * List the translations tasks\n *\n * Create a list of per-locale dictionaries to translate\n *\n * In 'complete' mode, filter only the missing locales to translate\n */\n const translationTasks: TranslationTask[] = listTranslationsTasks(\n targetUnmergedDictionaries.map((dict) => dict.localId!),\n outputLocales,\n mode,\n baseLocale,\n configuration\n );\n\n // AI calls in flight at once (translateJSON + metadata audit)\n const nbConcurrentTranslations =\n options?.nbConcurrentTranslations ?? NB_CONCURRENT_TRANSLATIONS;\n const globalLimiter = getGlobalLimiter(nbConcurrentTranslations);\n\n // NEW: number of *tasks* that may run at once (start/prepare/log/write)\n const nbConcurrentTasks = Math.min(\n options?.nbConcurrentTasks ?? nbConcurrentTranslations,\n translationTasks.length\n );\n const taskLimiter = getTaskLimiter(nbConcurrentTasks);\n\n const runners = translationTasks.map((task) =>\n taskLimiter(async () => {\n const relativePath = relative(\n configuration?.content?.baseDir ?? process.cwd(),\n task?.dictionaryFilePath ?? ''\n );\n\n // log AFTER acquiring a task slot\n appLogger(\n `${task.dictionaryPreset} Processing ${colorizePath(basename(relativePath))}`,\n { level: 'info' }\n );\n\n const translationTaskResult = await translateDictionary(\n task,\n configuration,\n {\n mode,\n aiOptions: options?.aiOptions,\n fillMetadata: !options?.skipMetadata,\n onHandle: globalLimiter, // <= AI calls go through here\n }\n );\n\n if (!translationTaskResult?.dictionaryOutput) return;\n\n const { dictionaryOutput, sourceLocale } = translationTaskResult;\n\n // fix impossible && condition\n const isFillOtherFile =\n typeof dictionaryOutput.fill === 'string' ||\n typeof dictionaryOutput.fill === 'object';\n\n if (isFillOtherFile) {\n await writeFill(\n dictionaryOutput,\n outputLocales,\n [sourceLocale],\n configuration\n );\n } else {\n await writeContentDeclaration(dictionaryOutput, configuration);\n\n if (dictionaryOutput.filePath) {\n const dictionaryPreset = colon(\n [\n ' - ',\n colorize('[', ANSIColors.GREY_DARK),\n colorizeKey(dictionaryOutput.key),\n colorize(']', ANSIColors.GREY_DARK),\n ].join(''),\n { colSize: 15 }\n );\n appLogger(\n `${dictionaryPreset} Content declaration written to ${formatPath(basename(dictionaryOutput.filePath))}`,\n { level: 'info' }\n );\n }\n }\n })\n );\n\n await Promise.all(runners);\n await (globalLimiter as any).onIdle();\n};\n"],"mappings":";;;;;;;;;;;;;;AAiCA,MAAM,6BAA6B;;;;AAmBnC,MAAa,OAAO,OAAO,YAAyC;CAClE,MAAM,wDAAiC,SAAS,cAAc;CAC9D,MAAM,gDAAyB,cAAc;AAE7C,KAAI,SAAS,UAAU,KACrB,gDAAsB,eAAe,EAAE,UAAU,MAAM,CAAC;UAC/C,OAAO,SAAS,UAAU,YACnC,gDAAsB,cAAc;CAGtC,MAAM,EAAE,eAAe,YAAY,cAAc;CACjD,MAAM,OAAO,SAAS,QAAQ;CAC9B,MAAM,aAAa,SAAS,gBAAgB;CAC5C,MAAM,iBACJ,SAAS,gBAAgBA,wCAAY,QAAQ,cAAc,GAAG,SAC9D,QAAQ,WAAW,WAAW,WAAW;AAI3C,KAAI,CAFgB,MAAMC,wCAAc,eAAe,SAAS,UAAU,CAExD;CAElB,MAAM,6BACJ,MAAMC,0DAA8B,QAAQ;CAE9C,MAAM,yCAAyB,IAAI,KAAa;AAChD,4BAA2B,SAAS,SAAS;AAC3C,yBAAuB,IAAI,KAAK,IAAI;GACpC;CAEF,MAAM,gBAAgB,MAAM,KAAK,uBAAuB;AAExD,WAAU,CACR,4CACA,cAAc,SAAS,IACnB,cAA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
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_fill_formatAutoFilledFilePath = require('./formatAutoFilledFilePath.cjs');
2
+
3
+ //#region src/fill/formatAutoFillData.ts
4
+ const formatFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
5
+ const outputContentDeclarationFile = [];
6
+ const baseDir = configuration.content.baseDir;
7
+ if (!autoFillField) return outputContentDeclarationFile;
8
+ if (typeof autoFillField === "string") {
9
+ if (autoFillField.includes("{{locale}}")) {
10
+ const output = localeList.map((locale) => {
11
+ const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir, locale);
12
+ return {
13
+ localeList: [locale],
14
+ filePath: formattedFilePath,
15
+ isPerLocale: true
16
+ };
17
+ });
18
+ outputContentDeclarationFile.push(...output);
19
+ } else {
20
+ const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField, dictionaryKey, filePath, baseDir);
21
+ outputContentDeclarationFile.push({
22
+ localeList,
23
+ filePath: formattedFilePath,
24
+ isPerLocale: false
25
+ });
26
+ }
27
+ return outputContentDeclarationFile;
28
+ }
29
+ if (typeof autoFillField === "object") {
30
+ const groupedByFilePath = Object.keys(autoFillField).filter((locale) => typeof autoFillField[locale] === "string").filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
31
+ const formattedFilePath = require_fill_formatAutoFilledFilePath.formatAutoFilledFilePath(autoFillField[locale], dictionaryKey, filePath, baseDir, locale);
32
+ return {
33
+ localeList: [locale],
34
+ filePath: formattedFilePath,
35
+ isPerLocale: true
36
+ };
37
+ }).reduce((acc, curr) => {
38
+ const existing = acc.find((item) => item.filePath === curr.filePath);
39
+ if (existing) existing.localeList.push(...curr.localeList);
40
+ else acc.push(curr);
41
+ return acc;
42
+ }, []);
43
+ outputContentDeclarationFile.push(...groupedByFilePath);
44
+ }
45
+ return outputContentDeclarationFile;
9
46
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var formatAutoFillData_exports = {};
20
- __export(formatAutoFillData_exports, {
21
- formatAutoFillData: () => formatAutoFillData
22
- });
23
- module.exports = __toCommonJS(formatAutoFillData_exports);
24
- var import_path = require("path");
25
- var import_formatAutoFilledFilePath = require('./formatAutoFilledFilePath.cjs');
26
- const formatAutoFillData = (autoFillField, localeList, filePath, dictionaryKey, configuration) => {
27
- const outputContentDeclarationFile = [];
28
- const baseDir = configuration.content.baseDir;
29
- if (!Boolean(autoFillField)) return outputContentDeclarationFile;
30
- if (autoFillField === true) {
31
- let jsonFilePath = filePath.replace((0, import_path.extname)(filePath), ".json");
32
- if (filePath === jsonFilePath) {
33
- jsonFilePath = jsonFilePath.replace((0, import_path.extname)(jsonFilePath), ".fill.json");
34
- }
35
- outputContentDeclarationFile.push({
36
- localeList,
37
- filePath: jsonFilePath,
38
- isPerLocale: false
39
- });
40
- }
41
- if (typeof autoFillField === "string") {
42
- if (autoFillField.includes("{{locale}}")) {
43
- const output = localeList.map((locale) => {
44
- const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
45
- autoFillField,
46
- dictionaryKey,
47
- filePath,
48
- baseDir,
49
- locale
50
- );
51
- return {
52
- localeList: [locale],
53
- filePath: formattedFilePath,
54
- isPerLocale: true
55
- };
56
- });
57
- outputContentDeclarationFile.push(...output);
58
- } else {
59
- const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
60
- autoFillField,
61
- dictionaryKey,
62
- filePath,
63
- baseDir
64
- );
65
- outputContentDeclarationFile.push({
66
- localeList,
67
- filePath: formattedFilePath,
68
- isPerLocale: false
69
- });
70
- }
71
- return outputContentDeclarationFile;
72
- }
73
- if (typeof autoFillField === "object") {
74
- const localeList2 = Object.keys(autoFillField).filter(
75
- (locale) => typeof autoFillField[locale] === "string"
76
- );
77
- const output = localeList2.filter((locale) => Boolean(autoFillField[locale])).map((locale) => {
78
- const formattedFilePath = (0, import_formatAutoFilledFilePath.formatAutoFilledFilePath)(
79
- autoFillField[locale],
80
- dictionaryKey,
81
- filePath,
82
- baseDir,
83
- locale
84
- );
85
- return {
86
- localeList: [locale],
87
- filePath: formattedFilePath,
88
- isPerLocale: true
89
- };
90
- });
91
- const groupedByFilePath = output.reduce((acc, curr) => {
92
- const existing = acc.find((item) => item.filePath === curr.filePath);
93
- if (existing) {
94
- existing.localeList.push(...curr.localeList);
95
- } else {
96
- acc.push(curr);
97
- }
98
- return acc;
99
- }, []);
100
- outputContentDeclarationFile.push(...groupedByFilePath);
101
- }
102
- return outputContentDeclarationFile;
103
- };
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {
106
- formatAutoFillData
107
- });
47
+
48
+ //#endregion
49
+ exports.formatFillData = formatFillData;
108
50
  //# sourceMappingURL=formatAutoFillData.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/fill/formatAutoFillData.ts"],"sourcesContent":["import { type IntlayerConfig, Locales } from '@intlayer/config';\nimport { type AutoFill } from '@intlayer/core';\nimport { extname } from 'path';\nimport { formatAutoFilledFilePath } from './formatAutoFilledFilePath';\n\nexport type AutoFillData = {\n localeList: Locales[];\n filePath: string;\n isPerLocale: boolean;\n};\n\nexport const formatAutoFillData = (\n autoFillField: AutoFill,\n localeList: Locales[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): AutoFillData[] => {\n const outputContentDeclarationFile: AutoFillData[] = [];\n\n const baseDir = configuration.content.baseDir;\n\n if (!Boolean(autoFillField)) return outputContentDeclarationFile;\n\n if (autoFillField === true) {\n // wanted jsonFilePath: /..../src/components/home/index.content.json\n // replace file extension in json\n let jsonFilePath = filePath.replace(extname(filePath), '.json');\n\n // if both filePath jsonFilePath are same path, change it as : /..../src/components/home/index.fill.content.json\n if (filePath === jsonFilePath) {\n jsonFilePath = jsonFilePath.replace(extname(jsonFilePath), '.fill.json');\n }\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: jsonFilePath,\n isPerLocale: false,\n });\n }\n\n if (typeof autoFillField === 'string') {\n if (autoFillField.includes('{{locale}}')) {\n const output = localeList.map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n outputContentDeclarationFile.push(...output);\n } else {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir\n );\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: formattedFilePath,\n isPerLocale: false,\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillField === 'object') {\n const localeList = Object.keys(autoFillField).filter(\n (locale) => typeof autoFillField[locale] === 'string'\n ) as Locales[];\n\n const output: AutoFillData[] = localeList\n .filter((locale) => Boolean(autoFillField[locale]))\n .map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField[locale],\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as AutoFillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAAwB;AACxB,sCAAyC;AAQlC,MAAM,qBAAqB,CAChC,eACA,YACA,UACA,eACA,kBACmB;AACnB,QAAM,+BAA+C,CAAC;AAEtD,QAAM,UAAU,cAAc,QAAQ;AAEtC,MAAI,CAAC,QAAQ,aAAa,EAAG,QAAO;AAEpC,MAAI,kBAAkB,MAAM;AAG1B,QAAI,eAAe,SAAS,YAAQ,qBAAQ,QAAQ,GAAG,OAAO;AAG9D,QAAI,aAAa,cAAc;AAC7B,qBAAe,aAAa,YAAQ,qBAAQ,YAAY,GAAG,YAAY;AAAA,IACzE;AAEA,iCAA6B,KAAK;AAAA,MAChC;AAAA,MACA,UAAU;AAAA,MACV,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAEA,MAAI,OAAO,kBAAkB,UAAU;AACrC,QAAI,cAAc,SAAS,YAAY,GAAG;AACxC,YAAM,SAAS,WAAW,IAAI,CAAC,WAAW;AACxC,cAAM,wBAAoB;AAAA,UACxB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO;AAAA,UACL,YAAY,CAAC,MAAM;AAAA,UACnB,UAAU;AAAA,UACV,aAAa;AAAA,QACf;AAAA,MACF,CAAC;AAED,mCAA6B,KAAK,GAAG,MAAM;AAAA,IAC7C,OAAO;AACL,YAAM,wBAAoB;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,mCAA6B,KAAK;AAAA,QAChC;AAAA,QACA,UAAU;AAAA,QACV,aAAa;AAAA,MACf,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,kBAAkB,UAAU;AACrC,UAAMA,cAAa,OAAO,KAAK,aAAa,EAAE;AAAA,MAC5C,CAAC,WAAW,OAAO,cAAc,MAAM,MAAM;AAAA,IAC/C;AAEA,UAAM,SAAyBA,YAC5B,OAAO,CAAC,WAAW,QAAQ,cAAc,MAAM,CAAC,CAAC,EACjD,IAAI,CAAC,WAAW;AACf,YAAM,wBAAoB;AAAA,QACxB,cAAc,MAAM;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,aAAO;AAAA,QACL,YAAY,CAAC,MAAM;AAAA,QACnB,UAAU;AAAA,QACV,aAAa;AAAA,MACf;AAAA,IACF,CAAC;AAGH,UAAM,oBAAoB,OAAO,OAAO,CAAC,KAAK,SAAS;AACrD,YAAM,WAAW,IAAI,KAAK,CAAC,SAAS,KAAK,aAAa,KAAK,QAAQ;AACnE,UAAI,UAAU;AACZ,iBAAS,WAAW,KAAK,GAAG,KAAK,UAAU;AAAA,MAC7C,OAAO;AACL,YAAI,KAAK,IAAI;AAAA,MACf;AACA,aAAO;AAAA,IACT,GAAG,CAAC,CAAmB;AAEvB,iCAA6B,KAAK,GAAG,iBAAiB;AAAA,EACxD;AAEA,SAAO;AACT;","names":["localeList"]}
1
+ {"version":3,"file":"formatAutoFillData.cjs","names":["outputContentDeclarationFile: FillData[]","formatAutoFilledFilePath"],"sources":["../../../src/fill/formatAutoFillData.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Fill, IntlayerConfig, LocalesValues } from '@intlayer/types';\nimport { formatAutoFilledFilePath } from './formatAutoFilledFilePath';\n\nexport type FillData = {\n localeList: LocalesValues[];\n filePath: string;\n isPerLocale: boolean;\n};\n\nexport const formatFillData = (\n autoFillField: Fill,\n localeList: LocalesValues[],\n filePath: string,\n dictionaryKey: string,\n configuration: IntlayerConfig\n): FillData[] => {\n const outputContentDeclarationFile: FillData[] = [];\n\n const baseDir = configuration.content.baseDir;\n\n if (!autoFillField) return outputContentDeclarationFile;\n\n if (typeof autoFillField === 'string') {\n if (autoFillField.includes('{{locale}}')) {\n const output = localeList.map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n outputContentDeclarationFile.push(...output);\n } else {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField,\n dictionaryKey,\n filePath,\n baseDir\n );\n\n outputContentDeclarationFile.push({\n localeList,\n filePath: formattedFilePath,\n isPerLocale: false,\n });\n }\n\n return outputContentDeclarationFile;\n }\n\n if (typeof autoFillField === 'object') {\n const localeList = Object.keys(autoFillField).filter(\n (locale) =>\n typeof autoFillField[locale as keyof typeof autoFillField] === 'string'\n ) as LocalesValues[];\n\n const output: FillData[] = localeList\n .filter((locale) =>\n Boolean(autoFillField[locale as keyof typeof autoFillField])\n )\n .map((locale) => {\n const formattedFilePath = formatAutoFilledFilePath(\n autoFillField[locale as keyof typeof autoFillField] as string,\n dictionaryKey,\n filePath,\n baseDir,\n locale\n );\n\n return {\n localeList: [locale],\n filePath: formattedFilePath,\n isPerLocale: true,\n };\n });\n\n // Group by filePath and merge localeList\n const groupedByFilePath = output.reduce((acc, curr) => {\n const existing = acc.find((item) => item.filePath === curr.filePath);\n if (existing) {\n existing.localeList.push(...curr.localeList);\n } else {\n acc.push(curr);\n }\n return acc;\n }, [] as FillData[]);\n\n outputContentDeclarationFile.push(...groupedByFilePath);\n }\n\n return outputContentDeclarationFile;\n};\n"],"mappings":";;;AAUA,MAAa,kBACX,eACA,YACA,UACA,eACA,kBACe;CACf,MAAMA,+BAA2C,EAAE;CAEnD,MAAM,UAAU,cAAc,QAAQ;AAEtC,KAAI,CAAC,cAAe,QAAO;AAE3B,KAAI,OAAO,kBAAkB,UAAU;AACrC,MAAI,cAAc,SAAS,aAAa,EAAE;GACxC,MAAM,SAAS,WAAW,KAAK,WAAW;IACxC,MAAM,oBAAoBC,+DACxB,eACA,eACA,UACA,SACA,OACD;AAED,WAAO;KACL,YAAY,CAAC,OAAO;KACpB,UAAU;KACV,aAAa;KACd;KACD;AAEF,gCAA6B,KAAK,GAAG,OAAO;SACvC;GACL,MAAM,oBAAoBA,+DACxB,eACA,eACA,UACA,QACD;AAED,gCAA6B,KAAK;IAChC;IACA,UAAU;IACV,aAAa;IACd,CAAC;;AAGJ,SAAO;;AAGT,KAAI,OAAO,kBAAkB,UAAU;EA2BrC,MAAM,oBA1Ba,OAAO,KAAK,cAAc,CAAC,QAC3C,WACC,OAAO,cAAc,YAA0C,SAClE,CAGE,QAAQ,WACP,QAAQ,cAAc,QAAsC,CAC7D,CACA,KAAK,WAAW;GACf,MAAM,oBAAoBA,+DACxB,cAAc,SACd,eACA,UACA,SACA,OACD;AAED,UAAO;IACL,YAAY,CAAC,OAAO;IACpB,UAAU;IACV,aAAa;IACd;IACD,CAG6B,QAAQ,KAAK,SAAS;GACrD,MAAM,WAAW,IAAI,MAAM,SAAS,KAAK,aAAa,KAAK,SAAS;AACpE,OAAI,SACF,UAAS,WAAW,KAAK,GAAG,KAAK,WAAW;OAE5C,KAAI,KAAK,KAAK;AAEhB,UAAO;KACN,EAAE,CAAe;AAEpB,+BAA6B,KAAK,GAAG,kBAAkB;;AAGzD,QAAO"}