@intlayer/cli 6.1.6-canary.0 → 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.
- package/dist/cjs/IntlayerEventListener.cjs +187 -239
- package/dist/cjs/IntlayerEventListener.cjs.map +1 -1
- package/dist/cjs/_virtual/_utils_asset.cjs +104 -0
- package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/cjs/build.cjs +23 -42
- package/dist/cjs/build.cjs.map +1 -1
- package/dist/cjs/cli.cjs +370 -431
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/config.cjs +10 -35
- package/dist/cjs/config.cjs.map +1 -1
- package/dist/cjs/editor.cjs +51 -66
- package/dist/cjs/editor.cjs.map +1 -1
- package/dist/cjs/fill/fill.cjs +73 -301
- package/dist/cjs/fill/fill.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFillData.cjs +48 -106
- package/dist/cjs/fill/formatAutoFillData.cjs.map +1 -1
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs +27 -43
- package/dist/cjs/fill/formatAutoFilledFilePath.cjs.map +1 -1
- package/dist/cjs/fill/formatFillData.cjs +50 -0
- package/dist/cjs/fill/formatFillData.cjs.map +1 -0
- package/dist/cjs/fill/groupLimiter.cjs +42 -0
- package/dist/cjs/fill/groupLimiter.cjs.map +1 -0
- package/dist/cjs/fill/index.cjs +5 -25
- package/dist/cjs/fill/listTranslationsTasks.cjs +77 -0
- package/dist/cjs/fill/listTranslationsTasks.cjs.map +1 -0
- package/dist/cjs/fill/test-original-case.cjs +10 -0
- package/dist/cjs/fill/test-original-case.cjs.map +1 -0
- package/dist/cjs/fill/translateDictionary.cjs +148 -0
- package/dist/cjs/fill/translateDictionary.cjs.map +1 -0
- package/dist/cjs/fill/writeAutoFill.cjs +48 -0
- package/dist/cjs/fill/writeAutoFill.cjs.map +1 -0
- package/dist/cjs/fill/writeFill.cjs +50 -0
- package/dist/cjs/fill/writeFill.cjs.map +1 -0
- package/dist/cjs/getTargetDictionary.cjs +36 -76
- package/dist/cjs/getTargetDictionary.cjs.map +1 -1
- package/dist/cjs/index.cjs +31 -45
- package/dist/cjs/listContentDeclaration.cjs +36 -64
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/liveSync.cjs +146 -221
- package/dist/cjs/liveSync.cjs.map +1 -1
- package/dist/cjs/pull.cjs +132 -195
- package/dist/cjs/pull.cjs.map +1 -1
- package/dist/cjs/push/pullLog.cjs +101 -144
- package/dist/cjs/push/pullLog.cjs.map +1 -1
- package/dist/cjs/push/push.cjs +159 -249
- package/dist/cjs/push/push.cjs.map +1 -1
- package/dist/cjs/pushConfig.cjs +18 -45
- package/dist/cjs/pushConfig.cjs.map +1 -1
- package/dist/cjs/pushLog.cjs +87 -128
- package/dist/cjs/pushLog.cjs.map +1 -1
- package/dist/cjs/reviewDoc.cjs +183 -291
- package/dist/cjs/reviewDoc.cjs.map +1 -1
- package/dist/cjs/test/index.cjs +52 -91
- package/dist/cjs/test/index.cjs.map +1 -1
- package/dist/cjs/test/listMissingTranslations.cjs +35 -62
- package/dist/cjs/test/listMissingTranslations.cjs.map +1 -1
- package/dist/cjs/translateDoc.cjs +127 -221
- package/dist/cjs/translateDoc.cjs.map +1 -1
- package/dist/cjs/utils/calculateChunks.cjs +85 -115
- package/dist/cjs/utils/calculateChunks.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +33 -72
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/checkFileModifiedRange.cjs +75 -91
- package/dist/cjs/utils/checkFileModifiedRange.cjs.map +1 -1
- package/dist/cjs/utils/checkLastUpdateTime.cjs +17 -30
- package/dist/cjs/utils/checkLastUpdateTime.cjs.map +1 -1
- package/dist/cjs/utils/chunkInference.cjs +28 -47
- package/dist/cjs/utils/chunkInference.cjs.map +1 -1
- package/dist/cjs/utils/fixChunkStartEndChars.cjs +23 -42
- package/dist/cjs/utils/fixChunkStartEndChars.cjs.map +1 -1
- package/dist/cjs/utils/formatTimeDiff.cjs +17 -43
- package/dist/cjs/utils/formatTimeDiff.cjs.map +1 -1
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs +13 -32
- package/dist/cjs/utils/getIsFileUpdatedRecently.cjs.map +1 -1
- package/dist/cjs/utils/getOutputFilePath.cjs +71 -86
- package/dist/cjs/utils/getOutputFilePath.cjs.map +1 -1
- package/dist/cjs/utils/getParentPackageJSON.cjs +19 -44
- package/dist/cjs/utils/getParentPackageJSON.cjs.map +1 -1
- package/dist/cjs/utils/listSpecialChars.cjs +49 -73
- package/dist/cjs/utils/listSpecialChars.cjs.map +1 -1
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs +90 -132
- package/dist/cjs/utils/mapChunksBetweenFiles.cjs.map +1 -1
- package/dist/cjs/utils/reorderParagraphs.cjs +86 -118
- package/dist/cjs/utils/reorderParagraphs.cjs.map +1 -1
- package/dist/cjs/watch.cjs +21 -39
- package/dist/cjs/watch.cjs.map +1 -1
- package/dist/esm/IntlayerEventListener.mjs +178 -201
- package/dist/esm/IntlayerEventListener.mjs.map +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +100 -0
- package/dist/esm/_virtual/rolldown_runtime.mjs +8 -0
- package/dist/esm/build.mjs +20 -23
- package/dist/esm/build.mjs.map +1 -1
- package/dist/esm/cli.mjs +349 -380
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/config.mjs +8 -14
- package/dist/esm/config.mjs.map +1 -1
- package/dist/esm/editor.mjs +47 -41
- package/dist/esm/editor.mjs.map +1 -1
- package/dist/esm/fill/fill.mjs +68 -300
- package/dist/esm/fill/fill.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFillData.mjs +47 -81
- package/dist/esm/fill/formatAutoFillData.mjs.map +1 -1
- package/dist/esm/fill/formatAutoFilledFilePath.mjs +25 -19
- package/dist/esm/fill/formatAutoFilledFilePath.mjs.map +1 -1
- package/dist/esm/fill/formatFillData.mjs +50 -0
- package/dist/esm/fill/formatFillData.mjs.map +1 -0
- package/dist/esm/fill/groupLimiter.mjs +40 -0
- package/dist/esm/fill/groupLimiter.mjs.map +1 -0
- package/dist/esm/fill/index.mjs +4 -3
- package/dist/esm/fill/listTranslationsTasks.mjs +70 -0
- package/dist/esm/fill/listTranslationsTasks.mjs.map +1 -0
- package/dist/esm/fill/test-original-case.mjs +10 -0
- package/dist/esm/fill/test-original-case.mjs.map +1 -0
- package/dist/esm/fill/translateDictionary.mjs +141 -0
- package/dist/esm/fill/translateDictionary.mjs.map +1 -0
- package/dist/esm/fill/writeAutoFill.mjs +44 -0
- package/dist/esm/fill/writeAutoFill.mjs.map +1 -0
- package/dist/esm/fill/writeFill.mjs +45 -0
- package/dist/esm/fill/writeFill.mjs.map +1 -0
- package/dist/esm/getTargetDictionary.mjs +27 -48
- package/dist/esm/getTargetDictionary.mjs.map +1 -1
- package/dist/esm/index.mjs +15 -13
- package/dist/esm/listContentDeclaration.mjs +28 -43
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/liveSync.mjs +135 -187
- package/dist/esm/liveSync.mjs.map +1 -1
- package/dist/esm/pull.mjs +125 -178
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/pullLog.mjs +99 -125
- package/dist/esm/push/pullLog.mjs.map +1 -1
- package/dist/esm/push/push.mjs +149 -221
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/pushConfig.mjs +14 -23
- package/dist/esm/pushConfig.mjs.map +1 -1
- package/dist/esm/pushLog.mjs +85 -109
- package/dist/esm/pushLog.mjs.map +1 -1
- package/dist/esm/reviewDoc.mjs +167 -264
- package/dist/esm/reviewDoc.mjs.map +1 -1
- package/dist/esm/test/index.mjs +47 -73
- package/dist/esm/test/index.mjs.map +1 -1
- package/dist/esm/test/listMissingTranslations.mjs +30 -41
- package/dist/esm/test/listMissingTranslations.mjs.map +1 -1
- package/dist/esm/translateDoc.mjs +114 -193
- package/dist/esm/translateDoc.mjs.map +1 -1
- package/dist/esm/utils/calculateChunks.mjs +83 -91
- package/dist/esm/utils/calculateChunks.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +28 -46
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/checkFileModifiedRange.mjs +73 -65
- package/dist/esm/utils/checkFileModifiedRange.mjs.map +1 -1
- package/dist/esm/utils/checkLastUpdateTime.mjs +15 -6
- package/dist/esm/utils/checkLastUpdateTime.mjs.map +1 -1
- package/dist/esm/utils/chunkInference.mjs +24 -24
- package/dist/esm/utils/chunkInference.mjs.map +1 -1
- package/dist/esm/utils/fixChunkStartEndChars.mjs +22 -18
- package/dist/esm/utils/fixChunkStartEndChars.mjs.map +1 -1
- package/dist/esm/utils/formatTimeDiff.mjs +16 -19
- package/dist/esm/utils/formatTimeDiff.mjs.map +1 -1
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs +11 -8
- package/dist/esm/utils/getIsFileUpdatedRecently.mjs.map +1 -1
- package/dist/esm/utils/getOutputFilePath.mjs +70 -62
- package/dist/esm/utils/getOutputFilePath.mjs.map +1 -1
- package/dist/esm/utils/getParentPackageJSON.mjs +16 -20
- package/dist/esm/utils/getParentPackageJSON.mjs.map +1 -1
- package/dist/esm/utils/listSpecialChars.mjs +48 -49
- package/dist/esm/utils/listSpecialChars.mjs.map +1 -1
- package/dist/esm/utils/mapChunksBetweenFiles.mjs +87 -107
- package/dist/esm/utils/mapChunksBetweenFiles.mjs.map +1 -1
- package/dist/esm/utils/reorderParagraphs.mjs +85 -93
- package/dist/esm/utils/reorderParagraphs.mjs.map +1 -1
- package/dist/esm/watch.mjs +17 -17
- package/dist/esm/watch.mjs.map +1 -1
- package/dist/types/IntlayerEventListener.d.ts +63 -59
- package/dist/types/IntlayerEventListener.d.ts.map +1 -1
- package/dist/types/build.d.ts +10 -7
- package/dist/types/build.d.ts.map +1 -1
- package/dist/types/cli.d.ts +13 -10
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/config.d.ts +7 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/editor.d.ts +6 -4
- package/dist/types/editor.d.ts.map +1 -1
- package/dist/types/fill/fill.d.ts +20 -14
- package/dist/types/fill/fill.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFillData.d.ts +10 -7
- package/dist/types/fill/formatAutoFillData.d.ts.map +1 -1
- package/dist/types/fill/formatAutoFilledFilePath.d.ts +6 -2
- package/dist/types/fill/formatAutoFilledFilePath.d.ts.map +1 -1
- package/dist/types/fill/formatFillData.d.ts +12 -0
- package/dist/types/fill/formatFillData.d.ts.map +1 -0
- package/dist/types/fill/groupLimiter.d.ts +15 -0
- package/dist/types/fill/groupLimiter.d.ts.map +1 -0
- package/dist/types/fill/index.d.ts +3 -3
- package/dist/types/fill/listTranslationsTasks.d.ts +15 -0
- package/dist/types/fill/listTranslationsTasks.d.ts.map +1 -0
- package/dist/types/fill/test-original-case.d.ts +1 -0
- package/dist/types/fill/translateDictionary.d.ts +19 -0
- package/dist/types/fill/translateDictionary.d.ts.map +1 -0
- package/dist/types/fill/writeAutoFill.d.ts +7 -0
- package/dist/types/fill/writeAutoFill.d.ts.map +1 -0
- package/dist/types/fill/writeFill.d.ts +7 -0
- package/dist/types/fill/writeFill.d.ts.map +1 -0
- package/dist/types/getTargetDictionary.d.ts +17 -13
- package/dist/types/getTargetDictionary.d.ts.map +1 -1
- package/dist/types/index.d.ts +15 -14
- package/dist/types/listContentDeclaration.d.ts +10 -7
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/liveSync.d.ts +8 -3
- package/dist/types/liveSync.d.ts.map +1 -1
- package/dist/types/pull.d.ts +9 -6
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/push/pullLog.d.ts +25 -21
- package/dist/types/push/pullLog.d.ts.map +1 -1
- package/dist/types/push/push.d.ts +13 -9
- package/dist/types/push/push.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts +7 -4
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/dist/types/pushLog.d.ts +23 -20
- package/dist/types/pushLog.d.ts.map +1 -1
- package/dist/types/reviewDoc.d.ts +34 -17
- package/dist/types/reviewDoc.d.ts.map +1 -1
- package/dist/types/test/index.d.ts +9 -5
- package/dist/types/test/index.d.ts.map +1 -1
- package/dist/types/test/listMissingTranslations.d.ts +14 -10
- package/dist/types/test/listMissingTranslations.d.ts.map +1 -1
- package/dist/types/translateDoc.d.ts +34 -17
- package/dist/types/translateDoc.d.ts.map +1 -1
- package/dist/types/utils/calculateChunks.d.ts +10 -7
- package/dist/types/utils/calculateChunks.d.ts.map +1 -1
- package/dist/types/utils/checkAccess.d.ts +8 -4
- package/dist/types/utils/checkAccess.d.ts.map +1 -1
- package/dist/types/utils/checkFileModifiedRange.d.ts +8 -6
- package/dist/types/utils/checkFileModifiedRange.d.ts.map +1 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts +4 -1
- package/dist/types/utils/checkLastUpdateTime.d.ts.map +1 -1
- package/dist/types/utils/chunkInference.d.ts +9 -6
- package/dist/types/utils/chunkInference.d.ts.map +1 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts +4 -1
- package/dist/types/utils/fixChunkStartEndChars.d.ts.map +1 -1
- package/dist/types/utils/formatTimeDiff.d.ts +4 -1
- package/dist/types/utils/formatTimeDiff.d.ts.map +1 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts +4 -1
- package/dist/types/utils/getIsFileUpdatedRecently.d.ts.map +1 -1
- package/dist/types/utils/getOutputFilePath.d.ts +7 -2
- package/dist/types/utils/getOutputFilePath.d.ts.map +1 -1
- package/dist/types/utils/getParentPackageJSON.d.ts +30 -28
- package/dist/types/utils/getParentPackageJSON.d.ts.map +1 -1
- package/dist/types/utils/listSpecialChars.d.ts +9 -7
- package/dist/types/utils/listSpecialChars.d.ts.map +1 -1
- package/dist/types/utils/mapChunksBetweenFiles.d.ts +10 -6
- package/dist/types/utils/mapChunksBetweenFiles.d.ts.map +1 -1
- package/dist/types/utils/reorderParagraphs.d.ts +4 -1
- package/dist/types/utils/reorderParagraphs.d.ts.map +1 -1
- package/dist/types/watch.d.ts +9 -6
- package/dist/types/watch.d.ts.map +1 -1
- package/package.json +42 -47
- package/LICENSE +0 -202
- package/dist/cjs/fill/autoFill.cjs +0 -105
- package/dist/cjs/fill/autoFill.cjs.map +0 -1
- package/dist/cjs/fill/index.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/utils/getChunk.cjs +0 -77
- package/dist/cjs/utils/getChunk.cjs.map +0 -1
- package/dist/cjs/utils/splitTextByLine.cjs +0 -35
- package/dist/cjs/utils/splitTextByLine.cjs.map +0 -1
- package/dist/esm/fill/autoFill.mjs +0 -92
- package/dist/esm/fill/autoFill.mjs.map +0 -1
- package/dist/esm/fill/index.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/prompts/REVIEW_PROMPT.md +0 -37
- package/dist/esm/prompts/TRANSLATE_PROMPT.md +0 -38
- package/dist/esm/utils/calculrateChunkTest.md +0 -9
- package/dist/esm/utils/getChunk.mjs +0 -53
- package/dist/esm/utils/getChunk.mjs.map +0 -1
- package/dist/esm/utils/splitTextByLine.mjs +0 -11
- package/dist/esm/utils/splitTextByLine.mjs.map +0 -1
- package/dist/types/fill/autoFill.d.ts +0 -4
- package/dist/types/fill/autoFill.d.ts.map +0 -1
- package/dist/types/fill/index.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/utils/getChunk.d.ts +0 -9
- package/dist/types/utils/getChunk.d.ts.map +0 -1
- package/dist/types/utils/splitTextByLine.d.ts +0 -2
- package/dist/types/utils/splitTextByLine.d.ts.map +0 -1
- /package/dist/{cjs → assets}/prompts/REVIEW_PROMPT.md +0 -0
- /package/dist/{cjs → assets}/prompts/TRANSLATE_PROMPT.md +0 -0
- /package/dist/{cjs/utils/calculrateChunkTest.md → assets/utils/_calculateChunkTest.md} +0 -0
package/dist/esm/test/index.mjs
CHANGED
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|