@intlayer/cli 7.5.10 → 7.5.12
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/ci.cjs +73 -0
- package/dist/cjs/ci.cjs.map +1 -0
- package/dist/cjs/cli.cjs +41 -6
- package/dist/cjs/cli.cjs.map +1 -1
- package/dist/cjs/editor.cjs +1 -1
- package/dist/cjs/index.cjs +4 -5
- package/dist/cjs/listContentDeclaration.cjs +6 -2
- package/dist/cjs/listContentDeclaration.cjs.map +1 -1
- package/dist/cjs/listProjects.cjs +28 -0
- package/dist/cjs/listProjects.cjs.map +1 -0
- package/dist/cjs/{reviewDoc.cjs → reviewDoc/reviewDoc.cjs} +17 -15
- package/dist/cjs/reviewDoc/reviewDoc.cjs.map +1 -0
- package/dist/cjs/{reviewDocBlockAware.cjs → reviewDoc/reviewDocBlockAware.cjs} +12 -8
- package/dist/cjs/reviewDoc/reviewDocBlockAware.cjs.map +1 -0
- package/dist/cjs/translateDoc/index.cjs +8 -0
- package/dist/cjs/translateDoc/translateDoc.cjs +74 -0
- package/dist/cjs/translateDoc/translateDoc.cjs.map +1 -0
- package/dist/cjs/translateDoc/translateFile.cjs +103 -0
- package/dist/cjs/translateDoc/translateFile.cjs.map +1 -0
- package/dist/cjs/translateDoc/types.cjs +0 -0
- package/dist/cjs/translateDoc/validation.cjs +49 -0
- package/dist/cjs/translateDoc/validation.cjs.map +1 -0
- package/dist/cjs/translation-alignment/planActions.cjs +2 -4
- package/dist/cjs/translation-alignment/planActions.cjs.map +1 -1
- package/dist/cjs/translation-alignment/segmentDocument.cjs +35 -101
- package/dist/cjs/translation-alignment/segmentDocument.cjs.map +1 -1
- package/dist/cjs/utils/checkAccess.cjs +2 -1
- package/dist/cjs/utils/checkAccess.cjs.map +1 -1
- package/dist/cjs/utils/setupAI.cjs +20 -11
- package/dist/cjs/utils/setupAI.cjs.map +1 -1
- package/dist/esm/auth/login.mjs +16 -16
- package/dist/esm/auth/login.mjs.map +1 -1
- package/dist/esm/ci.mjs +72 -0
- package/dist/esm/ci.mjs.map +1 -0
- package/dist/esm/cli.mjs +39 -4
- package/dist/esm/cli.mjs.map +1 -1
- package/dist/esm/editor.mjs +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/listContentDeclaration.mjs +6 -2
- package/dist/esm/listContentDeclaration.mjs.map +1 -1
- package/dist/esm/listProjects.mjs +27 -0
- package/dist/esm/listProjects.mjs.map +1 -0
- package/dist/esm/pull.mjs +6 -6
- package/dist/esm/pull.mjs.map +1 -1
- package/dist/esm/push/push.mjs +7 -7
- package/dist/esm/push/push.mjs.map +1 -1
- package/dist/esm/{reviewDoc.mjs → reviewDoc/reviewDoc.mjs} +14 -12
- package/dist/esm/reviewDoc/reviewDoc.mjs.map +1 -0
- package/dist/esm/{reviewDocBlockAware.mjs → reviewDoc/reviewDocBlockAware.mjs} +11 -7
- package/dist/esm/reviewDoc/reviewDocBlockAware.mjs.map +1 -0
- package/dist/esm/translateDoc/index.mjs +5 -0
- package/dist/esm/translateDoc/translateDoc.mjs +72 -0
- package/dist/esm/translateDoc/translateDoc.mjs.map +1 -0
- package/dist/esm/translateDoc/translateFile.mjs +102 -0
- package/dist/esm/translateDoc/translateFile.mjs.map +1 -0
- package/dist/esm/translateDoc/types.mjs +0 -0
- package/dist/esm/translateDoc/validation.mjs +47 -0
- package/dist/esm/translateDoc/validation.mjs.map +1 -0
- package/dist/esm/translation-alignment/planActions.mjs +2 -4
- package/dist/esm/translation-alignment/planActions.mjs.map +1 -1
- package/dist/esm/translation-alignment/segmentDocument.mjs +35 -101
- package/dist/esm/translation-alignment/segmentDocument.mjs.map +1 -1
- package/dist/esm/utils/checkAccess.mjs +2 -1
- package/dist/esm/utils/checkAccess.mjs.map +1 -1
- package/dist/esm/utils/setupAI.mjs +20 -11
- package/dist/esm/utils/setupAI.mjs.map +1 -1
- package/dist/types/ci.d.ts +5 -0
- package/dist/types/ci.d.ts.map +1 -0
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/listContentDeclaration.d.ts +2 -0
- package/dist/types/listContentDeclaration.d.ts.map +1 -1
- package/dist/types/listProjects.d.ts +11 -0
- package/dist/types/listProjects.d.ts.map +1 -0
- package/dist/types/pull.d.ts.map +1 -1
- package/dist/types/pushConfig.d.ts.map +1 -1
- package/dist/types/{reviewDoc.d.ts → reviewDoc/reviewDoc.d.ts} +1 -1
- package/dist/types/reviewDoc/reviewDoc.d.ts.map +1 -0
- package/dist/types/{reviewDocBlockAware.d.ts → reviewDoc/reviewDocBlockAware.d.ts} +2 -2
- package/dist/types/reviewDoc/reviewDocBlockAware.d.ts.map +1 -0
- package/dist/types/translateDoc/index.d.ts +5 -0
- package/dist/types/translateDoc/translateDoc.d.ts +21 -0
- package/dist/types/translateDoc/translateDoc.d.ts.map +1 -0
- package/dist/types/translateDoc/translateFile.d.ts +21 -0
- package/dist/types/translateDoc/translateFile.d.ts.map +1 -0
- package/dist/types/translateDoc/types.d.ts +47 -0
- package/dist/types/translateDoc/types.d.ts.map +1 -0
- package/dist/types/translateDoc/validation.d.ts +16 -0
- package/dist/types/translateDoc/validation.d.ts.map +1 -0
- package/dist/types/translation-alignment/planActions.d.ts +2 -2
- package/dist/types/translation-alignment/planActions.d.ts.map +1 -1
- package/dist/types/translation-alignment/rebuildDocument.d.ts.map +1 -1
- package/dist/types/translation-alignment/segmentDocument.d.ts.map +1 -1
- package/dist/types/utils/setupAI.d.ts.map +1 -1
- package/package.json +11 -10
- package/dist/cjs/reviewDoc.cjs.map +0 -1
- package/dist/cjs/reviewDocBlockAware.cjs.map +0 -1
- package/dist/cjs/translateDoc.cjs +0 -132
- package/dist/cjs/translateDoc.cjs.map +0 -1
- package/dist/esm/reviewDoc.mjs.map +0 -1
- package/dist/esm/reviewDocBlockAware.mjs.map +0 -1
- package/dist/esm/translateDoc.mjs +0 -129
- package/dist/esm/translateDoc.mjs.map +0 -1
- package/dist/types/reviewDoc.d.ts.map +0 -1
- package/dist/types/reviewDocBlockAware.d.ts.map +0 -1
- package/dist/types/translateDoc.d.ts +0 -47
- package/dist/types/translateDoc.d.ts.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AIClient } from "../utils/setupAI.js";
|
|
2
|
+
import { IntlayerConfig, Locale } from "@intlayer/types";
|
|
3
|
+
import { GetConfigurationOptions } from "@intlayer/config";
|
|
4
|
+
import { ListGitFilesOptions } from "@intlayer/chokidar";
|
|
5
|
+
import { AIConfig, AIOptions } from "@intlayer/ai";
|
|
6
|
+
|
|
7
|
+
//#region src/translateDoc/types.d.ts
|
|
8
|
+
type ErrorState = {
|
|
9
|
+
count: number;
|
|
10
|
+
maxErrors: number;
|
|
11
|
+
shouldStop: boolean;
|
|
12
|
+
};
|
|
13
|
+
type FlushStrategy = 'incremental' | 'end' | 'none';
|
|
14
|
+
type LimitFunction = (fn: () => Promise<any>, ...args: any[]) => Promise<any>;
|
|
15
|
+
type TranslateFileOptions = {
|
|
16
|
+
baseFilePath: string;
|
|
17
|
+
outputFilePath: string;
|
|
18
|
+
locale: Locale;
|
|
19
|
+
baseLocale: Locale;
|
|
20
|
+
configuration: IntlayerConfig;
|
|
21
|
+
errorState: ErrorState;
|
|
22
|
+
aiOptions?: AIOptions;
|
|
23
|
+
customInstructions?: string;
|
|
24
|
+
aiClient?: AIClient;
|
|
25
|
+
aiConfig?: AIConfig;
|
|
26
|
+
flushStrategy?: FlushStrategy;
|
|
27
|
+
onChunkReceive?: (chunk: string, index: number, total: number) => void;
|
|
28
|
+
limit?: LimitFunction;
|
|
29
|
+
};
|
|
30
|
+
type TranslateDocOptions = {
|
|
31
|
+
docPattern: string[];
|
|
32
|
+
locales: Locale[];
|
|
33
|
+
excludedGlobPattern: string[];
|
|
34
|
+
baseLocale: Locale;
|
|
35
|
+
aiOptions?: AIOptions;
|
|
36
|
+
nbSimultaneousFileProcessed?: number;
|
|
37
|
+
configOptions?: GetConfigurationOptions;
|
|
38
|
+
customInstructions?: string;
|
|
39
|
+
skipIfModifiedBefore?: number | string | Date;
|
|
40
|
+
skipIfModifiedAfter?: number | string | Date;
|
|
41
|
+
skipIfExists?: boolean;
|
|
42
|
+
gitOptions?: ListGitFilesOptions;
|
|
43
|
+
flushStrategy?: FlushStrategy;
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { ErrorState, FlushStrategy, LimitFunction, TranslateDocOptions, TranslateFileOptions };
|
|
47
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/translateDoc/types.ts"],"sourcesContent":[],"mappings":";;;;;;;KAMY,UAAA;;EAAA,SAAA,EAAA,MAAU;EAMV,UAAA,EAAA,OAAa;AAGzB,CAAA;AAKY,KARA,aAAA,GAQoB,aAAA,GAAA,KAAA,GAAA,MAAA;AAGtB,KARE,aAAA,GAQF,CAAA,EAAA,EAAA,GAAA,GAPE,OAOF,CAAA,GAAA,CAAA,EAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GALL,OAKK,CAAA,GAAA,CAAA;AACI,KAJF,oBAAA,GAIE;EACG,YAAA,EAAA,MAAA;EACH,cAAA,EAAA,MAAA;EACA,MAAA,EAJJ,MAII;EAED,UAAA,EALC,MAKD;EACA,aAAA,EALI,cAKJ;EACK,UAAA,EALJ,UAKI;EAER,SAAA,CAAA,EANI,SAMJ;EAAa,kBAAA,CAAA,EAAA,MAAA;EAGX,QAAA,CAAA,EAPC,QAOD;EAED,QAAA,CAAA,EARE,QAQF;EAEG,aAAA,CAAA,EATI,aASJ;EACA,cAAA,CAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,EAAA,KAAA,EAAA,MAAA,EAAA,GAAA,IAAA;EAEI,KAAA,CAAA,EAVR,aAUQ;CAEyB;AACD,KAV9B,mBAAA,GAU8B;EAE3B,UAAA,EAAA,MAAA,EAAA;EACG,OAAA,EAXP,MAWO,EAAA;EAAa,mBAAA,EAAA,MAAA,EAAA;cATjB;cACA;;kBAEI;;2CAEyB;0CACD;;eAE3B;kBACG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Logger } from "@intlayer/config";
|
|
2
|
+
|
|
3
|
+
//#region src/translateDoc/validation.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Validates that the translated content matches the structure of the original.
|
|
7
|
+
* Throws an error if a mismatch is found, triggering a retry.
|
|
8
|
+
*/
|
|
9
|
+
declare const validateTranslation: (original: string, translated: string, logger: Logger) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Clean common AI artifacts
|
|
12
|
+
*/
|
|
13
|
+
declare const sanitizeChunk: (translated: string, original: string) => string;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { sanitizeChunk, validateTranslation };
|
|
16
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","names":[],"sources":["../../../src/translateDoc/validation.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;AAoEA;cApEa,oEAGH;;;;cAiEG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AlignmentPair, AlignmentPlan
|
|
1
|
+
import { AlignmentPair, AlignmentPlan } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/translation-alignment/planActions.d.ts
|
|
4
|
-
declare const planAlignmentActions: (alignment: AlignmentPair[], changedEnglishBlockIndexes: Set<number
|
|
4
|
+
declare const planAlignmentActions: (alignment: AlignmentPair[], changedEnglishBlockIndexes: Set<number>) => AlignmentPlan;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { planAlignmentActions };
|
|
7
7
|
//# sourceMappingURL=planActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planActions.d.ts","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"planActions.d.ts","names":[],"sources":["../../../src/translation-alignment/planActions.ts"],"sourcesContent":[],"mappings":";;;cAEa,kCACA,6CACiB,gBAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rebuildDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;gBACI;EADJ,eAAA,EAAA,MAAe,GAAA,
|
|
1
|
+
{"version":3,"file":"rebuildDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/rebuildDocument.ts"],"sourcesContent":[],"mappings":";;;KAEY,eAAA;gBACI;EADJ,eAAA,EAAA,MAAe,GAAA,IAAA;EAMf,WAAA,EAAA,MAAY;CACP;AACD,KAFJ,YAAA,GAEI;EACR,aAAA,EAFS,kBAET,EAAA;EAAa,YAAA,EADL,kBACK,EAAA;EAGT,IAAA,EAHJ,aAGiB;AAQzB,CAAA;AAAyC,KAR7B,aAAA,GAQ6B;EAAA,gBAAA,EAPrB,eAOqB,EAAA;CAAA;;;;AAiCzC;AACQ,cAlCK,wBAkCL,EAAA,CAAA;EAAA,aAAA;EAAA,YAAA;EAAA;AAAA,CAAA,EA9BL,YA8BK,EAAA,GA9BU,aA8BV;;;;cADK,8BACL,6BACQ,wCACI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segmentDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"segmentDocument.d.ts","names":[],"sources":["../../../src/translation-alignment/segmentDocument.ts"],"sourcesContent":[],"mappings":";;;cAUa,mCAAkC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupAI.d.ts","names":[],"sources":["../../../src/utils/setupAI.ts"],"sourcesContent":[],"mappings":";;;;;KAUY,QAAA,UAAQ;KAEf,aAAA;aACQ;EAHD,QAAA,CAAA,EAIC,QAJO;EAEf,UAAA,EAAA,OAAa;EA0BL,
|
|
1
|
+
{"version":3,"file":"setupAI.d.ts","names":[],"sources":["../../../src/utils/setupAI.ts"],"sourcesContent":[],"mappings":";;;;;KAUY,QAAA,UAAQ;KAEf,aAAA;aACQ;EAHD,QAAA,CAAA,EAIC,QAJO;EAEf,UAAA,EAAA,OAAa;EA0BL,WAwEZ,EAAA,OAAA;CAvEgB;;;;;;cADJ,yBACI,4BACH,cACX,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/cli",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Provides uniform command-line interface scripts for Intlayer, used in packages like intlayer-cli and intlayer.",
|
|
6
6
|
"keywords": [
|
|
@@ -68,14 +68,15 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@clack/prompts": "^0.11.0",
|
|
71
|
-
"@intlayer/
|
|
72
|
-
"@intlayer/
|
|
73
|
-
"@intlayer/
|
|
74
|
-
"@intlayer/
|
|
75
|
-
"@intlayer/
|
|
76
|
-
"@intlayer/
|
|
77
|
-
"@intlayer/
|
|
78
|
-
"@intlayer/
|
|
71
|
+
"@intlayer/ai": "7.5.12",
|
|
72
|
+
"@intlayer/api": "7.5.12",
|
|
73
|
+
"@intlayer/chokidar": "7.5.12",
|
|
74
|
+
"@intlayer/config": "7.5.12",
|
|
75
|
+
"@intlayer/core": "7.5.12",
|
|
76
|
+
"@intlayer/dictionaries-entry": "7.5.12",
|
|
77
|
+
"@intlayer/remote-dictionaries-entry": "7.5.12",
|
|
78
|
+
"@intlayer/types": "7.5.12",
|
|
79
|
+
"@intlayer/unmerged-dictionaries-entry": "7.5.12",
|
|
79
80
|
"commander": "14.0.1",
|
|
80
81
|
"eventsource": "3.0.7",
|
|
81
82
|
"fast-glob": "3.3.3"
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"vitest": "4.0.16"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|
|
94
|
-
"@intlayer/ai": "7.5.
|
|
95
|
+
"@intlayer/ai": "7.5.12"
|
|
95
96
|
},
|
|
96
97
|
"peerDependenciesMeta": {
|
|
97
98
|
"@intlayer/ai": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDoc.cjs","names":["setupAI","docList: string[]","getOutputFilePath","ANSIColors","checkFileModifiedRange","changedLines: number[] | undefined","reviewFileBlockAware"],"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n type ListGitFilesOptions,\n listGitFiles,\n listGitLines,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { reviewFileBlockAware } from './reviewDocBlockAware';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\nimport { setupAI } from './utils/setupAI';\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n const aiResult = await setupAI(configuration, aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n let changedLines: number[] | undefined;\n // FIXED: Enable git optimization that was previously commented out\n if (gitOptions) {\n const gitChangedLines = await listGitLines(\n absoluteBaseFilePath,\n gitOptions\n );\n\n appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n changedLines = gitChangedLines;\n }\n\n await reviewFileBlockAware(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions,\n changedLines,\n aiClient,\n aiConfig\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,MAAa,YAAY,OAAO,EAC9B,YACA,SACA,qBACA,YACA,WACA,6BACA,eACA,oBACA,sBACA,qBACA,cACA,iBACsB;CACtB,MAAM,uDAAiC,cAAc;CACrD,MAAM,+CAAyB,cAAc;CAE7C,MAAM,WAAW,MAAMA,8BAAQ,eAAe,UAAU;AAExD,KAAI,CAAC,UAAU,YAAa;CAE5B,MAAM,EAAE,UAAU,aAAa;AAE/B,KAAI,+BAA+B,8BAA8B,IAAI;AACnE,YACE,kDAAkD,4BAA4B,+CAC/E;AACD,gCAA8B;;CAGhC,IAAIC,UAAoB,6BAAS,YAAY,EAC3C,QAAQ,qBACT,CAAC;AAEF,KAAI,YAAY;EACd,MAAM,kBAAkB,2CAAmB,WAAW;AAEtD,MAAI,gBAIF,WAAU,QAAQ,QAAQ,SACxB,gBAAgB,MAAM,gCAAiB,QAAQ,KAAK,EAAE,KAAK,KAAK,QAAQ,CACzE;;AAML,WAAU,uDAA+B,WAAW,GAAG;AACvD,WACE,kDAA4B,QAAQ,OAAO,CAAC,mDAA2B,QAAQ,CAAC,IACjF;AAED,WAAU,kDAA4B,QAAQ,OAAO,CAAC,SAAS;AAC/D,WAAU,QAAQ,KAAK,SAAS,yCAAiB,KAAK,CAAC,IAAI,CAAC;AAiE5D,2CA9DiB,QAAQ,SAAS,YAChC,QAAQ,KAAK,WAAW,YAAY;AAClC,YACE,sDAA8B,QAAQ,CAAC,2CAAmB,OAAO,GAClE;EAED,MAAM,2CAA4B,cAAc,QAAQ,SAAS,QAAQ;EACzE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,WACD;AAGD,MAAI,wCAA2B,eAAe,EAAE;GAC9C,MAAM,uCACJ,cAAc,QAAQ,SACtB,eACD;AACD,aACE,kCAAY,KAAKC,4BAAW,OAAO,CAAC,2CAAmB,aAAa,CAAC,4BACtE;AACD;;EAGF,MAAM,uBAAuBC,4DAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;EAGF,IAAIC;AAEJ,MAAI,YAAY;GACd,MAAM,kBAAkB,2CACtB,sBACA,WACD;AAED,aAAU,sBAAsB,gBAAgB,KAAK,KAAK,GAAG;AAC7D,kBAAe;;AAGjB,QAAMC,iDACJ,sBACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,SACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocBlockAware.cjs","names":["readAsset","ANSIColors","buildAlignmentPlan","mergeReviewedSegments","chunkInference","Locales","fixChunkStartEndChars"],"sources":["../../src/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from './translation-alignment/pipeline';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport type { AIClient } from './utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n * This approach:\n * 1. Segments both English and French documents into semantic blocks\n * 2. Aligns blocks using structure (special chars, numbers) and context\n * 3. Detects which blocks changed, were added, or deleted\n * 4. Only sends changed/new blocks to AI for translation\n * 5. Handles reordering automatically\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n) => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger(configuration);\n\n const englishText = await readFile(baseFilePath, 'utf-8');\n const frenchText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { englishBlocks, frenchBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n englishText,\n frenchText,\n changedLines,\n });\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: EN=${colorizeNumber(englishBlocks.length)}, FR=${colorizeNumber(frenchBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(plan.actions.filter((a) => a.kind === 'reuse').length)}, review=${colorizeNumber(plan.actions.filter((a) => a.kind === 'review').length)}, new=${colorizeNumber(plan.actions.filter((a) => a.kind === 'insert_new').length)}, delete=${colorizeNumber(plan.actions.filter((a) => a.kind === 'delete').length)}`\n );\n\n if (segmentsToReview.length === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(\n outputFilePath,\n mergeReviewedSegments(plan, frenchBlocks, new Map())\n );\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no changes needed).`\n );\n return;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Review segments that need AI translation\n const reviewedSegmentsMap = new Map<number, string>();\n\n for (const segment of segmentsToReview) {\n const segmentNumber = segmentsToReview.indexOf(segment) + 1;\n const englishBlock = segment.englishBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n englishBlock.content +\n `///chunksEnd///`;\n\n const getFrenchChunkPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.frenchBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getFrenchChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: englishBlock.content },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n const fixed = fixChunkStartEndChars(\n result?.fileContent,\n englishBlock.content\n );\n return fixed;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n }\n\n // Merge reviewed segments back into final document\n const finalFrenchOutput = mergeReviewedSegments(\n plan,\n frenchBlocks,\n reviewedSegmentsMap\n );\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, finalFrenchOutput);\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,uBAAuB,OAClC,cACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,aACG;CACH,MAAM,uDAAiC,cAAc;CACrD,MAAM,uDAAiC,cAAc;CAErD,MAAM,cAAc,qCAAe,cAAc,QAAQ;CACzD,MAAM,aAAa,qCAAe,gBAAgB,QAAQ,CAAC,YAAY,GAAG;CAE1E,MAAM,aAAaA,+BAAU,8BAA8B,QAAQ,CAChE,WAAW,kBAAkB,wCAAgB,QAAQ,MAAM,GAAG,CAC9D,WAAW,sBAAsB,wCAAgB,YAAY,MAAM,GAAG,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,IAAI,CACvE,QAAQ,0BAA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,QAAQ,QAAQ,GAAG;EAC1D,MAAM,eAAe,QAAQ;EAE7B,MAAM,kCACJ,WAAW,cAAc,MAAM,iBAAiB,OAAO,+DAAuC,YAAY,MAAM,CAAC,uCAEjH,aAAa,UACb;EAEF,MAAM,6BACJ,WAAW,cAAc,MAAM,iBAAiB,OAAO,4EAAoD,QAAQ,MAAM,CAAC,2BAEzH,QAAQ,mBAAmB,MAC5B;EAEF,MAAM,sBAAsB,yCAAmB,YAAY;GACzD,MAAM,SAAS,MAAMG,4CACnB;IACE;KAAE,MAAM;KAAU,SAAS;KAAY;IACvC;KAAE,MAAM;KAAU,SAAS,2BAA2B;KAAE;IACxD;KAAE,MAAM;KAAU,SAAS,sBAAsB;KAAE;IACnD;KACE,MAAM;KACN,SAAS,kFAA4D,cAAc,CAAC,2CAAqB,iBAAiB,OAAO,CAAC,oEAAgD,QAAQC,wBAAQ,QAAQ,CAAC,IAAI,OAAO;KACvN;IACD;KAAE,MAAM;KAAQ,SAAS,aAAa;KAAS;IAChD,EACD,WACA,eACA,UACA,SACD;AAED,qBACE,GAAG,8CAAwB,OAAO,UAAU,CAAC,4DAAsC,cAAc,CAAC,2CAAqB,iBAAiB,OAAO,GAChJ;AAMD,UAJcC,0DACZ,QAAQ,aACR,aAAa,QACd;IAED,EAAE;AAEJ,sBAAoB,IAAI,QAAQ,aAAa,oBAAoB;;CAInE,MAAM,oBAAoBH,oEACxB,MACA,cACA,oBACD;AAED,+CAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,4BAAc,gBAAgB,kBAAkB;AAEhD,mBACE,kCAAY,KAAKF,4BAAW,MAAM,CAAC,2CAAmB,eAAe,CAAC,gCACvE"}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_utils_setupAI = require('./utils/setupAI.cjs');
|
|
3
|
-
const require__utils_asset = require('./_virtual/_utils_asset.cjs');
|
|
4
|
-
const require_utils_chunkInference = require('./utils/chunkInference.cjs');
|
|
5
|
-
const require_utils_fixChunkStartEndChars = require('./utils/fixChunkStartEndChars.cjs');
|
|
6
|
-
const require_utils_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
|
|
7
|
-
const require_utils_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
|
|
8
|
-
const require_utils_calculateChunks = require('./utils/calculateChunks.cjs');
|
|
9
|
-
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
10
|
-
let _intlayer_config = require("@intlayer/config");
|
|
11
|
-
let node_path = require("node:path");
|
|
12
|
-
let node_fs = require("node:fs");
|
|
13
|
-
let node_fs_promises = require("node:fs/promises");
|
|
14
|
-
let fast_glob = require("fast-glob");
|
|
15
|
-
fast_glob = require_rolldown_runtime.__toESM(fast_glob);
|
|
16
|
-
|
|
17
|
-
//#region src/translateDoc.ts
|
|
18
|
-
/**
|
|
19
|
-
* Translate a single file for a given locale
|
|
20
|
-
*/
|
|
21
|
-
const translateFile = async (baseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions, aiClient, aiConfig) => {
|
|
22
|
-
try {
|
|
23
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(configuration, { config: { prefix: "" } });
|
|
24
|
-
const fileContent = await (0, node_fs_promises.readFile)(baseFilePath, "utf-8");
|
|
25
|
-
let fileResultContent = fileContent;
|
|
26
|
-
const basePrompt = require__utils_asset.readAsset("./prompts/TRANSLATE_PROMPT.md", "utf-8").replaceAll("{{localeName}}", `${(0, _intlayer_chokidar.formatLocale)(locale, false)}`).replaceAll("{{baseLocaleName}}", `${(0, _intlayer_chokidar.formatLocale)(baseLocale, false)}`).replace("{{applicationContext}}", aiOptions?.applicationContext ?? "-").replace("{{customInstructions}}", customInstructions ?? "-");
|
|
27
|
-
const filePrefix = [(0, _intlayer_config.colon)(`${_intlayer_config.ANSIColors.GREY_DARK}[${(0, _intlayer_chokidar.formatPath)(baseFilePath)}${_intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config.ANSIColors.RESET}`].join("");
|
|
28
|
-
const prefix = [(0, _intlayer_config.colon)(`${_intlayer_config.ANSIColors.GREY_DARK}[${(0, _intlayer_chokidar.formatPath)(baseFilePath)}${_intlayer_config.ANSIColors.GREY_DARK}][${(0, _intlayer_chokidar.formatLocale)(locale)}${_intlayer_config.ANSIColors.GREY_DARK}] `, { colSize: 40 }), `→ ${_intlayer_config.ANSIColors.RESET}`].join("");
|
|
29
|
-
const chunks = require_utils_calculateChunks.chunkText(fileContent);
|
|
30
|
-
appLogger(`${filePrefix}Base file splitted into ${(0, _intlayer_config.colorizeNumber)(chunks.length)} chunks`);
|
|
31
|
-
for await (const [i, chunk] of chunks.entries()) {
|
|
32
|
-
const isFirstChunk = i === 0;
|
|
33
|
-
const getPrevChunkPrompt = () => `**CHUNK ${i} of ${chunks.length}** that has been translated in ${(0, _intlayer_chokidar.formatLocale)(locale)}:\n///chunkStart///` + (0, _intlayer_chokidar.getChunk)(fileResultContent, chunks[i - 1]) + `///chunkEnd///`;
|
|
34
|
-
const getBaseChunkContextPrompt = () => `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${(0, _intlayer_chokidar.formatLocale)(baseLocale, false)} as reference.\n///chunksStart///` + (chunks[i - 1]?.content ?? "") + chunks[i].content + (chunks[i + 1]?.content ?? "") + `///chunksEnd///`;
|
|
35
|
-
const fileToTranslateCurrentChunk = chunk.content;
|
|
36
|
-
const chunkTranslation = await (0, _intlayer_config.retryManager)(async () => {
|
|
37
|
-
const result = await require_utils_chunkInference.chunkInference([
|
|
38
|
-
{
|
|
39
|
-
role: "system",
|
|
40
|
-
content: basePrompt
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
role: "system",
|
|
44
|
-
content: getBaseChunkContextPrompt()
|
|
45
|
-
},
|
|
46
|
-
...isFirstChunk ? [] : [{
|
|
47
|
-
role: "system",
|
|
48
|
-
content: getPrevChunkPrompt()
|
|
49
|
-
}],
|
|
50
|
-
{
|
|
51
|
-
role: "system",
|
|
52
|
-
content: `The next user message will be the **CHUNK ${(0, _intlayer_config.colorizeNumber)(i + 1)} of ${(0, _intlayer_config.colorizeNumber)(chunks.length)}** in ${(0, _intlayer_chokidar.formatLocale)(baseLocale, false)} to translate in ${(0, _intlayer_chokidar.formatLocale)(locale, false)}:`
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
role: "user",
|
|
56
|
-
content: fileToTranslateCurrentChunk
|
|
57
|
-
}
|
|
58
|
-
], aiOptions, configuration, aiClient, aiConfig);
|
|
59
|
-
appLogger([
|
|
60
|
-
`${prefix}`,
|
|
61
|
-
`${_intlayer_config.ANSIColors.GREY_DARK}[Chunk `,
|
|
62
|
-
(0, _intlayer_config.colorizeNumber)(i + 1),
|
|
63
|
-
`${_intlayer_config.ANSIColors.GREY_DARK} of `,
|
|
64
|
-
(0, _intlayer_config.colorizeNumber)(chunks.length),
|
|
65
|
-
`${_intlayer_config.ANSIColors.GREY_DARK}] →${_intlayer_config.ANSIColors.RESET} `,
|
|
66
|
-
`${(0, _intlayer_config.colorizeNumber)(result.tokenUsed)} tokens used`
|
|
67
|
-
].join(""));
|
|
68
|
-
return require_utils_fixChunkStartEndChars.fixChunkStartEndChars(result?.fileContent, fileToTranslateCurrentChunk);
|
|
69
|
-
})();
|
|
70
|
-
fileResultContent = fileResultContent.replace(fileToTranslateCurrentChunk, chunkTranslation);
|
|
71
|
-
}
|
|
72
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
73
|
-
(0, node_fs.writeFileSync)(outputFilePath, fileResultContent);
|
|
74
|
-
const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
|
|
75
|
-
appLogger(`${(0, _intlayer_config.colorize)("✔", _intlayer_config.ANSIColors.GREEN)} File ${(0, _intlayer_chokidar.formatPath)(relativePath)} created/updated successfully.`);
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error(error);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Main translate function: scans all .md files in "en/" (unless you specified DOC_LIST),
|
|
82
|
-
* then translates them to each locale in LOCALE_LIST.
|
|
83
|
-
*/
|
|
84
|
-
const translateDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions }) => {
|
|
85
|
-
const configuration = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
86
|
-
const appLogger = (0, _intlayer_config.getAppLogger)(configuration);
|
|
87
|
-
if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
|
|
88
|
-
appLogger(`Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`);
|
|
89
|
-
nbSimultaneousFileProcessed = 10;
|
|
90
|
-
}
|
|
91
|
-
let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
|
|
92
|
-
const aiResult = await require_utils_setupAI.setupAI(configuration, aiOptions);
|
|
93
|
-
if (!aiResult?.hasAIAccess) return;
|
|
94
|
-
const { aiClient, aiConfig } = aiResult;
|
|
95
|
-
if (gitOptions) {
|
|
96
|
-
const gitChangedFiles = await (0, _intlayer_chokidar.listGitFiles)(gitOptions);
|
|
97
|
-
if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
|
|
98
|
-
}
|
|
99
|
-
appLogger(`Base locale is ${(0, _intlayer_chokidar.formatLocale)(baseLocale)}`);
|
|
100
|
-
appLogger(`Translating ${(0, _intlayer_config.colorizeNumber)(locales.length)} locales: [ ${(0, _intlayer_chokidar.formatLocale)(locales)} ]`);
|
|
101
|
-
appLogger(`Translating ${(0, _intlayer_config.colorizeNumber)(docList.length)} files:`);
|
|
102
|
-
appLogger(docList.map((path) => ` - ${(0, _intlayer_chokidar.formatPath)(path)}\n`));
|
|
103
|
-
await (0, _intlayer_chokidar.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
|
|
104
|
-
appLogger(`Translating file: ${(0, _intlayer_chokidar.formatPath)(docPath)} to ${(0, _intlayer_chokidar.formatLocale)(locale)}`);
|
|
105
|
-
const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
|
|
106
|
-
const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
|
|
107
|
-
if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) {
|
|
108
|
-
const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
|
|
109
|
-
appLogger(`${(0, _intlayer_config.colorize)("⊘", _intlayer_config.ANSIColors.YELLOW)} File ${(0, _intlayer_chokidar.formatPath)(relativePath)} already exists, skipping.`);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (!(0, node_fs.existsSync)(outputFilePath)) {
|
|
113
|
-
appLogger(`File ${(0, _intlayer_chokidar.formatPath)((0, node_path.relative)(configuration.content.baseDir, outputFilePath))} does not exist, creating it...`);
|
|
114
|
-
(0, node_fs.mkdirSync)((0, node_path.dirname)(outputFilePath), { recursive: true });
|
|
115
|
-
(0, node_fs.writeFileSync)(outputFilePath, "");
|
|
116
|
-
}
|
|
117
|
-
const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
|
|
118
|
-
skipIfModifiedBefore,
|
|
119
|
-
skipIfModifiedAfter
|
|
120
|
-
});
|
|
121
|
-
if (fileModificationData.isSkipped) {
|
|
122
|
-
appLogger(fileModificationData.message);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
await translateFile(absoluteBaseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions, aiClient, aiConfig);
|
|
126
|
-
})), (task) => task(), nbSimultaneousFileProcessed ?? 3);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
//#endregion
|
|
130
|
-
exports.translateDoc = translateDoc;
|
|
131
|
-
exports.translateFile = translateFile;
|
|
132
|
-
//# sourceMappingURL=translateDoc.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translateDoc.cjs","names":["readAsset","ANSIColors","chunkText","chunkInference","fixChunkStartEndChars","docList: string[]","setupAI","getOutputFilePath","checkFileModifiedRange"],"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig, AIOptions } from '@intlayer/ai';\nimport {\n formatLocale,\n formatPath,\n getChunk,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport type { IntlayerConfig, Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\nimport { type AIClient, setupAI } from './utils/setupAI';\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n customInstructions?: string,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n const chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `File ${formatPath(relativePath)} does not exist, creating it...`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n configuration,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,gBAAgB,OAC3B,cACA,gBACA,QACA,YACA,eACA,WACA,oBACA,UACA,aACG;AACH,KAAI;EACF,MAAM,+CAAyB,eAAe,EAC5C,QAAQ,EACN,QAAQ,IACT,EACF,CAAC;EAGF,MAAM,cAAc,qCAAe,cAAc,QAAQ;EAEzD,IAAI,oBAAoB;EAGxB,MAAM,aAAaA,+BAAU,iCAAiC,QAAQ,CACnE,WAAW,kBAAkB,wCAAgB,QAAQ,MAAM,GAAG,CAC9D,WAAW,sBAAsB,wCAAgB,YAAY,MAAM,GAAG,CACtE,QAAQ,0BAA0B,WAAW,sBAAsB,IAAI,CACvE,QAAQ,0BAA0B,sBAAsB,IAAI;EAG/D,MAAM,aAAa,6BADI,GAAGC,4BAAW,UAAU,sCAAc,aAAa,GAAGA,4BAAW,UAAU,KAE1E,EAAE,SAAS,IAAI,CAAC,EACtC,KAAKA,4BAAW,QACjB,CAAC,KAAK,GAAG;EAGV,MAAM,SAAS,6BADI,GAAGA,4BAAW,UAAU,sCAAc,aAAa,GAAGA,4BAAW,UA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;AAClC,YACE,wDAAgC,QAAQ,CAAC,2CAAmB,OAAO,GACpE;EAED,MAAM,2CAA4B,cAAc,QAAQ,SAAS,QAAQ;EACzE,MAAM,iBAAiBC,kDACrB,sBACA,QACA,WACD;AAGD,MAAI,wCAA2B,eAAe,EAAE;GAC9C,MAAM,uCACJ,cAAc,QAAQ,SACtB,eACD;AACD,aACE,kCAAY,KAAKN,4BAAW,OAAO,CAAC,2CAAmB,aAAa,CAAC,4BACtE;AACD;;AAIF,MAAI,yBAAY,eAAe,EAAE;AAK/B,aACE,mEAJA,cAAc,QAAQ,SACtB,eACD,CAEiC,CAAC,iCAClC;AACD,iDAAkB,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,8BAAc,gBAAgB,GAAG;;EAGnC,MAAM,uBAAuBO,4DAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;AAGF,QAAM,cACJ,sBACA,gBACA,QACA,YACA,eACA,WACA,oBACA,UACA,SACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDoc.mjs","names":["docList: string[]","changedLines: number[] | undefined"],"sources":["../../src/reviewDoc.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { join, relative } from 'node:path';\nimport type { AIOptions } from '@intlayer/api'; // OAuth handled by API proxy\nimport {\n formatLocale,\n formatPath,\n type ListGitFilesOptions,\n listGitFiles,\n listGitLines,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n} from '@intlayer/config';\nimport type { Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { reviewFileBlockAware } from './reviewDocBlockAware';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\nimport { setupAI } from './utils/setupAI';\n\ntype ReviewDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main audit function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then audits them to each locale in LOCALE_LIST.\n */\nexport const reviewDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: ReviewDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n const aiResult = await setupAI(configuration, aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Reviewing ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Reviewing ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Reviewing file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n let changedLines: number[] | undefined;\n // FIXED: Enable git optimization that was previously commented out\n if (gitOptions) {\n const gitChangedLines = await listGitLines(\n absoluteBaseFilePath,\n gitOptions\n );\n\n appLogger(`Git changed lines: ${gitChangedLines.join(', ')}`);\n changedLines = gitChangedLines;\n }\n\n await reviewFileBlockAware(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n aiOptions,\n configOptions,\n customInstructions,\n changedLines,\n aiClient,\n aiConfig\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;AA6CA,MAAa,YAAY,OAAO,EAC9B,YACA,SACA,qBACA,YACA,WACA,6BACA,eACA,oBACA,sBACA,qBACA,cACA,iBACsB;CACtB,MAAM,gBAAgB,iBAAiB,cAAc;CACrD,MAAM,YAAY,aAAa,cAAc;CAE7C,MAAM,WAAW,MAAM,QAAQ,eAAe,UAAU;AAExD,KAAI,CAAC,UAAU,YA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D,kBAAe;;AAGjB,QAAM,qBACJ,sBACA,gBACA,QACA,YACA,WACA,eACA,oBACA,cACA,UACA,SACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocBlockAware.mjs","names":[],"sources":["../../src/reviewDocBlockAware.ts"],"sourcesContent":["import { mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig } from '@intlayer/ai';\nimport type { AIOptions } from '@intlayer/api';\nimport { formatLocale, formatPath } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport { getLocaleName } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport {\n buildAlignmentPlan,\n mergeReviewedSegments,\n} from './translation-alignment/pipeline';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport type { AIClient } from './utils/setupAI';\n\n/**\n * Review a file using block-aware alignment.\n * This approach:\n * 1. Segments both English and French documents into semantic blocks\n * 2. Aligns blocks using structure (special chars, numbers) and context\n * 3. Detects which blocks changed, were added, or deleted\n * 4. Only sends changed/new blocks to AI for translation\n * 5. Handles reordering automatically\n */\nexport const reviewFileBlockAware = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n aiOptions?: AIOptions,\n configOptions?: GetConfigurationOptions,\n customInstructions?: string,\n changedLines?: number[],\n aiClient?: AIClient,\n aiConfig?: AIConfig\n) => {\n const configuration = getConfiguration(configOptions);\n const applicationLogger = getAppLogger(configuration);\n\n const englishText = await readFile(baseFilePath, 'utf-8');\n const frenchText = await readFile(outputFilePath, 'utf-8').catch(() => '');\n\n const basePrompt = readAsset('./prompts/REVIEW_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // Build block-aware alignment and plan\n const { englishBlocks, frenchBlocks, plan, segmentsToReview } =\n buildAlignmentPlan({\n englishText,\n frenchText,\n changedLines,\n });\n\n applicationLogger(\n `${filePrefix}Block-aware alignment complete. Total blocks: EN=${colorizeNumber(englishBlocks.length)}, FR=${colorizeNumber(frenchBlocks.length)}`\n );\n applicationLogger(\n `${filePrefix}Actions: reuse=${colorizeNumber(plan.actions.filter((a) => a.kind === 'reuse').length)}, review=${colorizeNumber(plan.actions.filter((a) => a.kind === 'review').length)}, new=${colorizeNumber(plan.actions.filter((a) => a.kind === 'insert_new').length)}, delete=${colorizeNumber(plan.actions.filter((a) => a.kind === 'delete').length)}`\n );\n\n if (segmentsToReview.length === 0) {\n applicationLogger(\n `${filePrefix}No segments need review, reusing existing translation`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(\n outputFilePath,\n mergeReviewedSegments(plan, frenchBlocks, new Map())\n );\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} updated successfully (no changes needed).`\n );\n return;\n }\n\n applicationLogger(\n `${filePrefix}Segments to review: ${colorizeNumber(segmentsToReview.length)}`\n );\n\n // Review segments that need AI translation\n const reviewedSegmentsMap = new Map<number, string>();\n\n for (const segment of segmentsToReview) {\n const segmentNumber = segmentsToReview.indexOf(segment) + 1;\n const englishBlock = segment.englishBlock;\n\n const getBaseChunkContextPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the base block in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///\\n` +\n englishBlock.content +\n `///chunksEnd///`;\n\n const getFrenchChunkPrompt = () =>\n `**BLOCK ${segmentNumber} of ${segmentsToReview.length}** is the current block to review in ${formatLocale(locale, false)}.\\n` +\n `///chunksStart///\\n` +\n (segment.frenchBlockText ?? '') +\n `///chunksEnd///`;\n\n const reviewedChunkResult = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n { role: 'system', content: getBaseChunkContextPrompt() },\n { role: 'system', content: getFrenchChunkPrompt() },\n {\n role: 'system',\n content: `The next user message will be the **BLOCK ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}** that should be translated in ${getLocaleName(locale, Locales.ENGLISH)} (${locale}).`,\n },\n { role: 'user', content: englishBlock.content },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n applicationLogger(\n `${prefix}${colorizeNumber(result.tokenUsed)} tokens used - Block ${colorizeNumber(segmentNumber)} of ${colorizeNumber(segmentsToReview.length)}`\n );\n\n const fixed = fixChunkStartEndChars(\n result?.fileContent,\n englishBlock.content\n );\n return fixed;\n })();\n\n reviewedSegmentsMap.set(segment.actionIndex, reviewedChunkResult);\n }\n\n // Merge reviewed segments back into final document\n const finalFrenchOutput = mergeReviewedSegments(\n plan,\n frenchBlocks,\n reviewedSegmentsMap\n );\n\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, finalFrenchOutput);\n\n applicationLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(outputFilePath)} created/updated successfully.`\n );\n};\n"],"mappings":";;;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AAS,eAAe,OAAO,UAAU,CAAC,uBAAuB,eAAe,cAAc,CAAC,MAAM,eAAe,iBAAiB,OAAO,GAChJ;AAMD,UAJc,sBACZ,QAAQ,aACR,aAAa,QACd;IAED,EAAE;AAEJ,sBAAoB,IAAI,QAAQ,aAAa,oBAAoB;;CAInE,MAAM,oBAAoB,sBACxB,MACA,cACA,oBACD;AAED,WAAU,QAAQ,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,eAAc,gBAAgB,kBAAkB;AAEhD,mBACE,GAAG,SAAS,KAAK,WAAW,MAAM,CAAC,QAAQ,WAAW,eAAe,CAAC,gCACvE"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { setupAI } from "./utils/setupAI.mjs";
|
|
2
|
-
import { readAsset } from "./_virtual/_utils_asset.mjs";
|
|
3
|
-
import { chunkInference } from "./utils/chunkInference.mjs";
|
|
4
|
-
import { fixChunkStartEndChars } from "./utils/fixChunkStartEndChars.mjs";
|
|
5
|
-
import { checkFileModifiedRange } from "./utils/checkFileModifiedRange.mjs";
|
|
6
|
-
import { getOutputFilePath } from "./utils/getOutputFilePath.mjs";
|
|
7
|
-
import { chunkText } from "./utils/calculateChunks.mjs";
|
|
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, aiClient, aiConfig) => {
|
|
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, aiClient, aiConfig);
|
|
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
|
-
}
|
|
77
|
-
};
|
|
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, skipIfExists, 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
|
-
const aiResult = await setupAI(configuration, aiOptions);
|
|
91
|
-
if (!aiResult?.hasAIAccess) return;
|
|
92
|
-
const { aiClient, aiConfig } = aiResult;
|
|
93
|
-
if (gitOptions) {
|
|
94
|
-
const gitChangedFiles = await listGitFiles(gitOptions);
|
|
95
|
-
if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile));
|
|
96
|
-
}
|
|
97
|
-
appLogger(`Base locale is ${formatLocale(baseLocale)}`);
|
|
98
|
-
appLogger(`Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`);
|
|
99
|
-
appLogger(`Translating ${colorizeNumber(docList.length)} files:`);
|
|
100
|
-
appLogger(docList.map((path) => ` - ${formatPath(path)}\n`));
|
|
101
|
-
await parallelize(docList.flatMap((docPath) => locales.map((locale) => async () => {
|
|
102
|
-
appLogger(`Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`);
|
|
103
|
-
const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);
|
|
104
|
-
const outputFilePath = getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
|
|
105
|
-
if (skipIfExists && existsSync(outputFilePath)) {
|
|
106
|
-
const relativePath = relative(configuration.content.baseDir, outputFilePath);
|
|
107
|
-
appLogger(`${colorize("⊘", ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`);
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (!existsSync(outputFilePath)) {
|
|
111
|
-
appLogger(`File ${formatPath(relative(configuration.content.baseDir, outputFilePath))} does not exist, creating it...`);
|
|
112
|
-
mkdirSync(dirname(outputFilePath), { recursive: true });
|
|
113
|
-
writeFileSync(outputFilePath, "");
|
|
114
|
-
}
|
|
115
|
-
const fileModificationData = checkFileModifiedRange(outputFilePath, {
|
|
116
|
-
skipIfModifiedBefore,
|
|
117
|
-
skipIfModifiedAfter
|
|
118
|
-
});
|
|
119
|
-
if (fileModificationData.isSkipped) {
|
|
120
|
-
appLogger(fileModificationData.message);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
await translateFile(absoluteBaseFilePath, outputFilePath, locale, baseLocale, configuration, aiOptions, customInstructions, aiClient, aiConfig);
|
|
124
|
-
})), (task) => task(), nbSimultaneousFileProcessed ?? 3);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
export { translateDoc, translateFile };
|
|
129
|
-
//# sourceMappingURL=translateDoc.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translateDoc.mjs","names":["docList: string[]"],"sources":["../../src/translateDoc.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { readAsset } from 'utils:asset';\nimport type { AIConfig, AIOptions } from '@intlayer/ai';\nimport {\n formatLocale,\n formatPath,\n getChunk,\n type ListGitFilesOptions,\n listGitFiles,\n parallelize,\n} from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colon,\n colorize,\n colorizeNumber,\n type GetConfigurationOptions,\n getAppLogger,\n getConfiguration,\n retryManager,\n} from '@intlayer/config';\nimport type { IntlayerConfig, Locale } from '@intlayer/types';\nimport fg from 'fast-glob';\nimport { chunkText } from './utils/calculateChunks';\nimport { checkFileModifiedRange } from './utils/checkFileModifiedRange';\nimport { chunkInference } from './utils/chunkInference';\nimport { fixChunkStartEndChars } from './utils/fixChunkStartEndChars';\nimport { getOutputFilePath } from './utils/getOutputFilePath';\nimport { type AIClient, setupAI } from './utils/setupAI';\n\n/**\n * Translate a single file for a given locale\n */\nexport const translateFile = async (\n baseFilePath: string,\n outputFilePath: string,\n locale: Locale,\n baseLocale: Locale,\n configuration: IntlayerConfig,\n aiOptions?: AIOptions,\n customInstructions?: string,\n aiClient?: AIClient,\n aiConfig?: AIConfig\n) => {\n try {\n const appLogger = getAppLogger(configuration, {\n config: {\n prefix: '',\n },\n });\n\n // Determine the target locale file path\n const fileContent = await readFile(baseFilePath, 'utf-8');\n\n let fileResultContent = fileContent;\n\n // Prepare the base prompt for ChatGPT\n const basePrompt = readAsset('./prompts/TRANSLATE_PROMPT.md', 'utf-8')\n .replaceAll('{{localeName}}', `${formatLocale(locale, false)}`)\n .replaceAll('{{baseLocaleName}}', `${formatLocale(baseLocale, false)}`)\n .replace('{{applicationContext}}', aiOptions?.applicationContext ?? '-')\n .replace('{{customInstructions}}', customInstructions ?? '-');\n\n const filePrefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}] `;\n const filePrefix = [\n colon(filePrefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n const prefixText = `${ANSIColors.GREY_DARK}[${formatPath(baseFilePath)}${ANSIColors.GREY_DARK}][${formatLocale(locale)}${ANSIColors.GREY_DARK}] `;\n const prefix = [\n colon(prefixText, { colSize: 40 }),\n `→ ${ANSIColors.RESET}`,\n ].join('');\n\n // 1. Chunk the file by number of lines instead of characters\n const chunks = chunkText(fileContent);\n appLogger(\n `${filePrefix}Base file splitted into ${colorizeNumber(chunks.length)} chunks`\n );\n\n for await (const [i, chunk] of chunks.entries()) {\n const isFirstChunk = i === 0;\n\n // Build the chunk-specific prompt\n const getPrevChunkPrompt = () =>\n `**CHUNK ${i} of ${chunks.length}** that has been translated in ${formatLocale(locale)}:\\n` +\n `///chunkStart///` +\n getChunk(fileResultContent, chunks[i - 1]) +\n `///chunkEnd///`;\n\n const getBaseChunkContextPrompt = () =>\n `**CHUNK ${i + 1} to ${Math.min(i + 3, chunks.length)} of ${chunks.length}** is the base chunk in ${formatLocale(baseLocale, false)} as reference.\\n` +\n `///chunksStart///` +\n (chunks[i - 1]?.content ?? '') +\n chunks[i].content +\n (chunks[i + 1]?.content ?? '') +\n `///chunksEnd///`;\n\n const fileToTranslateCurrentChunk = chunk.content;\n\n // Make the actual translation call\n const chunkTranslation = await retryManager(async () => {\n const result = await chunkInference(\n [\n { role: 'system', content: basePrompt },\n\n { role: 'system', content: getBaseChunkContextPrompt() },\n ...(isFirstChunk\n ? []\n : [{ role: 'system', content: getPrevChunkPrompt() } as const]),\n {\n role: 'system',\n content: `The next user message will be the **CHUNK ${colorizeNumber(i + 1)} of ${colorizeNumber(chunks.length)}** in ${formatLocale(baseLocale, false)} to translate in ${formatLocale(locale, false)}:`,\n },\n { role: 'user', content: fileToTranslateCurrentChunk },\n ],\n aiOptions,\n configuration,\n aiClient,\n aiConfig\n );\n\n appLogger(\n [\n `${prefix}`,\n `${ANSIColors.GREY_DARK}[Chunk `,\n colorizeNumber(i + 1),\n `${ANSIColors.GREY_DARK} of `,\n colorizeNumber(chunks.length),\n `${ANSIColors.GREY_DARK}] →${ANSIColors.RESET} `,\n `${colorizeNumber(result.tokenUsed)} tokens used`,\n ].join('')\n );\n\n const fixedTranslatedChunkResult = fixChunkStartEndChars(\n result?.fileContent,\n fileToTranslateCurrentChunk\n );\n\n return fixedTranslatedChunkResult;\n })();\n\n // Replace the chunk in the file content\n fileResultContent = fileResultContent.replace(\n fileToTranslateCurrentChunk,\n chunkTranslation\n );\n }\n\n // 4. Write the final translation to the appropriate file path\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, fileResultContent);\n\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n\n appLogger(\n `${colorize('✔', ANSIColors.GREEN)} File ${formatPath(relativePath)} created/updated successfully.`\n );\n } catch (error) {\n console.error(error);\n }\n};\n\ntype TranslateDocOptions = {\n docPattern: string[];\n locales: Locale[];\n excludedGlobPattern: string[];\n baseLocale: Locale;\n aiOptions?: AIOptions;\n nbSimultaneousFileProcessed?: number;\n configOptions?: GetConfigurationOptions;\n customInstructions?: string;\n skipIfModifiedBefore?: number | string | Date;\n skipIfModifiedAfter?: number | string | Date;\n skipIfExists?: boolean;\n gitOptions?: ListGitFilesOptions;\n};\n\n/**\n * Main translate function: scans all .md files in \"en/\" (unless you specified DOC_LIST),\n * then translates them to each locale in LOCALE_LIST.\n */\nexport const translateDoc = async ({\n docPattern,\n locales,\n excludedGlobPattern,\n baseLocale,\n aiOptions,\n nbSimultaneousFileProcessed,\n configOptions,\n customInstructions,\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n skipIfExists,\n gitOptions,\n}: TranslateDocOptions) => {\n const configuration = getConfiguration(configOptions);\n const appLogger = getAppLogger(configuration);\n\n if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {\n appLogger(\n `Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`\n );\n nbSimultaneousFileProcessed = 10; // Limit the number of simultaneous file processed to 10\n }\n\n let docList: string[] = await fg(docPattern, {\n ignore: excludedGlobPattern,\n });\n\n const aiResult = await setupAI(configuration, aiOptions);\n\n if (!aiResult?.hasAIAccess) return;\n\n const { aiClient, aiConfig } = aiResult;\n\n if (gitOptions) {\n const gitChangedFiles = await listGitFiles(gitOptions);\n\n if (gitChangedFiles) {\n // Convert dictionary file paths to be relative to git root for comparison\n\n // Filter dictionaries based on git changed files\n docList = docList.filter((path) =>\n gitChangedFiles.some((gitFile) => join(process.cwd(), path) === gitFile)\n );\n }\n }\n\n // OAuth handled by API proxy internally\n\n appLogger(`Base locale is ${formatLocale(baseLocale)}`);\n appLogger(\n `Translating ${colorizeNumber(locales.length)} locales: [ ${formatLocale(locales)} ]`\n );\n\n appLogger(`Translating ${colorizeNumber(docList.length)} files:`);\n appLogger(docList.map((path) => ` - ${formatPath(path)}\\n`));\n\n // Create all tasks to be processed\n const allTasks = docList.flatMap((docPath) =>\n locales.map((locale) => async () => {\n appLogger(\n `Translating file: ${formatPath(docPath)} to ${formatLocale(locale)}`\n );\n\n const absoluteBaseFilePath = join(configuration.content.baseDir, docPath);\n const outputFilePath = getOutputFilePath(\n absoluteBaseFilePath,\n locale,\n baseLocale\n );\n\n // Skip if file exists and skipIfExists option is enabled\n if (skipIfExists && existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `${colorize('⊘', ANSIColors.YELLOW)} File ${formatPath(relativePath)} already exists, skipping.`\n );\n return;\n }\n\n // check if the file exist, otherwise create it\n if (!existsSync(outputFilePath)) {\n const relativePath = relative(\n configuration.content.baseDir,\n outputFilePath\n );\n appLogger(\n `File ${formatPath(relativePath)} does not exist, creating it...`\n );\n mkdirSync(dirname(outputFilePath), { recursive: true });\n writeFileSync(outputFilePath, '');\n }\n\n const fileModificationData = checkFileModifiedRange(outputFilePath, {\n skipIfModifiedBefore,\n skipIfModifiedAfter,\n });\n\n if (fileModificationData.isSkipped) {\n appLogger(fileModificationData.message);\n return;\n }\n\n await translateFile(\n absoluteBaseFilePath,\n outputFilePath,\n locale as Locale,\n baseLocale,\n configuration,\n aiOptions,\n customInstructions,\n aiClient,\n aiConfig\n );\n })\n );\n\n await parallelize(\n allTasks,\n (task) => task(),\n nbSimultaneousFileProcessed ?? 3\n );\n};\n"],"mappings":";;;;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D,CAEiC,CAAC,iCAClC;AACD,aAAU,QAAQ,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AACvD,iBAAc,gBAAgB,GAAG;;EAGnC,MAAM,uBAAuB,uBAAuB,gBAAgB;GAClE;GACA;GACD,CAAC;AAEF,MAAI,qBAAqB,WAAW;AAClC,aAAU,qBAAqB,QAAQ;AACvC;;AAGF,QAAM,cACJ,sBACA,gBACA,QACA,YACA,eACA,WACA,oBACA,UACA,SACD;GACD,CACH,GAIE,SAAS,MAAM,EAChB,+BAA+B,EAChC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDoc.d.ts","names":[],"sources":["../../src/reviewDoc.ts"],"sourcesContent":[],"mappings":";;;;;;KA0BK,gBAAA;;EAAA,OAAA,EAEM,MAFN,EAAA;EAEM,mBAAA,EAAA,MAAA,EAAA;EAEG,UAAA,EAAA,MAAA;EACA,SAAA,CAAA,EAAA,SAAA;EAEI,2BAAA,CAAA,EAAA,MAAA;EAEyB,aAAA,CAAA,EAFzB,uBAEyB;EACD,kBAAA,CAAA,EAAA,MAAA;EAE3B,oBAAA,CAAA,EAAA,MAAA,GAAA,MAAA,GAH4B,IAG5B;EAAmB,mBAAA,CAAA,EAAA,MAAA,GAAA,MAAA,GAFQ,IAER;EAOrB,YA6HZ,CAAA,EAAA,OAAA;EA7H+B,UAAA,CAAA,EAPjB,mBAOiB;CAAA;;;;;AAAA,cAAnB,SAAmB,EAAA,CAAA;EAAA,UAAA;EAAA,OAAA;EAAA,mBAAA;EAAA,UAAA;EAAA,SAAA;EAAA,2BAAA;EAAA,aAAA;EAAA,kBAAA;EAAA,oBAAA;EAAA,mBAAA;EAAA,YAAA;EAAA;AAAA,CAAA,EAa7B,gBAb6B,EAAA,GAab,OAba,CAAA,IAAA,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reviewDocBlockAware.d.ts","names":[],"sources":["../../src/reviewDocBlockAware.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAoCA;;;;;;;AAUqB,cAVR,oBAUQ,EAAA,CAAA,YAAA,EAAA,MAAA,EAAA,cAAA,EAAA,MAAA,EAAA,MAAA,EAPX,MAOW,EAAA,UAAA,EANP,MAMO,EAAA,SAAA,CAAA,EALP,SAKO,EAAA,aAAA,CAAA,EAJH,uBAIG,EAAA,kBAAA,CAAA,EAAA,MAAA,EAAA,YAAA,CAAA,EAAA,MAAA,EAAA,EAAA,QAAA,CAAA,EADR,QACQ,EAAA,QAAA,CAAA,EAAR,QAAQ,EAAA,GAAA,OAAA,CAAA,IAAA,CAAA"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { AIClient } from "./utils/setupAI.js";
|
|
2
|
-
import { IntlayerConfig, Locale } from "@intlayer/types";
|
|
3
|
-
import { GetConfigurationOptions } from "@intlayer/config";
|
|
4
|
-
import { ListGitFilesOptions } from "@intlayer/chokidar";
|
|
5
|
-
import { AIConfig, AIOptions } from "@intlayer/ai";
|
|
6
|
-
|
|
7
|
-
//#region src/translateDoc.d.ts
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Translate a single file for a given locale
|
|
11
|
-
*/
|
|
12
|
-
declare const translateFile: (baseFilePath: string, outputFilePath: string, locale: Locale, baseLocale: Locale, configuration: IntlayerConfig, aiOptions?: AIOptions, customInstructions?: string, aiClient?: AIClient, aiConfig?: AIConfig) => Promise<void>;
|
|
13
|
-
type TranslateDocOptions = {
|
|
14
|
-
docPattern: string[];
|
|
15
|
-
locales: Locale[];
|
|
16
|
-
excludedGlobPattern: string[];
|
|
17
|
-
baseLocale: Locale;
|
|
18
|
-
aiOptions?: AIOptions;
|
|
19
|
-
nbSimultaneousFileProcessed?: number;
|
|
20
|
-
configOptions?: GetConfigurationOptions;
|
|
21
|
-
customInstructions?: string;
|
|
22
|
-
skipIfModifiedBefore?: number | string | Date;
|
|
23
|
-
skipIfModifiedAfter?: number | string | Date;
|
|
24
|
-
skipIfExists?: boolean;
|
|
25
|
-
gitOptions?: ListGitFilesOptions;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Main translate function: scans all .md files in "en/" (unless you specified DOC_LIST),
|
|
29
|
-
* then translates them to each locale in LOCALE_LIST.
|
|
30
|
-
*/
|
|
31
|
-
declare const translateDoc: ({
|
|
32
|
-
docPattern,
|
|
33
|
-
locales,
|
|
34
|
-
excludedGlobPattern,
|
|
35
|
-
baseLocale,
|
|
36
|
-
aiOptions,
|
|
37
|
-
nbSimultaneousFileProcessed,
|
|
38
|
-
configOptions,
|
|
39
|
-
customInstructions,
|
|
40
|
-
skipIfModifiedBefore,
|
|
41
|
-
skipIfModifiedAfter,
|
|
42
|
-
skipIfExists,
|
|
43
|
-
gitOptions
|
|
44
|
-
}: TranslateDocOptions) => Promise<void>;
|
|
45
|
-
//#endregion
|
|
46
|
-
export { translateDoc, translateFile };
|
|
47
|
-
//# sourceMappingURL=translateDoc.d.ts.map
|