@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,76 +1,50 @@
1
- import { formatLocale, formatPath } from "@intlayer/chokidar";
2
- import {
3
- ANSIColors,
4
- colon,
5
- colorize,
6
- colorizeKey,
7
- colorizeNumber,
8
- getAppLogger,
9
- getConfiguration
10
- } from "@intlayer/config";
11
1
  import { listMissingTranslations } from "./listMissingTranslations.mjs";
12
- const testMissingTranslations = (options) => {
13
- const config = getConfiguration(options?.configOptions);
14
- const { locales, requiredLocales } = config.internationalization;
15
- const appLogger = getAppLogger(config, {
16
- config: {
17
- prefix: ""
18
- }
19
- });
20
- const result = listMissingTranslations(void 0, options?.configOptions);
21
- const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
22
- const maxLocalesColSize = result.missingTranslations.map((t) => formatLocale(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
23
- const formattedMissingTranslations = result.missingTranslations.map(
24
- (translation) => [
25
- colon(` - ${colorizeKey(translation.key)}`, {
26
- colSize: maxKeyColSize,
27
- maxSize: 40
28
- }),
29
- " - ",
30
- colon(formatLocale(translation.locales, ANSIColors.RED), {
31
- colSize: maxLocalesColSize,
32
- maxSize: 40
33
- }),
34
- " - ",
35
- translation.filePath ? formatPath(translation.filePath) : "Remote"
36
- ].join("")
37
- );
38
- appLogger(`Missing translations:`, {
39
- level: "info"
40
- });
41
- formattedMissingTranslations.forEach((t) => {
42
- appLogger(t, {
43
- level: "info"
44
- });
45
- });
46
- appLogger(`Locales: ${formatLocale(locales)}`);
47
- appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);
48
- appLogger(
49
- `Missing locales: ${result.missingLocales.length === 0 ? colorize("-", ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`
50
- );
51
- appLogger(
52
- `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize("-", ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`
53
- );
54
- appLogger(
55
- `Total missing locales: ${colorizeNumber(result.missingLocales.length, {
56
- one: ANSIColors.RED,
57
- other: ANSIColors.RED,
58
- zero: ANSIColors.GREEN
59
- })}`
60
- );
61
- appLogger(
62
- `Total missing required locales: ${colorizeNumber(
63
- result.missingRequiredLocales.length,
64
- {
65
- one: ANSIColors.RED,
66
- other: ANSIColors.RED,
67
- zero: ANSIColors.GREEN
68
- }
69
- )}`
70
- );
71
- };
72
- export {
73
- listMissingTranslations,
74
- testMissingTranslations
2
+ import { formatLocale, formatPath, prepareIntlayer } from "@intlayer/chokidar";
3
+ import { ANSIColors, colon, colorize, colorizeKey, colorizeNumber, getAppLogger, getConfiguration } from "@intlayer/config";
4
+
5
+ //#region src/test/index.ts
6
+ const testMissingTranslations = async (options) => {
7
+ const config = getConfiguration(options?.configOptions);
8
+ const { locales, requiredLocales } = config.internationalization;
9
+ const appLogger = getAppLogger(config, { config: { prefix: "" } });
10
+ if (options?.build === true) await prepareIntlayer(config, { forceRun: true });
11
+ else if (typeof options?.build === "undefined") await prepareIntlayer(config);
12
+ const result = listMissingTranslations(void 0, options?.configOptions);
13
+ const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
14
+ const maxLocalesColSize = result.missingTranslations.map((t) => formatLocale(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
15
+ const formattedMissingTranslations = result.missingTranslations.map((translation) => [
16
+ colon(` - ${colorizeKey(translation.key)}`, {
17
+ colSize: maxKeyColSize,
18
+ maxSize: 40
19
+ }),
20
+ " - ",
21
+ colon(formatLocale(translation.locales, ANSIColors.RED), {
22
+ colSize: maxLocalesColSize,
23
+ maxSize: 40
24
+ }),
25
+ " - ",
26
+ translation.filePath ? formatPath(translation.filePath) : "Remote"
27
+ ].join(""));
28
+ appLogger(`Missing translations:`, { level: "info" });
29
+ formattedMissingTranslations.forEach((t) => {
30
+ appLogger(t, { level: "info" });
31
+ });
32
+ appLogger(`Locales: ${formatLocale(locales)}`);
33
+ appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);
34
+ appLogger(`Missing locales: ${result.missingLocales.length === 0 ? colorize("-", ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`);
35
+ appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize("-", ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`);
36
+ appLogger(`Total missing locales: ${colorizeNumber(result.missingLocales.length, {
37
+ one: ANSIColors.RED,
38
+ other: ANSIColors.RED,
39
+ zero: ANSIColors.GREEN
40
+ })}`);
41
+ appLogger(`Total missing required locales: ${colorizeNumber(result.missingRequiredLocales.length, {
42
+ one: ANSIColors.RED,
43
+ other: ANSIColors.RED,
44
+ zero: ANSIColors.GREEN
45
+ })}`);
75
46
  };
47
+
48
+ //#endregion
49
+ export { listMissingTranslations, testMissingTranslations };
76
50
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n getAppLogger,\n getConfiguration,\n GetConfigurationOptions,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n};\n\nexport const testMissingTranslations = (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n const result = listMissingTranslations(undefined, options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n ' - ',\n translation.filePath ? formatPath(translation.filePath) : 'Remote',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":"AAAA,SAAS,cAAc,kBAAkB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B;AAQjC,MAAM,0BAA0B,CACrC,YACG;AACH,QAAM,SAAS,iBAAiB,SAAS,aAAa;AACtD,QAAM,EAAE,SAAS,gBAAgB,IAAI,OAAO;AAE5C,QAAM,YAAY,aAAa,QAAQ;AAAA,IACrC,QAAQ;AAAA,MACN,QAAQ;AAAA,IACV;AAAA,EACF,CAAC;AAED,QAAM,SAAS,wBAAwB,QAAW,SAAS,aAAa;AAExE,QAAM,gBAAgB,OAAO,oBAC1B,IAAI,CAAC,MAAM,MAAM,EAAE,GAAG,EAAE,EACxB,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;AAChD,QAAM,oBAAoB,OAAO,oBAC9B,IAAI,CAAC,MAAM,aAAa,EAAE,SAAS,KAAK,CAAC,EACzC,OAAO,CAAC,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,MAAM,GAAG,CAAC;AAEhD,QAAM,+BAA+B,OAAO,oBAAoB;AAAA,IAC9D,CAAC,gBACC;AAAA,MACE,MAAM,MAAM,YAAY,YAAY,GAAG,CAAC,IAAI;AAAA,QAC1C,SAAS;AAAA,QACT,SAAS;AAAA,MACX,CAAC;AAAA,MACD;AAAA,MACA,MAAM,aAAa,YAAY,SAAS,WAAW,GAAG,GAAG;AAAA,QACvD,SAAS;AAAA,QACT,SAAS;AAAA,MACX,CAAC;AAAA,MACD;AAAA,MACA,YAAY,WAAW,WAAW,YAAY,QAAQ,IAAI;AAAA,IAC5D,EAAE,KAAK,EAAE;AAAA,EACb;AAEA,YAAU,yBAAyB;AAAA,IACjC,OAAO;AAAA,EACT,CAAC;AAED,+BAA6B,QAAQ,CAAC,MAAM;AAC1C,cAAU,GAAG;AAAA,MACX,OAAO;AAAA,IACT,CAAC;AAAA,EACH,CAAC;AAED,YAAU,YAAY,aAAa,OAAO,CAAC,EAAE;AAC7C,YAAU,qBAAqB,aAAa,mBAAmB,OAAO,CAAC,EAAE;AACzE;AAAA,IACE,oBAAoB,OAAO,eAAe,WAAW,IAAI,SAAS,KAAK,WAAW,KAAK,IAAI,aAAa,OAAO,gBAAgB,WAAW,GAAG,CAAC;AAAA,EAChJ;AAEA;AAAA,IACE,6BAA6B,OAAO,uBAAuB,WAAW,IAAI,SAAS,KAAK,WAAW,KAAK,IAAI,aAAa,OAAO,wBAAwB,WAAW,GAAG,CAAC;AAAA,EACzK;AACA;AAAA,IACE,0BAA0B,eAAe,OAAO,eAAe,QAAQ;AAAA,MACrE,KAAK,WAAW;AAAA,MAChB,OAAO,WAAW;AAAA,MAClB,MAAM,WAAW;AAAA,IACnB,CAAC,CAAC;AAAA,EACJ;AACA;AAAA,IACE,mCAAmC;AAAA,MACjC,OAAO,uBAAuB;AAAA,MAC9B;AAAA,QACE,KAAK,WAAW;AAAA,QAChB,OAAO,WAAW;AAAA,QAClB,MAAM,WAAW;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/test/index.ts"],"sourcesContent":["import { formatLocale, formatPath, prepareIntlayer } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeKey,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport { listMissingTranslations } from './listMissingTranslations';\n\nexport { listMissingTranslations };\n\ntype ListMissingTranslationsOptions = {\n configOptions?: GetConfigurationOptions;\n build?: boolean;\n};\n\nexport const testMissingTranslations = async (\n options?: ListMissingTranslationsOptions\n) => {\n const config = getConfiguration(options?.configOptions);\n const { locales, requiredLocales } = config.internationalization;\n\n const appLogger = getAppLogger(config, {\n config: {\n prefix: '',\n },\n });\n\n if (options?.build === true) {\n await prepareIntlayer(config, { forceRun: true });\n } else if (typeof options?.build === 'undefined') {\n await prepareIntlayer(config);\n }\n\n const result = listMissingTranslations(undefined, options?.configOptions);\n\n const maxKeyColSize = result.missingTranslations\n .map((t) => ` - ${t.key}`)\n .reduce((max, t) => Math.max(max, t.length), 0);\n const maxLocalesColSize = result.missingTranslations\n .map((t) => formatLocale(t.locales, false))\n .reduce((max, t) => Math.max(max, t.length), 0);\n\n const formattedMissingTranslations = result.missingTranslations.map(\n (translation) =>\n [\n colon(` - ${colorizeKey(translation.key)}`, {\n colSize: maxKeyColSize,\n maxSize: 40,\n }),\n ' - ',\n colon(formatLocale(translation.locales, ANSIColors.RED), {\n colSize: maxLocalesColSize,\n maxSize: 40,\n }),\n ' - ',\n translation.filePath ? formatPath(translation.filePath) : 'Remote',\n ].join('')\n );\n\n appLogger(`Missing translations:`, {\n level: 'info',\n });\n\n formattedMissingTranslations.forEach((t) => {\n appLogger(t, {\n level: 'info',\n });\n });\n\n appLogger(`Locales: ${formatLocale(locales)}`);\n appLogger(`Required locales: ${formatLocale(requiredLocales ?? locales)}`);\n appLogger(\n `Missing locales: ${result.missingLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingLocales, ANSIColors.RED)}`\n );\n\n appLogger(\n `Missing required locales: ${result.missingRequiredLocales.length === 0 ? colorize('-', ANSIColors.GREEN) : formatLocale(result.missingRequiredLocales, ANSIColors.RED)}`\n );\n appLogger(\n `Total missing locales: ${colorizeNumber(result.missingLocales.length, {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n })}`\n );\n appLogger(\n `Total missing required locales: ${colorizeNumber(\n result.missingRequiredLocales.length,\n {\n one: ANSIColors.RED,\n other: ANSIColors.RED,\n zero: ANSIColors.GREEN,\n }\n )}`\n );\n};\n"],"mappings":";;;;;AAoBA,MAAa,0BAA0B,OACrC,YACG;CACH,MAAM,SAAS,iBAAiB,SAAS,cAAc;CACvD,MAAM,EAAE,SAAS,oBAAoB,OAAO;CAE5C,MAAM,YAAY,aAAa,QAAQ,EACrC,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;AAEF,KAAI,SAAS,UAAU,KACrB,OAAM,gBAAgB,QAAQ,EAAE,UAAU,MAAM,CAAC;UACxC,OAAO,SAAS,UAAU,YACnC,OAAM,gBAAgB,OAAO;CAG/B,MAAM,SAAS,wBAAwB,QAAW,SAAS,cAAc;CAEzE,MAAM,gBAAgB,OAAO,oBAC1B,KAAK,MAAM,MAAM,EAAE,MAAM,CACzB,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CACjD,MAAM,oBAAoB,OAAO,oBAC9B,KAAK,MAAM,aAAa,EAAE,SAAS,MAAM,CAAC,CAC1C,QAAQ,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,OAAO,EAAE,EAAE;CAEjD,MAAM,+BAA+B,OAAO,oBAAoB,KAC7D,gBACC;EACE,MAAM,MAAM,YAAY,YAAY,IAAI,IAAI;GAC1C,SAAS;GACT,SAAS;GACV,CAAC;EACF;EACA,MAAM,aAAa,YAAY,SAAS,WAAW,IAAI,EAAE;GACvD,SAAS;GACT,SAAS;GACV,CAAC;EACF;EACA,YAAY,WAAW,WAAW,YAAY,SAAS,GAAG;EAC3D,CAAC,KAAK,GAAG,CACb;AAED,WAAU,yBAAyB,EACjC,OAAO,QACR,CAAC;AAEF,8BAA6B,SAAS,MAAM;AAC1C,YAAU,GAAG,EACX,OAAO,QACR,CAAC;GACF;AAEF,WAAU,YAAY,aAAa,QAAQ,GAAG;AAC9C,WAAU,qBAAqB,aAAa,mBAAmB,QAAQ,GAAG;AAC1E,WACE,oBAAoB,OAAO,eAAe,WAAW,IAAI,SAAS,KAAK,WAAW,MAAM,GAAG,aAAa,OAAO,gBAAgB,WAAW,IAAI,GAC/I;AAED,WACE,6BAA6B,OAAO,uBAAuB,WAAW,IAAI,SAAS,KAAK,WAAW,MAAM,GAAG,aAAa,OAAO,wBAAwB,WAAW,IAAI,GACxK;AACD,WACE,0BAA0B,eAAe,OAAO,eAAe,QAAQ;EACrE,KAAK,WAAW;EAChB,OAAO,WAAW;EAClB,MAAM,WAAW;EAClB,CAAC,GACH;AACD,WACE,mCAAmC,eACjC,OAAO,uBAAuB,QAC9B;EACE,KAAK,WAAW;EAChB,OAAO,WAAW;EAClB,MAAM,WAAW;EAClB,CACF,GACF"}
@@ -1,45 +1,34 @@
1
- import {
2
- getConfiguration
3
- } from "@intlayer/config";
4
- import {
5
- getMissingLocalesContent
6
- } from "@intlayer/core";
1
+ import { getConfiguration } from "@intlayer/config";
7
2
  import { getUnmergedDictionaries } from "@intlayer/unmerged-dictionaries-entry";
3
+ import { getMissingLocalesContent } from "@intlayer/core";
4
+
5
+ //#region src/test/listMissingTranslations.ts
8
6
  const listMissingTranslations = (dictionariesRecord, configurationOptions) => {
9
- const configuration = getConfiguration(configurationOptions);
10
- const unmergedDictionariesRecord = dictionariesRecord ?? getUnmergedDictionaries(configuration);
11
- const missingTranslations = [];
12
- const { locales, requiredLocales } = configuration.internationalization;
13
- for (const dictionaries of Object.values(unmergedDictionariesRecord)) {
14
- for (const dictionary of dictionaries) {
15
- const missingLocales2 = getMissingLocalesContent(
16
- dictionary,
17
- configuration.internationalization.locales,
18
- {
19
- dictionaryKey: dictionary.key,
20
- keyPath: [],
21
- plugins: []
22
- }
23
- );
24
- if (missingLocales2.length > 0) {
25
- missingTranslations.push({
26
- key: dictionary.key,
27
- filePath: dictionary.filePath,
28
- locales: missingLocales2
29
- });
30
- }
31
- }
32
- }
33
- const missingLocalesSet = new Set(
34
- missingTranslations.flatMap((t) => t.locales)
35
- );
36
- const missingLocales = Array.from(missingLocalesSet);
37
- const missingRequiredLocales = missingLocales.filter(
38
- (locale) => (requiredLocales ?? locales).includes(locale)
39
- );
40
- return { missingTranslations, missingLocales, missingRequiredLocales };
41
- };
42
- export {
43
- listMissingTranslations
7
+ const configuration = getConfiguration(configurationOptions);
8
+ const unmergedDictionariesRecord = dictionariesRecord ?? getUnmergedDictionaries(configuration);
9
+ const missingTranslations = [];
10
+ const { locales, requiredLocales } = configuration.internationalization;
11
+ for (const dictionaries of Object.values(unmergedDictionariesRecord)) for (const dictionary of dictionaries) {
12
+ const missingLocales$1 = getMissingLocalesContent(dictionary, configuration.internationalization.locales, {
13
+ dictionaryKey: dictionary.key,
14
+ keyPath: [],
15
+ plugins: []
16
+ });
17
+ if (missingLocales$1.length > 0) missingTranslations.push({
18
+ key: dictionary.key,
19
+ filePath: dictionary.filePath,
20
+ locales: missingLocales$1
21
+ });
22
+ }
23
+ const missingLocalesSet = new Set(missingTranslations.flatMap((t) => t.locales));
24
+ const missingLocales = Array.from(missingLocalesSet);
25
+ return {
26
+ missingTranslations,
27
+ missingLocales,
28
+ missingRequiredLocales: missingLocales.filter((locale) => (requiredLocales ?? locales).includes(locale))
29
+ };
44
30
  };
31
+
32
+ //#endregion
33
+ export { listMissingTranslations };
45
34
  //# sourceMappingURL=listMissingTranslations.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n GetConfigurationOptions,\n type Locales,\n getConfiguration,\n} from '@intlayer/config';\nimport {\n type ContentNode,\n type Dictionary,\n getMissingLocalesContent,\n} from '@intlayer/core';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n dictionariesRecord?: Record<string, Dictionary[]>,\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n const unmergedDictionariesRecord =\n dictionariesRecord ?? getUnmergedDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n locales: Locales[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n for (const dictionaries of Object.values(unmergedDictionariesRecord)) {\n for (const dictionary of dictionaries as unknown as Dictionary[]) {\n const missingLocales = getMissingLocalesContent(\n dictionary as unknown as ContentNode,\n configuration.internationalization.locales,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionary.key,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":"AAAA;AAAA,EAGE;AAAA,OACK;AACP;AAAA,EAGE;AAAA,OACK;AACP,SAAS,+BAA+B;AAEjC,MAAM,0BAA0B,CACrC,oBACA,yBACG;AACH,QAAM,gBAAgB,iBAAiB,oBAAoB;AAC3D,QAAM,6BACJ,sBAAsB,wBAAwB,aAAa;AAE7D,QAAM,sBAIA,CAAC;AAEP,QAAM,EAAE,SAAS,gBAAgB,IAAI,cAAc;AAEnD,aAAW,gBAAgB,OAAO,OAAO,0BAA0B,GAAG;AACpE,eAAW,cAAc,cAAyC;AAChE,YAAMA,kBAAiB;AAAA,QACrB;AAAA,QACA,cAAc,qBAAqB;AAAA,QACnC;AAAA,UACE,eAAe,WAAW;AAAA,UAC1B,SAAS,CAAC;AAAA,UACV,SAAS,CAAC;AAAA,QACZ;AAAA,MACF;AAEA,UAAIA,gBAAe,SAAS,GAAG;AAC7B,4BAAoB,KAAK;AAAA,UACvB,KAAK,WAAW;AAAA,UAChB,UAAU,WAAW;AAAA,UACrB,SAASA;AAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,QAAM,oBAAoB,IAAI;AAAA,IAC5B,oBAAoB,QAAQ,CAAC,MAAM,EAAE,OAAO;AAAA,EAC9C;AACA,QAAM,iBAAiB,MAAM,KAAK,iBAAiB;AAEnD,QAAM,yBAAyB,eAAe;AAAA,IAAO,CAAC,YACnD,mBAAmB,SAAS,SAAS,MAAM;AAAA,EAC9C;AAEA,SAAO,EAAE,qBAAqB,gBAAgB,uBAAuB;AACvE;","names":["missingLocales"]}
1
+ {"version":3,"file":"listMissingTranslations.mjs","names":["missingTranslations: {\n key: string;\n filePath?: string;\n locales: Locale[];\n }[]","missingLocales"],"sources":["../../../src/test/listMissingTranslations.ts"],"sourcesContent":["import {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config';\nimport { getMissingLocalesContent } from '@intlayer/core';\nimport type { ContentNode, Dictionary, Locale } from '@intlayer/types';\nimport { getUnmergedDictionaries } from '@intlayer/unmerged-dictionaries-entry';\n\nexport const listMissingTranslations = (\n dictionariesRecord?: Record<string, Dictionary[]>,\n configurationOptions?: GetConfigurationOptions\n) => {\n const configuration = getConfiguration(configurationOptions);\n const unmergedDictionariesRecord =\n dictionariesRecord ?? getUnmergedDictionaries(configuration);\n\n const missingTranslations: {\n key: string;\n filePath?: string;\n locales: Locale[];\n }[] = [];\n\n const { locales, requiredLocales } = configuration.internationalization;\n\n for (const dictionaries of Object.values(unmergedDictionariesRecord)) {\n for (const dictionary of dictionaries as unknown as Dictionary[]) {\n const missingLocales = getMissingLocalesContent(\n dictionary as unknown as ContentNode,\n configuration.internationalization.locales,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n );\n\n if (missingLocales.length > 0) {\n missingTranslations.push({\n key: dictionary.key,\n filePath: dictionary.filePath,\n locales: missingLocales,\n });\n }\n }\n }\n\n const missingLocalesSet = new Set(\n missingTranslations.flatMap((t) => t.locales)\n );\n const missingLocales = Array.from(missingLocalesSet);\n\n const missingRequiredLocales = missingLocales.filter((locale) =>\n (requiredLocales ?? locales).includes(locale)\n );\n\n return { missingTranslations, missingLocales, missingRequiredLocales };\n};\n"],"mappings":";;;;;AAQA,MAAa,2BACX,oBACA,yBACG;CACH,MAAM,gBAAgB,iBAAiB,qBAAqB;CAC5D,MAAM,6BACJ,sBAAsB,wBAAwB,cAAc;CAE9D,MAAMA,sBAIA,EAAE;CAER,MAAM,EAAE,SAAS,oBAAoB,cAAc;AAEnD,MAAK,MAAM,gBAAgB,OAAO,OAAO,2BAA2B,CAClE,MAAK,MAAM,cAAc,cAAyC;EAChE,MAAMC,mBAAiB,yBACrB,YACA,cAAc,qBAAqB,SACnC;GACE,eAAe,WAAW;GAC1B,SAAS,EAAE;GACX,SAAS,EAAE;GACZ,CACF;AAED,MAAIA,iBAAe,SAAS,EAC1B,qBAAoB,KAAK;GACvB,KAAK,WAAW;GAChB,UAAU,WAAW;GACrB,SAASA;GACV,CAAC;;CAKR,MAAM,oBAAoB,IAAI,IAC5B,oBAAoB,SAAS,MAAM,EAAE,QAAQ,CAC9C;CACD,MAAM,iBAAiB,MAAM,KAAK,kBAAkB;AAMpD,QAAO;EAAE;EAAqB;EAAgB,wBAJf,eAAe,QAAQ,YACnD,mBAAmB,SAAS,SAAS,OAAO,CAC9C;EAEqE"}
@@ -1,201 +1,122 @@
1
- import {
2
- formatLocale,
3
- formatPath,
4
- listGitFiles,
5
- parallelize
6
- } from "@intlayer/chokidar";
7
- import {
8
- ANSIColors,
9
- colon,
10
- colorize,
11
- colorizeNumber,
12
- getAppLogger,
13
- getConfiguration,
14
- retryManager
15
- } from "@intlayer/config";
16
- import fg from "fast-glob";
17
- import { existsSync, mkdirSync, writeFileSync } from "fs";
18
- import { readFile } from "fs/promises";
19
- import { dirname, join, relative } from "path";
20
- import { fileURLToPath } from "url";
21
- import { chunkText } from "./utils/calculateChunks.mjs";
22
1
  import { checkAIAccess } from "./utils/checkAccess.mjs";
2
+ import { readAsset } from "./_virtual/_utils_asset.mjs";
3
+ import { chunkText } from "./utils/calculateChunks.mjs";
23
4
  import { checkFileModifiedRange } from "./utils/checkFileModifiedRange.mjs";
24
5
  import { chunkInference } from "./utils/chunkInference.mjs";
25
6
  import { fixChunkStartEndChars } from "./utils/fixChunkStartEndChars.mjs";
26
- import { getChunk } from "./utils/getChunk.mjs";
27
7
  import { getOutputFilePath } from "./utils/getOutputFilePath.mjs";
28
- const isESModule = typeof import.meta.url === "string";
29
- const dir = isESModule ? dirname(fileURLToPath(import.meta.url)) : __dirname;
30
- const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, aiOptions, configuration = getConfiguration(), customInstructions) => {
31
- try {
32
- const appLogger = getAppLogger(configuration, {
33
- config: {
34
- prefix: ""
35
- }
36
- });
37
- const fileContent = await readFile(baseFilePath, "utf-8");
38
- let fileResultContent = fileContent;
39
- const basePrompt = (await readFile(join(dir, "./prompts/TRANSLATE_PROMPT.md"), "utf-8")).replaceAll("{{localeName}}", `${formatLocale(locale, false)}`).replaceAll("{{baseLocaleName}}", `${formatLocale(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
40
- const filePrexixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;
41
- const filePrefix = [
42
- colon(filePrexixText, { colSize: 40 }),
43
- `\u2192 ${ANSIColors.RESET}`
44
- ].join("");
45
- const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;
46
- const prefix = [
47
- colon(prefixText, { colSize: 40 }),
48
- `\u2192 ${ANSIColors.RESET}`
49
- ].join("");
50
- const chunks = chunkText(fileContent);
51
- appLogger(
52
- `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`
53
- );
54
- for await (const [i, chunk] of chunks.entries()) {
55
- const isFirstChunk = i === 0;
56
- const getPrevChunkPrompt = () => `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:
57
- ///chunkStart///` + getChunk(fileResultContent, chunks[i - 1]) + `///chunkEnd///`;
58
- const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.
59
- ///chunksStart///` + (chunks[i - 1]?.content ?? "") + chunks[i].content + (chunks[i + 1]?.content ?? "") + `///chunksEnd///`;
60
- const fileToTranslateCurrentChunk = chunk.content;
61
- let chunkTranslation = await retryManager(async () => {
62
- const result = await chunkInference(
63
- [
64
- { role: "system", content: basePrompt },
65
- { role: "system", content: getBaseChunkContextPrompt() },
66
- ...isFirstChunk ? [] : [{ role: "system", content: getPrevChunkPrompt() }],
67
- {
68
- role: "system",
69
- content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`
70
- },
71
- { role: "user", content: fileToTranslateCurrentChunk }
72
- ],
73
- aiOptions,
74
- configuration
75
- );
76
- appLogger(
77
- [
78
- `${prefix}`,
79
- `${ANSIColors.GREY_DARK}[Chunk `,
80
- colorizeNumber(i + 1),
81
- `${ANSIColors.GREY_DARK} of `,
82
- colorizeNumber(chunks.length),
83
- `${ANSIColors.GREY_DARK}] \u2192${ANSIColors.RESET} `,
84
- `${colorizeNumber(result.tokenUsed)} tokens used`
85
- ].join("")
86
- );
87
- const fixedTranslatedChunkResult = fixChunkStartEndChars(
88
- result?.fileContent,
89
- fileToTranslateCurrentChunk
90
- );
91
- return fixedTranslatedChunkResult;
92
- })();
93
- fileResultContent = fileResultContent.replace(
94
- fileToTranslateCurrentChunk,
95
- chunkTranslation
96
- );
97
- }
98
- mkdirSync(dirname(outputFilePath), { recursive: true });
99
- writeFileSync(outputFilePath, fileResultContent);
100
- const relativePath = relative(
101
- configuration.content.baseDir,
102
- outputFilePath
103
- );
104
- appLogger(
105
- `${colorize("\u2714", ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`
106
- );
107
- } catch (error) {
108
- console.error(error);
109
- }
110
- };
111
- const translateDoc = async ({
112
- docPattern,
113
- locales,
114
- excludedGlobPattern,
115
- baseLocale,
116
- aiOptions,
117
- nbSimultaneousFileProcessed,
118
- configOptions,
119
- customInstructions,
120
- skipIfModifiedBefore,
121
- skipIfModifiedAfter,
122
- gitOptions
123
- }) => {
124
- const configuration = getConfiguration(configOptions);
125
- const appLogger = getAppLogger(configuration, {
126
- config: {
127
- prefix: ""
128
- }
129
- });
130
- if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
131
- appLogger(
132
- `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`
133
- );
134
- nbSimultaneousFileProcessed = 10;
135
- }
136
- let docList = fg.sync(docPattern, {
137
- ignore: excludedGlobPattern
138
- });
139
- const hasCMSAuth = await checkAIAccess(configuration, aiOptions);
140
- if (!hasCMSAuth) return;
141
- if (gitOptions) {
142
- const gitChangedFiles = await listGitFiles(gitOptions);
143
- if (gitChangedFiles) {
144
- docList = docList.filter(
145
- (path) => gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)
146
- );
147
- }
148
- }
149
- appLogger(`Base locale is ${formatLocale(baseLocale)}`);
150
- appLogger(
151
- `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`
152
- );
153
- appLogger(`Translating ${colorizeNumber(docList.length)} files:`);
154
- appLogger(docList.map((path) => ` - ${formatPath(path)}
155
- `));
156
- const allTasks = docList.flatMap(
157
- (docPath) => locales.map((locale) => async () => {
158
- appLogger(
159
- `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`
160
- );
161
- const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);
162
- const outputFilePath = getOutputFilePath(
163
- absoluteBaseFilePath,
164
- locale,
165
- baseLocale
166
- );
167
- if (!existsSync(outputFilePath)) {
168
- appLogger(`File ${outputFilePath} does not exist, creating it...`);
169
- mkdirSync(dirname(outputFilePath), { recursive: true });
170
- writeFileSync(outputFilePath, "");
171
- }
172
- const fileModificationData = checkFileModifiedRange(outputFilePath, {
173
- skipIfModifiedBefore,
174
- skipIfModifiedAfter
175
- });
176
- if (fileModificationData.isSkipped) {
177
- appLogger(fileModificationData.message);
178
- return;
179
- }
180
- await translateFile(
181
- absoluteBaseFilePath,
182
- outputFilePath,
183
- locale,
184
- baseLocale,
185
- aiOptions,
186
- configuration,
187
- customInstructions
188
- );
189
- })
190
- );
191
- await parallelize(
192
- allTasks,
193
- (task) => task(),
194
- nbSimultaneousFileProcessed ?? 3
195
- );
8
+ import { formatLocale, formatPath, getChunk, listGitFiles, parallelize } from "@intlayer/chokidar";
9
+ import { ANSIColors, colon, colorize, colorizeNumber, getAppLogger, getConfiguration, retryManager } from "@intlayer/config";
10
+ import { dirname, join, relative } from "node:path";
11
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
12
+ import { readFile } from "node:fs/promises";
13
+ import fg from "fast-glob";
14
+
15
+ //#region src/translateDoc.ts
16
+ /**
17
+ * Translate a single file for a given locale
18
+ */
19
+ const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions) => {
20
+ try {
21
+ const appLogger = getAppLogger(configuration, { config: { prefix: "" } });
22
+ const fileContent = await readFile(baseFilePath, "utf-8");
23
+ let fileResultContent = fileContent;
24
+ const basePrompt = readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${formatLocale(locale, false)}`).replaceAll("{{baseLocaleName}}", `${formatLocale(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
25
+ const filePrefix = [colon(`${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${ANSIColors.RESET}`].join("");
26
+ const prefix = [colon(`${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${ANSIColors.RESET}`].join("");
27
+ const chunks = chunkText(fileContent);
28
+ appLogger(`${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`);
29
+ for await (const [i, chunk] of chunks.entries()) {
30
+ const isFirstChunk = i === 0;
31
+ const getPrevChunkPrompt = () => `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\n///chunkStart///` + getChunk(fileResultContent, chunks[i - 1]) + `///chunkEnd///`;
32
+ const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\n///chunksStart///` + (chunks[i - 1]?.content ?? "") + chunks[i].content + (chunks[i + 1]?.content ?? "") + `///chunksEnd///`;
33
+ const fileToTranslateCurrentChunk = chunk.content;
34
+ const chunkTranslation = await retryManager(async () => {
35
+ const result = await chunkInference([
36
+ {
37
+ role: "system",
38
+ content: basePrompt
39
+ },
40
+ {
41
+ role: "system",
42
+ content: getBaseChunkContextPrompt()
43
+ },
44
+ ...isFirstChunk ? [] : [{
45
+ role: "system",
46
+ content: getPrevChunkPrompt()
47
+ }],
48
+ {
49
+ role: "system",
50
+ content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`
51
+ },
52
+ {
53
+ role: "user",
54
+ content: fileToTranslateCurrentChunk
55
+ }
56
+ ], aiOptions, configuration);
57
+ appLogger([
58
+ `${prefix}`,
59
+ `${ANSIColors.GREY_DARK}[Chunk `,
60
+ colorizeNumber(i + 1),
61
+ `${ANSIColors.GREY_DARK} of `,
62
+ colorizeNumber(chunks.length),
63
+ `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,
64
+ `${colorizeNumber(result.tokenUsed)} tokens used`
65
+ ].join(""));
66
+ return fixChunkStartEndChars(result?.fileContent, fileToTranslateCurrentChunk);
67
+ })();
68
+ fileResultContent = fileResultContent.replace(fileToTranslateCurrentChunk, chunkTranslation);
69
+ }
70
+ mkdirSync(dirname(outputFilePath), { recursive: true });
71
+ writeFileSync(outputFilePath, fileResultContent);
72
+ const relativePath = relative(configuration.content.baseDir, outputFilePath);
73
+ appLogger(`${colorize("✔", ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`);
74
+ } catch (error) {
75
+ console.error(error);
76
+ }
196
77
  };
197
- export {
198
- translateDoc,
199
- translateFile
78
+ /**
79
+ * Main translate function: scans all .md files in "en/" (unless you specified DOC_LIST),
80
+ * then translates them to each locale in LOCALE_LIST.
81
+ */
82
+ const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, gitOptions }) => {
83
+ const configuration = getConfiguration(configOptions);
84
+ const appLogger = getAppLogger(configuration);
85
+ if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
86
+ appLogger(`Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`);
87
+ nbSimultaneousFileProcessed = 10;
88
+ }
89
+ let docList = await fg(docPattern, { ignore: excludedGlobPattern });
90
+ if (!await checkAIAccess(configuration, aiOptions)) return;
91
+ if (gitOptions) {
92
+ const gitChangedFiles = await listGitFiles(gitOptions);
93
+ if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile));
94
+ }
95
+ appLogger(`Base locale is ${formatLocale(baseLocale)}`);
96
+ appLogger(`Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`);
97
+ appLogger(`Translating ${colorizeNumber(docList.length)} files:`);
98
+ appLogger(docList.map((path) => ` - ${formatPath(path)}\n`));
99
+ await parallelize(docList.flatMap((docPath) => locales.map((locale) => async () => {
100
+ appLogger(`Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`);
101
+ const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);
102
+ const outputFilePath = getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
103
+ if (!existsSync(outputFilePath)) {
104
+ appLogger(`File ${outputFilePath} does not exist, creating it...`);
105
+ mkdirSync(dirname(outputFilePath), { recursive: true });
106
+ writeFileSync(outputFilePath, "");
107
+ }
108
+ const fileModificationData = checkFileModifiedRange(outputFilePath, {
109
+ skipIfModifiedBefore,
110
+ skipIfModifiedAfter
111
+ });
112
+ if (fileModificationData.isSkipped) {
113
+ appLogger(fileModificationData.message);
114
+ return;
115
+ }
116
+ await translateFile(absoluteBaseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions);
117
+ })), (task) => task(), nbSimultaneousFileProcessed ?? 3);
200
118
  };
119
+
120
+ //#endregion
121
+ export { translateDoc, translateFile };
201
122
  //# sourceMappingURL=translateDoc.mjs.map