@babelize/engine 0.0.0-stage โ 0.1.2
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/LICENSE +202 -0
- package/dist/BabelizeEngine.d.ts +12 -0
- package/dist/BabelizeEngine.js +47 -0
- package/dist/analysis/analyze.d.ts +106 -0
- package/dist/analysis/analyze.js +323 -0
- package/dist/config/env.d.ts +9 -0
- package/dist/config/env.js +16 -0
- package/dist/config.d.ts +74 -0
- package/dist/config.js +47 -0
- package/dist/detection/stack.d.ts +42 -0
- package/dist/detection/stack.js +277 -0
- package/dist/django/catalog.d.ts +92 -0
- package/dist/django/catalog.js +677 -0
- package/dist/django/extract.d.ts +20 -0
- package/dist/django/extract.js +79 -0
- package/dist/django/inject-file.d.ts +6 -0
- package/dist/django/inject-file.js +52 -0
- package/dist/django/inject.d.ts +11 -0
- package/dist/django/inject.js +205 -0
- package/dist/django/keys.d.ts +21 -0
- package/dist/django/keys.js +63 -0
- package/dist/django/locale-names.d.ts +13 -0
- package/dist/django/locale-names.js +60 -0
- package/dist/django/mo-file.d.ts +6 -0
- package/dist/django/mo-file.js +60 -0
- package/dist/django/plural-forms.d.ts +34 -0
- package/dist/django/plural-forms.js +216 -0
- package/dist/django/po-file.d.ts +38 -0
- package/dist/django/po-file.js +273 -0
- package/dist/django/python-extract.d.ts +34 -0
- package/dist/django/python-extract.js +619 -0
- package/dist/django/python-lexer.d.ts +65 -0
- package/dist/django/python-lexer.js +398 -0
- package/dist/django/template-extract.d.ts +32 -0
- package/dist/django/template-extract.js +680 -0
- package/dist/django/types.d.ts +49 -0
- package/dist/django/types.js +15 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +140 -0
- package/dist/injection/InjectionStrategy.d.ts +62 -0
- package/dist/injection/InjectionStrategy.js +2 -0
- package/dist/injection/StrategyFactory.d.ts +4 -0
- package/dist/injection/StrategyFactory.js +29 -0
- package/dist/injection/html/html-injector.d.ts +11 -0
- package/dist/injection/html/html-injector.js +173 -0
- package/dist/injection/strategies/NextIntlStrategy.d.ts +25 -0
- package/dist/injection/strategies/NextIntlStrategy.js +141 -0
- package/dist/injection/strategies/ReactI18nextStrategy.d.ts +19 -0
- package/dist/injection/strategies/ReactI18nextStrategy.js +116 -0
- package/dist/injection/strategies/VanillaStrategy.d.ts +11 -0
- package/dist/injection/strategies/VanillaStrategy.js +73 -0
- package/dist/injection/strategies/VueI18nStrategy.d.ts +11 -0
- package/dist/injection/strategies/VueI18nStrategy.js +84 -0
- package/dist/local/formatter.d.ts +26 -0
- package/dist/local/formatter.js +105 -0
- package/dist/local/git.d.ts +23 -0
- package/dist/local/git.js +136 -0
- package/dist/local/hosted-provider.d.ts +68 -0
- package/dist/local/hosted-provider.js +215 -0
- package/dist/local/index.d.ts +23 -0
- package/dist/local/index.js +75 -0
- package/dist/local/provider.d.ts +56 -0
- package/dist/local/provider.js +119 -0
- package/dist/local/pseudo-provider.d.ts +18 -0
- package/dist/local/pseudo-provider.js +208 -0
- package/dist/local/report.d.ts +177 -0
- package/dist/local/report.js +186 -0
- package/dist/local/translate-core.d.ts +218 -0
- package/dist/local/translate-core.js +499 -0
- package/dist/local/translate-messages.d.ts +49 -0
- package/dist/local/translate-messages.js +89 -0
- package/dist/local/workspace-copy.d.ts +91 -0
- package/dist/local/workspace-copy.js +355 -0
- package/dist/modules/extractor/extract.d.ts +20 -0
- package/dist/modules/extractor/extract.js +709 -0
- package/dist/modules/extractor/index.d.ts +2 -0
- package/dist/modules/extractor/index.js +63 -0
- package/dist/modules/finalization/django-finalize.d.ts +28 -0
- package/dist/modules/finalization/django-finalize.js +412 -0
- package/dist/modules/finalization/finalize.d.ts +38 -0
- package/dist/modules/finalization/finalize.js +745 -0
- package/dist/modules/finalization/index.d.ts +1 -0
- package/dist/modules/finalization/index.js +5 -0
- package/dist/modules/finalization/nextjs-finalize.d.ts +40 -0
- package/dist/modules/finalization/nextjs-finalize.js +328 -0
- package/dist/modules/finalization/static-runtime.d.ts +9 -0
- package/dist/modules/finalization/static-runtime.js +261 -0
- package/dist/modules/finalization/writes.d.ts +29 -0
- package/dist/modules/finalization/writes.js +78 -0
- package/dist/modules/format-injection/index.d.ts +19 -0
- package/dist/modules/format-injection/index.js +273 -0
- package/dist/modules/format-injection/inject-formats.d.ts +31 -0
- package/dist/modules/format-injection/inject-formats.js +208 -0
- package/dist/modules/glossary/index.d.ts +2 -0
- package/dist/modules/glossary/index.js +16 -0
- package/dist/modules/glossary/rules.d.ts +81 -0
- package/dist/modules/glossary/rules.js +244 -0
- package/dist/modules/glossary/types.d.ts +22 -0
- package/dist/modules/glossary/types.js +2 -0
- package/dist/modules/injection/index.d.ts +1 -0
- package/dist/modules/injection/index.js +6 -0
- package/dist/modules/injection/inject.d.ts +29 -0
- package/dist/modules/injection/inject.js +1050 -0
- package/dist/modules/keygen/index.d.ts +1 -0
- package/dist/modules/keygen/index.js +11 -0
- package/dist/modules/keygen/keygen.d.ts +4 -0
- package/dist/modules/keygen/keygen.js +123 -0
- package/dist/modules/keygen/locale-data.d.ts +7 -0
- package/dist/modules/keygen/locale-data.js +73 -0
- package/dist/modules/keygen/public.d.ts +2 -0
- package/dist/modules/keygen/public.js +12 -0
- package/dist/modules/locale-builder/index.d.ts +1 -0
- package/dist/modules/locale-builder/index.js +7 -0
- package/dist/modules/locale-builder/locales.d.ts +13 -0
- package/dist/modules/locale-builder/locales.js +130 -0
- package/dist/modules/lockfile/hasher.d.ts +7 -0
- package/dist/modules/lockfile/hasher.js +13 -0
- package/dist/modules/lockfile/index.d.ts +3 -0
- package/dist/modules/lockfile/index.js +22 -0
- package/dist/modules/lockfile/lockfile-manager.d.ts +99 -0
- package/dist/modules/lockfile/lockfile-manager.js +497 -0
- package/dist/modules/lockfile/schema.d.ts +196 -0
- package/dist/modules/lockfile/schema.js +56 -0
- package/dist/modules/parser/index.d.ts +2 -0
- package/dist/modules/parser/index.js +9 -0
- package/dist/modules/summary/index.d.ts +1 -0
- package/dist/modules/summary/index.js +7 -0
- package/dist/modules/summary/summary.d.ts +9 -0
- package/dist/modules/summary/summary.js +195 -0
- package/dist/modules/sync-detector/index.d.ts +2 -0
- package/dist/modules/sync-detector/index.js +7 -0
- package/dist/modules/sync-detector/reporter.d.ts +3 -0
- package/dist/modules/sync-detector/reporter.js +16 -0
- package/dist/modules/sync-detector/sync-detector.d.ts +39 -0
- package/dist/modules/sync-detector/sync-detector.js +374 -0
- package/dist/modules/translator/batch-optimizer.d.ts +12 -0
- package/dist/modules/translator/batch-optimizer.js +30 -0
- package/dist/modules/translator/client/byok.provider.d.ts +64 -0
- package/dist/modules/translator/client/byok.provider.js +319 -0
- package/dist/modules/translator/client/direct-translator.client.d.ts +12 -0
- package/dist/modules/translator/client/direct-translator.client.js +71 -0
- package/dist/modules/translator/client/gemini.provider.d.ts +1 -0
- package/dist/modules/translator/client/gemini.provider.js +110 -0
- package/dist/modules/translator/client/groq.provider.d.ts +1 -0
- package/dist/modules/translator/client/groq.provider.js +111 -0
- package/dist/modules/translator/client/request.types.d.ts +1 -0
- package/dist/modules/translator/client/request.types.js +2 -0
- package/dist/modules/translator/client/retry.d.ts +29 -0
- package/dist/modules/translator/client/retry.js +94 -0
- package/dist/modules/translator/client/test-utils/mock.client.d.ts +31 -0
- package/dist/modules/translator/client/test-utils/mock.client.js +59 -0
- package/dist/modules/translator/client/translator.interface.d.ts +1 -0
- package/dist/modules/translator/client/translator.interface.js +2 -0
- package/dist/modules/translator/icu-branches.d.ts +138 -0
- package/dist/modules/translator/icu-branches.js +393 -0
- package/dist/modules/translator/language-codes/errors.d.ts +10 -0
- package/dist/modules/translator/language-codes/errors.js +18 -0
- package/dist/modules/translator/language-codes/flores-map.d.ts +1 -0
- package/dist/modules/translator/language-codes/flores-map.js +107 -0
- package/dist/modules/translator/language-codes/index.d.ts +11 -0
- package/dist/modules/translator/language-codes/index.js +24 -0
- package/dist/modules/translator/language-codes/language-mapper.d.ts +25 -0
- package/dist/modules/translator/language-codes/language-mapper.js +132 -0
- package/dist/modules/translator/language-codes/rtl-languages.d.ts +2 -0
- package/dist/modules/translator/language-codes/rtl-languages.js +9 -0
- package/dist/modules/translator/memory/memory-matcher.d.ts +8 -0
- package/dist/modules/translator/memory/memory-matcher.js +218 -0
- package/dist/modules/translator/memory/types.d.ts +22 -0
- package/dist/modules/translator/memory/types.js +2 -0
- package/dist/modules/translator/translate.d.ts +74 -0
- package/dist/modules/translator/translate.js +1047 -0
- package/dist/modules/vue/migrate.d.ts +13 -0
- package/dist/modules/vue/migrate.js +40 -0
- package/dist/modules/vue/script-inject.d.ts +16 -0
- package/dist/modules/vue/script-inject.js +115 -0
- package/dist/modules/vue/sfc.d.ts +11 -0
- package/dist/modules/vue/sfc.js +51 -0
- package/dist/modules/vue/template-rewrite.d.ts +25 -0
- package/dist/modules/vue/template-rewrite.js +76 -0
- package/dist/modules/vue/template-scan.d.ts +29 -0
- package/dist/modules/vue/template-scan.js +264 -0
- package/dist/modules/workspace/index.d.ts +1 -0
- package/dist/modules/workspace/index.js +5 -0
- package/dist/modules/workspace/validate.d.ts +13 -0
- package/dist/modules/workspace/validate.js +333 -0
- package/dist/orchestrator.d.ts +13 -0
- package/dist/orchestrator.js +727 -0
- package/dist/providers/default-translation-provider.d.ts +20 -0
- package/dist/providers/default-translation-provider.js +30 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +21 -0
- package/dist/providers/types.d.ts +153 -0
- package/dist/providers/types.js +2 -0
- package/dist/qa/check-project.d.ts +50 -0
- package/dist/qa/check-project.js +193 -0
- package/dist/qa/gettext-files.d.ts +15 -0
- package/dist/qa/gettext-files.js +115 -0
- package/dist/qa/locale-files.d.ts +44 -0
- package/dist/qa/locale-files.js +159 -0
- package/dist/qa/locale-qa.d.ts +61 -0
- package/dist/qa/locale-qa.js +342 -0
- package/dist/qa/review.d.ts +43 -0
- package/dist/qa/review.js +175 -0
- package/dist/runtime/config.d.ts +8 -0
- package/dist/runtime/config.js +37 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +8 -0
- package/dist/runtime/types.d.ts +427 -0
- package/dist/runtime/types.js +38 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.js +12 -0
- package/dist/utils/ast-helpers.d.ts +57 -0
- package/dist/utils/ast-helpers.js +608 -0
- package/dist/utils/cache-keys.d.ts +8 -0
- package/dist/utils/cache-keys.js +18 -0
- package/dist/utils/circuit-breaker.d.ts +43 -0
- package/dist/utils/circuit-breaker.js +119 -0
- package/dist/utils/concurrent-map.d.ts +4 -0
- package/dist/utils/concurrent-map.js +21 -0
- package/dist/utils/detect-format.d.ts +5 -0
- package/dist/utils/detect-format.js +125 -0
- package/dist/utils/extraction-options.d.ts +29 -0
- package/dist/utils/extraction-options.js +33 -0
- package/dist/utils/file-utils.d.ts +33 -0
- package/dist/utils/file-utils.js +267 -0
- package/dist/utils/glossary-match.d.ts +9 -0
- package/dist/utils/glossary-match.js +25 -0
- package/dist/utils/html-extractor.d.ts +8 -0
- package/dist/utils/html-extractor.js +317 -0
- package/dist/utils/i18next-icu.d.ts +38 -0
- package/dist/utils/i18next-icu.js +159 -0
- package/dist/utils/icu-message.d.ts +65 -0
- package/dist/utils/icu-message.js +346 -0
- package/dist/utils/icu-spans.d.ts +10 -0
- package/dist/utils/icu-spans.js +126 -0
- package/dist/utils/jsx-message.d.ts +93 -0
- package/dist/utils/jsx-message.js +628 -0
- package/dist/utils/key-usage.d.ts +35 -0
- package/dist/utils/key-usage.js +247 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.js +33 -0
- package/dist/utils/metadata.d.ts +82 -0
- package/dist/utils/metadata.js +261 -0
- package/dist/utils/module-constants.d.ts +30 -0
- package/dist/utils/module-constants.js +265 -0
- package/dist/utils/not-injected.d.ts +6 -0
- package/dist/utils/not-injected.js +38 -0
- package/dist/utils/placeholder-protection.d.ts +74 -0
- package/dist/utils/placeholder-protection.js +181 -0
- package/dist/utils/pseudo-markers.d.ts +9 -0
- package/dist/utils/pseudo-markers.js +16 -0
- package/dist/utils/string-utils.d.ts +52 -0
- package/dist/utils/string-utils.js +270 -0
- package/dist/utils/translation-quality.d.ts +34 -0
- package/dist/utils/translation-quality.js +156 -0
- package/dist/utils/translation-sanitizer.d.ts +11 -0
- package/dist/utils/translation-sanitizer.js +71 -0
- package/dist/utils/translator-caller.d.ts +32 -0
- package/dist/utils/translator-caller.js +217 -0
- package/dist/utils/translator-load-balancer.d.ts +73 -0
- package/dist/utils/translator-load-balancer.js +297 -0
- package/dist/utils/ui-copy.d.ts +32 -0
- package/dist/utils/ui-copy.js +126 -0
- package/dist/utils/untranslated.d.ts +15 -0
- package/dist/utils/untranslated.js +34 -0
- package/dist/utils/workspace.d.ts +14 -0
- package/dist/utils/workspace.js +89 -0
- package/package.json +64 -4
- package/schemas/translate-report.schema.json +297 -0
- package/README.md +0 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lockfileDataSchema = exports.lockfileEntrySchema = void 0;
|
|
4
|
+
exports.createEmptyLockfile = createEmptyLockfile;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
7
|
+
// Lockfile entry (per translation key)
|
|
8
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
9
|
+
exports.lockfileEntrySchema = zod_1.z.object({
|
|
10
|
+
/** SHA-256 hex digest of the source string */
|
|
11
|
+
sourceHash: zod_1.z.string(),
|
|
12
|
+
/** ISO-8601 timestamp of last translation */
|
|
13
|
+
translatedAt: zod_1.z.string(),
|
|
14
|
+
/** Translated values keyed by locale code */
|
|
15
|
+
languages: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
|
|
16
|
+
/** Metadata per locale */
|
|
17
|
+
metadata: zod_1.z.record(zod_1.z.string(), zod_1.z.object({
|
|
18
|
+
fromMemory: zod_1.z.boolean().optional(),
|
|
19
|
+
sourceHash: zod_1.z.string().optional(),
|
|
20
|
+
/** This key's translation for the locale is known to be in TM; skip backfill. */
|
|
21
|
+
inTm: zod_1.z.boolean().optional(),
|
|
22
|
+
/** Pseudo-localized (`--provider pseudo`), not a translation: any real run re-translates it. */
|
|
23
|
+
pseudo: zod_1.z.boolean().optional(),
|
|
24
|
+
/**
|
|
25
|
+
* Fingerprint of the glossary rules that applied to this key's source
|
|
26
|
+
* for the locale (see glossaryFingerprint). Absent: none applied.
|
|
27
|
+
* A run whose rules give a different fingerprint re-translates it.
|
|
28
|
+
*/
|
|
29
|
+
glossaryHash: zod_1.z.string().optional(),
|
|
30
|
+
/**
|
|
31
|
+
* The translation came from the project's own files (e.g. a .po
|
|
32
|
+
* catalogue), not from Babelize: glossary edits don't overwrite it.
|
|
33
|
+
*/
|
|
34
|
+
external: zod_1.z.boolean().optional(),
|
|
35
|
+
})).optional(),
|
|
36
|
+
});
|
|
37
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
38
|
+
// Top-level lockfile
|
|
39
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
40
|
+
exports.lockfileDataSchema = zod_1.z.object({
|
|
41
|
+
version: zod_1.z.string().default('1.0'),
|
|
42
|
+
projectId: zod_1.z.string(),
|
|
43
|
+
updatedAt: zod_1.z.string(),
|
|
44
|
+
keys: zod_1.z.record(zod_1.z.string(), exports.lockfileEntrySchema),
|
|
45
|
+
});
|
|
46
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
47
|
+
// Empty lockfile factory
|
|
48
|
+
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
49
|
+
function createEmptyLockfile(projectId) {
|
|
50
|
+
return {
|
|
51
|
+
version: '1.0',
|
|
52
|
+
projectId,
|
|
53
|
+
updatedAt: new Date().toISOString(),
|
|
54
|
+
keys: {},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseFile = parseFile;
|
|
4
|
+
const ast_helpers_1 = require("../../utils/ast-helpers");
|
|
5
|
+
function parseFile(content, language) {
|
|
6
|
+
const isTypeScript = language === 'ts' || language === 'tsx';
|
|
7
|
+
const options = { isTypeScript, isJSX: language.endsWith('x') };
|
|
8
|
+
return (0, ast_helpers_1.parseCode)(content, options);
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateSummary, generateReadableSummary, formatProcessingTime } from './summary';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatProcessingTime = exports.generateReadableSummary = exports.generateSummary = void 0;
|
|
4
|
+
var summary_1 = require("./summary");
|
|
5
|
+
Object.defineProperty(exports, "generateSummary", { enumerable: true, get: function () { return summary_1.generateSummary; } });
|
|
6
|
+
Object.defineProperty(exports, "generateReadableSummary", { enumerable: true, get: function () { return summary_1.generateReadableSummary; } });
|
|
7
|
+
Object.defineProperty(exports, "formatProcessingTime", { enumerable: true, get: function () { return summary_1.formatProcessingTime; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DiffMetadata, ExtractionResult, InjectionResult, KeyGenerationResult, LocaleHandlingResult, ProcessingStats, TranslationResult, Warning } from '../../runtime/types';
|
|
2
|
+
import type { LockfileStats } from '../lockfile';
|
|
3
|
+
export declare function generateSummary(extraction: ExtractionResult, keyGeneration: KeyGenerationResult, localeHandling: LocaleHandlingResult, translation: TranslationResult, injection: InjectionResult, processingStartTime: number, lockfileStats?: LockfileStats, tmHits?: number): {
|
|
4
|
+
stats: ProcessingStats;
|
|
5
|
+
warnings: Warning[];
|
|
6
|
+
diffs: DiffMetadata[];
|
|
7
|
+
};
|
|
8
|
+
export declare function formatProcessingTime(ms: number): string;
|
|
9
|
+
export declare function generateReadableSummary(stats: ProcessingStats): string;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSummary = generateSummary;
|
|
4
|
+
exports.formatProcessingTime = formatProcessingTime;
|
|
5
|
+
exports.generateReadableSummary = generateReadableSummary;
|
|
6
|
+
function generateSummary(extraction, keyGeneration, localeHandling, translation, injection, processingStartTime, lockfileStats, tmHits = 0) {
|
|
7
|
+
const processingTimeMs = Date.now() - processingStartTime;
|
|
8
|
+
const stats = {
|
|
9
|
+
filesScanned: extraction.filesAnalyzed.length,
|
|
10
|
+
filesWithStrings: countFilesWithStrings(extraction),
|
|
11
|
+
stringsExtracted: extraction.strings.length,
|
|
12
|
+
keysGenerated: keyGeneration.keys.length,
|
|
13
|
+
filesModified: injection.modifiedFiles.length,
|
|
14
|
+
injectionsApplied: injection.totalInjections,
|
|
15
|
+
localeFilesCreated: translation.locales.length + (localeHandling.sourceLocale.isNew ? 1 : 0),
|
|
16
|
+
processingTimeMs,
|
|
17
|
+
translationsFromLockfile: lockfileStats?.reused ?? 0,
|
|
18
|
+
translationsFromMemory: tmHits,
|
|
19
|
+
lockfileUsed: lockfileStats != null,
|
|
20
|
+
lockfileKeysTranslated: lockfileStats?.translated,
|
|
21
|
+
lockfileKeysChanged: lockfileStats?.changed,
|
|
22
|
+
};
|
|
23
|
+
const warnings = [
|
|
24
|
+
...collectExtractionWarnings(extraction),
|
|
25
|
+
...collectKeyGenWarnings(keyGeneration),
|
|
26
|
+
...collectTranslationWarnings(translation),
|
|
27
|
+
...collectInjectionWarnings(injection),
|
|
28
|
+
];
|
|
29
|
+
const diffs = [...generateLocaleDiffs(localeHandling, translation), ...generateInjectionDiffs(injection)];
|
|
30
|
+
return { stats, warnings, diffs };
|
|
31
|
+
}
|
|
32
|
+
function countFilesWithStrings(extraction) {
|
|
33
|
+
const filesWithStrings = new Set();
|
|
34
|
+
for (const str of extraction.strings)
|
|
35
|
+
filesWithStrings.add(str.file);
|
|
36
|
+
return filesWithStrings.size;
|
|
37
|
+
}
|
|
38
|
+
function collectExtractionWarnings(extraction) {
|
|
39
|
+
const warnings = [];
|
|
40
|
+
if (extraction.warnings) {
|
|
41
|
+
warnings.push(...extraction.warnings);
|
|
42
|
+
}
|
|
43
|
+
for (const skipped of extraction.skippedFiles) {
|
|
44
|
+
warnings.push({
|
|
45
|
+
type: 'parse-warning',
|
|
46
|
+
file: skipped.file,
|
|
47
|
+
message: `File skipped: ${skipped.reason}${skipped.details ? ` - ${skipped.details}` : ''}`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return warnings;
|
|
51
|
+
}
|
|
52
|
+
function collectKeyGenWarnings(keyGeneration) {
|
|
53
|
+
const warnings = [];
|
|
54
|
+
for (const dup of keyGeneration.duplicates) {
|
|
55
|
+
warnings.push({
|
|
56
|
+
type: 'duplicate-key',
|
|
57
|
+
file: '',
|
|
58
|
+
message: `Key "${dup.original}" was renamed to "${dup.renamed}" to avoid collision`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return warnings;
|
|
62
|
+
}
|
|
63
|
+
function collectTranslationWarnings(translation) {
|
|
64
|
+
const warnings = [];
|
|
65
|
+
for (const error of translation.errors) {
|
|
66
|
+
warnings.push({
|
|
67
|
+
type: 'parse-warning',
|
|
68
|
+
file: `locales/${error.locale}.json`,
|
|
69
|
+
message: `Translation failed: ${error.error}`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return warnings;
|
|
73
|
+
}
|
|
74
|
+
function collectInjectionWarnings(injection) {
|
|
75
|
+
const warnings = [];
|
|
76
|
+
for (const skipped of injection.skippedFiles) {
|
|
77
|
+
warnings.push({
|
|
78
|
+
type: 'parse-warning',
|
|
79
|
+
file: skipped.file,
|
|
80
|
+
message: `Injection skipped: ${skipped.reason}${skipped.details ? ` - ${skipped.details}` : ''}`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
for (const file of injection.modifiedFiles) {
|
|
84
|
+
for (const inj of file.injections) {
|
|
85
|
+
if (inj.confidence < 90) {
|
|
86
|
+
warnings.push({
|
|
87
|
+
type: 'low-confidence',
|
|
88
|
+
file: inj.file,
|
|
89
|
+
line: inj.line,
|
|
90
|
+
message: `Low confidence (${inj.confidence}%) injection: "${inj.original}" -> "${inj.replacement}"`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return warnings;
|
|
96
|
+
}
|
|
97
|
+
function generateLocaleDiffs(localeHandling, translation) {
|
|
98
|
+
const diffs = [];
|
|
99
|
+
diffs.push({
|
|
100
|
+
file: localeHandling.sourceLocale.path,
|
|
101
|
+
changeType: localeHandling.sourceLocale.isNew ? 'created' : 'modified',
|
|
102
|
+
linesAdded: localeHandling.newKeysCount,
|
|
103
|
+
linesRemoved: 0,
|
|
104
|
+
});
|
|
105
|
+
for (const locale of translation.locales) {
|
|
106
|
+
const keyCount = countNestedKeys(locale.data);
|
|
107
|
+
diffs.push({
|
|
108
|
+
file: locale.path,
|
|
109
|
+
changeType: 'created',
|
|
110
|
+
linesAdded: keyCount,
|
|
111
|
+
linesRemoved: 0,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return diffs;
|
|
115
|
+
}
|
|
116
|
+
function generateInjectionDiffs(injection) {
|
|
117
|
+
const diffs = [];
|
|
118
|
+
for (const file of injection.modifiedFiles) {
|
|
119
|
+
const originalLines = file.originalContent.split('\n').length;
|
|
120
|
+
const modifiedLines = file.modifiedContent.split('\n').length;
|
|
121
|
+
const lineDiff = modifiedLines - originalLines;
|
|
122
|
+
diffs.push({
|
|
123
|
+
file: file.file,
|
|
124
|
+
changeType: 'modified',
|
|
125
|
+
linesAdded: Math.max(0, lineDiff) + file.injections.length,
|
|
126
|
+
linesRemoved: file.injections.length,
|
|
127
|
+
diff: generateUnifiedDiff(file),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return diffs;
|
|
131
|
+
}
|
|
132
|
+
function countNestedKeys(data) {
|
|
133
|
+
let count = 0;
|
|
134
|
+
for (const value of Object.values(data)) {
|
|
135
|
+
if (typeof value === 'string')
|
|
136
|
+
count++;
|
|
137
|
+
else if (typeof value === 'object' && value !== null)
|
|
138
|
+
count += countNestedKeys(value);
|
|
139
|
+
}
|
|
140
|
+
return count;
|
|
141
|
+
}
|
|
142
|
+
function generateUnifiedDiff(file) {
|
|
143
|
+
const lines = [];
|
|
144
|
+
lines.push(`--- a/${file.file}`);
|
|
145
|
+
lines.push(`+++ b/${file.file}`);
|
|
146
|
+
if (file.importAdded) {
|
|
147
|
+
lines.push(`@@ +1,1 @@`);
|
|
148
|
+
lines.push(`+<i18n import added>`);
|
|
149
|
+
}
|
|
150
|
+
if (file.hookAdded) {
|
|
151
|
+
lines.push(`++ <i18n hook added>`);
|
|
152
|
+
}
|
|
153
|
+
for (const inj of file.injections) {
|
|
154
|
+
lines.push(`@@ -${inj.line},1 +${inj.line},1 @@`);
|
|
155
|
+
lines.push(`-${inj.original}`);
|
|
156
|
+
lines.push(`+${inj.replacement}`);
|
|
157
|
+
}
|
|
158
|
+
return lines.join('\n');
|
|
159
|
+
}
|
|
160
|
+
function formatProcessingTime(ms) {
|
|
161
|
+
if (ms < 1000)
|
|
162
|
+
return `${ms}ms`;
|
|
163
|
+
const seconds = (ms / 1000).toFixed(1);
|
|
164
|
+
return `${seconds}s`;
|
|
165
|
+
}
|
|
166
|
+
function generateReadableSummary(stats) {
|
|
167
|
+
const lines = [
|
|
168
|
+
'=== Babelize Processing Summary ===',
|
|
169
|
+
'',
|
|
170
|
+
`๐ Files scanned: ${stats.filesScanned}`,
|
|
171
|
+
`๐ Files with translatable strings: ${stats.filesWithStrings}`,
|
|
172
|
+
`๐ค Strings extracted: ${stats.stringsExtracted}`,
|
|
173
|
+
`๐ Keys generated: ${stats.keysGenerated}`,
|
|
174
|
+
`โ๏ธ Files modified: ${stats.filesModified}`,
|
|
175
|
+
`๐ Injections applied: ${stats.injectionsApplied}`,
|
|
176
|
+
`๐ Locale files created: ${stats.localeFilesCreated}`,
|
|
177
|
+
`โฑ๏ธ Processing time: ${formatProcessingTime(stats.processingTimeMs)}`,
|
|
178
|
+
];
|
|
179
|
+
if (stats.lockfileUsed) {
|
|
180
|
+
const translated = stats.lockfileKeysTranslated ?? 0;
|
|
181
|
+
const reused = stats.translationsFromLockfile ?? 0;
|
|
182
|
+
const changed = stats.lockfileKeysChanged ?? 0;
|
|
183
|
+
const parts = [];
|
|
184
|
+
parts.push(`${translated.toLocaleString()} translated`);
|
|
185
|
+
parts.push(`${reused.toLocaleString()} reused from lockfile`);
|
|
186
|
+
if (changed > 0) {
|
|
187
|
+
parts.push(`${changed.toLocaleString()} source updates`);
|
|
188
|
+
}
|
|
189
|
+
lines.push(`๐ Lockfile: ${parts.join(' ยท ')}`);
|
|
190
|
+
}
|
|
191
|
+
if (stats.translationsFromMemory && stats.translationsFromMemory > 0) {
|
|
192
|
+
lines.push(`๐ง Memory: ${stats.translationsFromMemory.toLocaleString()} strings reused from translation memory`);
|
|
193
|
+
}
|
|
194
|
+
return lines.join('\n');
|
|
195
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatSyncNotificationMessage = exports.detectSyncIssues = void 0;
|
|
4
|
+
var sync_detector_1 = require("./sync-detector");
|
|
5
|
+
Object.defineProperty(exports, "detectSyncIssues", { enumerable: true, get: function () { return sync_detector_1.detectSyncIssues; } });
|
|
6
|
+
var reporter_1 = require("./reporter");
|
|
7
|
+
Object.defineProperty(exports, "formatSyncNotificationMessage", { enumerable: true, get: function () { return reporter_1.formatSyncNotificationMessage; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatSyncNotificationMessage = formatSyncNotificationMessage;
|
|
4
|
+
function formatSyncNotificationMessage(result) {
|
|
5
|
+
const parts = [];
|
|
6
|
+
if (result.newStrings.length > 0) {
|
|
7
|
+
parts.push(`${result.newStrings.length} new string${result.newStrings.length === 1 ? '' : 's'}`);
|
|
8
|
+
}
|
|
9
|
+
if (result.changedStrings.length > 0) {
|
|
10
|
+
parts.push(`${result.changedStrings.length} changed string${result.changedStrings.length === 1 ? '' : 's'}`);
|
|
11
|
+
}
|
|
12
|
+
if (result.missingLocaleKeys.length > 0) {
|
|
13
|
+
parts.push(`${result.missingLocaleKeys.length} missing locale key${result.missingLocaleKeys.length === 1 ? '' : 's'}`);
|
|
14
|
+
}
|
|
15
|
+
return `${parts.join(', ')} detected in your last commit`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { WorkspaceInfo } from '../../runtime/types';
|
|
2
|
+
export interface SyncDetectionOptions {
|
|
3
|
+
/** The project's runs use an LLM translator (BYOK / hosted LLM); default false (NLLB). */
|
|
4
|
+
llmTranslator?: boolean;
|
|
5
|
+
/** Framework of the project, when the caller knows it; otherwise guessed from package.json. */
|
|
6
|
+
framework?: WorkspaceInfo['framework'];
|
|
7
|
+
}
|
|
8
|
+
export interface SyncDetectedString {
|
|
9
|
+
key: string;
|
|
10
|
+
value: string;
|
|
11
|
+
file: string;
|
|
12
|
+
line: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SyncMissingLocaleKey {
|
|
15
|
+
key: string;
|
|
16
|
+
presentIn: string[];
|
|
17
|
+
missingFrom: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface SyncDetectionResult {
|
|
20
|
+
newStrings: SyncDetectedString[];
|
|
21
|
+
changedStrings: SyncDetectedString[];
|
|
22
|
+
missingLocaleKeys: SyncMissingLocaleKey[];
|
|
23
|
+
totalIssues: number;
|
|
24
|
+
commitSha: string;
|
|
25
|
+
checkedAt: string;
|
|
26
|
+
filesChecked: string[];
|
|
27
|
+
filesSkipped: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Detect sync issues by comparing extracted strings from changed files
|
|
31
|
+
* against the lockfile and locale files.
|
|
32
|
+
*
|
|
33
|
+
* @param projectId The project identifier (for lockfile lookup)
|
|
34
|
+
* @param workspacePath Absolute path to the project workspace
|
|
35
|
+
* @param changedFiles List of file paths changed in the push (relative to repo root)
|
|
36
|
+
* @param commitSha The commit SHA that triggered this check
|
|
37
|
+
* @param targetLocales Target locales configured for this project
|
|
38
|
+
*/
|
|
39
|
+
export declare function detectSyncIssues(projectId: string, workspacePath: string, changedFiles: string[], commitSha: string, targetLocales: string[], options?: SyncDetectionOptions): Promise<SyncDetectionResult>;
|