@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,49 @@
|
|
|
1
|
+
/** Shared types for the Django (gettext) pipeline. */
|
|
2
|
+
export interface GettextMessage {
|
|
3
|
+
msgid: string;
|
|
4
|
+
msgidPlural?: string;
|
|
5
|
+
msgctxt?: string;
|
|
6
|
+
/** PO flags such as python-format / python-brace-format. */
|
|
7
|
+
flags: string[];
|
|
8
|
+
/** Translator comments (`#.` in the PO file). */
|
|
9
|
+
comments: string[];
|
|
10
|
+
}
|
|
11
|
+
/** A hardcoded string the injector can wrap. */
|
|
12
|
+
export interface PythonEdit {
|
|
13
|
+
kind: 'python';
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
/** Evaluated at import time (module/class level): needs gettext_lazy. */
|
|
17
|
+
lazy: boolean;
|
|
18
|
+
/** Argument text placed inside the gettext call. */
|
|
19
|
+
inner: string;
|
|
20
|
+
/** Text appended after the call, e.g. ` % {"count": count}`. */
|
|
21
|
+
suffix: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TemplateEdit {
|
|
24
|
+
kind: 'template';
|
|
25
|
+
start: number;
|
|
26
|
+
end: number;
|
|
27
|
+
replacement: string;
|
|
28
|
+
}
|
|
29
|
+
export interface DjangoFinding {
|
|
30
|
+
message: GettextMessage;
|
|
31
|
+
/** 1-based line of the string in the original file. */
|
|
32
|
+
line: number;
|
|
33
|
+
/** Already marked for translation in the code (gettext call, trans tag). */
|
|
34
|
+
wrapped: boolean;
|
|
35
|
+
/** How to mark a hardcoded string (absent for wrapped strings). */
|
|
36
|
+
edit?: PythonEdit | TemplateEdit;
|
|
37
|
+
}
|
|
38
|
+
export interface DjangoUnwired {
|
|
39
|
+
line: number;
|
|
40
|
+
text: string;
|
|
41
|
+
reason: string;
|
|
42
|
+
}
|
|
43
|
+
export interface DjangoFileAnalysis {
|
|
44
|
+
findings: DjangoFinding[];
|
|
45
|
+
/** User-facing text found but deliberately not wrapped, with why. */
|
|
46
|
+
unwired: DjangoUnwired[];
|
|
47
|
+
}
|
|
48
|
+
/** PO format flags for a message, the way xgettext would mark it. */
|
|
49
|
+
export declare function formatFlags(...texts: Array<string | undefined>): string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Shared types for the Django (gettext) pipeline. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.formatFlags = formatFlags;
|
|
5
|
+
const PYTHON_FORMAT = /%(?:\(\w+\))?[sdif]/;
|
|
6
|
+
const BRACE_FORMAT = /\{(?:\w+(?:\.\w+|\[\w+\])*)?(?:![rsa])?(?::[^{}]*)?\}/;
|
|
7
|
+
/** PO format flags for a message, the way xgettext would mark it. */
|
|
8
|
+
function formatFlags(...texts) {
|
|
9
|
+
const all = texts.filter((t) => !!t).map((t) => t.replace(/%%/g, ''));
|
|
10
|
+
if (all.some((t) => PYTHON_FORMAT.test(t)))
|
|
11
|
+
return ['python-format'];
|
|
12
|
+
if (all.some((t) => BRACE_FORMAT.test(t.replace(/\{\{|\}\}/g, ''))))
|
|
13
|
+
return ['python-brace-format'];
|
|
14
|
+
return [];
|
|
15
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babelize Engine v2 — public API.
|
|
3
|
+
*
|
|
4
|
+
* This folder is introduced alongside the existing v1 engine (phases/*) using a
|
|
5
|
+
* strangler-fig approach. Nothing outside v2 should import internal modules
|
|
6
|
+
* directly — only this file re-exports the public surface.
|
|
7
|
+
*/
|
|
8
|
+
export { BabelizeEngine } from './BabelizeEngine';
|
|
9
|
+
export type { BabelizeConfig, BabelizeEngineDependencies, BabelRunResult, ExtractedString, TranslationResult, TranslationUnit, } from './types';
|
|
10
|
+
export { loadBabelizeConfig } from './config';
|
|
11
|
+
export { runEngineV2, validateEngineConfigV2 } from './runtime';
|
|
12
|
+
export { RunAbortedError } from './orchestrator';
|
|
13
|
+
export type { EngineConfigV2, EngineResultV2 } from './runtime';
|
|
14
|
+
export type { KeyUsageReport, ProcessingStats } from './runtime/types';
|
|
15
|
+
export { scanKeyReferences } from './utils/key-usage';
|
|
16
|
+
export { validateWorkspace } from './modules/workspace';
|
|
17
|
+
export * from './providers';
|
|
18
|
+
export { runWithEngineLogger, setEngineLogger } from './utils/logger';
|
|
19
|
+
export type { EngineLogger, LogContext } from './utils/logger';
|
|
20
|
+
export * from './modules/lockfile';
|
|
21
|
+
export * from './modules/translator/language-codes';
|
|
22
|
+
export type { MemoryEntry, FuzzyMatch, MemoryLookupResult } from './modules/translator/memory/types';
|
|
23
|
+
export { matchFromMemory } from './modules/translator/memory/memory-matcher';
|
|
24
|
+
export { detectSyncIssues, formatSyncNotificationMessage } from './modules/sync-detector';
|
|
25
|
+
export type { SyncDetectionResult, SyncDetectedString, SyncMissingLocaleKey } from './modules/sync-detector';
|
|
26
|
+
export type { TranslationEntry, WorkspaceInfo } from './runtime/types';
|
|
27
|
+
export { addBabelToHistory, detectProjectInfo, getBabelizeSummary, getProjectInfo, saveCachedStrings, saveProjectConfig, } from './utils/metadata';
|
|
28
|
+
export type { BabelHistoryEntry, ExtractedStringEntry, ProjectInfo } from './utils/metadata';
|
|
29
|
+
export { detectStack, localRepoFiles, FRAMEWORK_DISPLAY_NAMES } from './detection/stack';
|
|
30
|
+
export type { DetectedStack, RepoFiles, StackFramework, PackageManagerId } from './detection/stack';
|
|
31
|
+
export { parseCode } from './utils/ast-helpers';
|
|
32
|
+
export { extractPlaceholders, hasICUSyntax, hashString, protectPlaceholders, restorePlaceholders, } from './utils/string-utils';
|
|
33
|
+
export { sanitizeTranslation, validateRawTokens } from './utils/translation-sanitizer';
|
|
34
|
+
export { checkTokens, hasNothingToTranslate, protectText, restoreText, sameProtectedSpans } from './utils/placeholder-protection';
|
|
35
|
+
export type { ProtectedText, TokenCheck } from './utils/placeholder-protection';
|
|
36
|
+
export { compareIcuMessages, isIcuMessage, parseIcu, requiredPluralCategories } from './utils/icu-message';
|
|
37
|
+
export type { IcuIssue, IcuNode } from './utils/icu-message';
|
|
38
|
+
export { callTranslator, checkTranslatorHealth, warmupTranslator } from './utils/translator-caller';
|
|
39
|
+
export { translatorLoadBalancer } from './utils/translator-load-balancer';
|
|
40
|
+
export type { TranslatorEndpoint } from './utils/translator-load-balancer';
|
|
41
|
+
export { validateTranslationQuality, validateBatchQuality } from './utils/translation-quality';
|
|
42
|
+
export type { QualityIssue, QualityResult } from './utils/translation-quality';
|
|
43
|
+
export { CircuitBreaker, CircuitState, getCircuitBreaker } from './utils/circuit-breaker';
|
|
44
|
+
export type { CircuitBreakerOptions } from './utils/circuit-breaker';
|
|
45
|
+
export { localeExtension } from './utils/file-utils';
|
|
46
|
+
export { analyzeProject, analyzeWorkspace, frameworkSupport, } from './analysis/analyze';
|
|
47
|
+
export type { AnalyzeOptions, AnalyzedString, FrameworkSupport, ProjectAnalysis } from './analysis/analyze';
|
|
48
|
+
export { checkLocalePair, flattenLocaleMessages, tallyLocaleIssues } from './qa/locale-qa';
|
|
49
|
+
export { canonicalLocale, canonicalizeLocaleKeys, containsTerm, localeValue, normalizeGlossary, glossaryFingerprint, } from './modules/glossary';
|
|
50
|
+
export type { GlossaryRules, GlossaryRuleInput } from './modules/glossary';
|
|
51
|
+
export type { LocaleGlossary, LocaleIssue, LocaleIssueCode, LocaleIssueSeverity, LocalePairOptions, LocalePairReport, } from './qa/locale-qa';
|
|
52
|
+
export { DEFAULT_LOCALE_IGNORE_DIRS, findLocaleFileSets, groupLocaleFiles, isIgnoredLocalePath, isLocaleCode, loadLocale } from './qa/locale-files';
|
|
53
|
+
export type { FindLocaleOptions, LoadedLocale, LocaleFileSet, ProjectFileReader } from './qa/locale-files';
|
|
54
|
+
export { reviewLocaleChanges, ReviewError } from './qa/review';
|
|
55
|
+
export type { LocaleChangeReview, LocaleSetChangeReview, ReviewOptions } from './qa/review';
|
|
56
|
+
export { checkProjectLocales, localeIssueFile, readProjectLocaleConfig } from './qa/check-project';
|
|
57
|
+
export type { CheckProjectOptions, LocaleSetReport, ProjectLocaleCheck, ProjectLocaleConfig } from './qa/check-project';
|
|
58
|
+
export { hashText, translationCacheKey, TRANSLATION_CACHE_TTL_SECONDS } from './utils/cache-keys';
|
|
59
|
+
export * from './local';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Babelize Engine v2 — public API.
|
|
4
|
+
*
|
|
5
|
+
* This folder is introduced alongside the existing v1 engine (phases/*) using a
|
|
6
|
+
* strangler-fig approach. Nothing outside v2 should import internal modules
|
|
7
|
+
* directly — only this file re-exports the public surface.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
21
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.analyzeWorkspace = exports.analyzeProject = exports.localeExtension = exports.getCircuitBreaker = exports.CircuitState = exports.CircuitBreaker = exports.validateBatchQuality = exports.validateTranslationQuality = exports.translatorLoadBalancer = exports.warmupTranslator = exports.checkTranslatorHealth = exports.callTranslator = exports.requiredPluralCategories = exports.parseIcu = exports.isIcuMessage = exports.compareIcuMessages = exports.sameProtectedSpans = exports.restoreText = exports.protectText = exports.hasNothingToTranslate = exports.checkTokens = exports.validateRawTokens = exports.sanitizeTranslation = exports.restorePlaceholders = exports.protectPlaceholders = exports.hashString = exports.hasICUSyntax = exports.extractPlaceholders = exports.parseCode = exports.FRAMEWORK_DISPLAY_NAMES = exports.localRepoFiles = exports.detectStack = exports.saveProjectConfig = exports.saveCachedStrings = exports.getProjectInfo = exports.getBabelizeSummary = exports.detectProjectInfo = exports.addBabelToHistory = exports.formatSyncNotificationMessage = exports.detectSyncIssues = exports.matchFromMemory = exports.setEngineLogger = exports.runWithEngineLogger = exports.validateWorkspace = exports.scanKeyReferences = exports.RunAbortedError = exports.validateEngineConfigV2 = exports.runEngineV2 = exports.loadBabelizeConfig = exports.BabelizeEngine = void 0;
|
|
25
|
+
exports.TRANSLATION_CACHE_TTL_SECONDS = exports.translationCacheKey = exports.hashText = exports.readProjectLocaleConfig = exports.localeIssueFile = exports.checkProjectLocales = exports.ReviewError = exports.reviewLocaleChanges = exports.loadLocale = exports.isLocaleCode = exports.isIgnoredLocalePath = exports.groupLocaleFiles = exports.findLocaleFileSets = exports.DEFAULT_LOCALE_IGNORE_DIRS = exports.glossaryFingerprint = exports.normalizeGlossary = exports.localeValue = exports.containsTerm = exports.canonicalizeLocaleKeys = exports.canonicalLocale = exports.tallyLocaleIssues = exports.flattenLocaleMessages = exports.checkLocalePair = exports.frameworkSupport = void 0;
|
|
26
|
+
var BabelizeEngine_1 = require("./BabelizeEngine");
|
|
27
|
+
Object.defineProperty(exports, "BabelizeEngine", { enumerable: true, get: function () { return BabelizeEngine_1.BabelizeEngine; } });
|
|
28
|
+
var config_1 = require("./config");
|
|
29
|
+
Object.defineProperty(exports, "loadBabelizeConfig", { enumerable: true, get: function () { return config_1.loadBabelizeConfig; } });
|
|
30
|
+
// Backend runtime surface (workers/controllers).
|
|
31
|
+
var runtime_1 = require("./runtime");
|
|
32
|
+
Object.defineProperty(exports, "runEngineV2", { enumerable: true, get: function () { return runtime_1.runEngineV2; } });
|
|
33
|
+
Object.defineProperty(exports, "validateEngineConfigV2", { enumerable: true, get: function () { return runtime_1.validateEngineConfigV2; } });
|
|
34
|
+
var orchestrator_1 = require("./orchestrator");
|
|
35
|
+
Object.defineProperty(exports, "RunAbortedError", { enumerable: true, get: function () { return orchestrator_1.RunAbortedError; } });
|
|
36
|
+
var key_usage_1 = require("./utils/key-usage");
|
|
37
|
+
Object.defineProperty(exports, "scanKeyReferences", { enumerable: true, get: function () { return key_usage_1.scanKeyReferences; } });
|
|
38
|
+
// Framework detection without running the pipeline (CLI `translate` uses it
|
|
39
|
+
// to refuse unsupported projects before spending any LLM calls).
|
|
40
|
+
var workspace_1 = require("./modules/workspace");
|
|
41
|
+
Object.defineProperty(exports, "validateWorkspace", { enumerable: true, get: function () { return workspace_1.validateWorkspace; } });
|
|
42
|
+
// ── Providers (infrastructure the host injects) ──────────────
|
|
43
|
+
__exportStar(require("./providers"), exports);
|
|
44
|
+
var logger_1 = require("./utils/logger");
|
|
45
|
+
Object.defineProperty(exports, "runWithEngineLogger", { enumerable: true, get: function () { return logger_1.runWithEngineLogger; } });
|
|
46
|
+
Object.defineProperty(exports, "setEngineLogger", { enumerable: true, get: function () { return logger_1.setEngineLogger; } });
|
|
47
|
+
// ── Pipeline pieces the backend uses directly ────────────────
|
|
48
|
+
__exportStar(require("./modules/lockfile"), exports);
|
|
49
|
+
__exportStar(require("./modules/translator/language-codes"), exports);
|
|
50
|
+
var memory_matcher_1 = require("./modules/translator/memory/memory-matcher");
|
|
51
|
+
Object.defineProperty(exports, "matchFromMemory", { enumerable: true, get: function () { return memory_matcher_1.matchFromMemory; } });
|
|
52
|
+
var sync_detector_1 = require("./modules/sync-detector");
|
|
53
|
+
Object.defineProperty(exports, "detectSyncIssues", { enumerable: true, get: function () { return sync_detector_1.detectSyncIssues; } });
|
|
54
|
+
Object.defineProperty(exports, "formatSyncNotificationMessage", { enumerable: true, get: function () { return sync_detector_1.formatSyncNotificationMessage; } });
|
|
55
|
+
// ── Utilities shared with the backend ────────────────────────
|
|
56
|
+
var metadata_1 = require("./utils/metadata");
|
|
57
|
+
Object.defineProperty(exports, "addBabelToHistory", { enumerable: true, get: function () { return metadata_1.addBabelToHistory; } });
|
|
58
|
+
Object.defineProperty(exports, "detectProjectInfo", { enumerable: true, get: function () { return metadata_1.detectProjectInfo; } });
|
|
59
|
+
Object.defineProperty(exports, "getBabelizeSummary", { enumerable: true, get: function () { return metadata_1.getBabelizeSummary; } });
|
|
60
|
+
Object.defineProperty(exports, "getProjectInfo", { enumerable: true, get: function () { return metadata_1.getProjectInfo; } });
|
|
61
|
+
Object.defineProperty(exports, "saveCachedStrings", { enumerable: true, get: function () { return metadata_1.saveCachedStrings; } });
|
|
62
|
+
Object.defineProperty(exports, "saveProjectConfig", { enumerable: true, get: function () { return metadata_1.saveProjectConfig; } });
|
|
63
|
+
var stack_1 = require("./detection/stack");
|
|
64
|
+
Object.defineProperty(exports, "detectStack", { enumerable: true, get: function () { return stack_1.detectStack; } });
|
|
65
|
+
Object.defineProperty(exports, "localRepoFiles", { enumerable: true, get: function () { return stack_1.localRepoFiles; } });
|
|
66
|
+
Object.defineProperty(exports, "FRAMEWORK_DISPLAY_NAMES", { enumerable: true, get: function () { return stack_1.FRAMEWORK_DISPLAY_NAMES; } });
|
|
67
|
+
var ast_helpers_1 = require("./utils/ast-helpers");
|
|
68
|
+
Object.defineProperty(exports, "parseCode", { enumerable: true, get: function () { return ast_helpers_1.parseCode; } });
|
|
69
|
+
var string_utils_1 = require("./utils/string-utils");
|
|
70
|
+
Object.defineProperty(exports, "extractPlaceholders", { enumerable: true, get: function () { return string_utils_1.extractPlaceholders; } });
|
|
71
|
+
Object.defineProperty(exports, "hasICUSyntax", { enumerable: true, get: function () { return string_utils_1.hasICUSyntax; } });
|
|
72
|
+
Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return string_utils_1.hashString; } });
|
|
73
|
+
Object.defineProperty(exports, "protectPlaceholders", { enumerable: true, get: function () { return string_utils_1.protectPlaceholders; } });
|
|
74
|
+
Object.defineProperty(exports, "restorePlaceholders", { enumerable: true, get: function () { return string_utils_1.restorePlaceholders; } });
|
|
75
|
+
var translation_sanitizer_1 = require("./utils/translation-sanitizer");
|
|
76
|
+
Object.defineProperty(exports, "sanitizeTranslation", { enumerable: true, get: function () { return translation_sanitizer_1.sanitizeTranslation; } });
|
|
77
|
+
Object.defineProperty(exports, "validateRawTokens", { enumerable: true, get: function () { return translation_sanitizer_1.validateRawTokens; } });
|
|
78
|
+
var placeholder_protection_1 = require("./utils/placeholder-protection");
|
|
79
|
+
Object.defineProperty(exports, "checkTokens", { enumerable: true, get: function () { return placeholder_protection_1.checkTokens; } });
|
|
80
|
+
Object.defineProperty(exports, "hasNothingToTranslate", { enumerable: true, get: function () { return placeholder_protection_1.hasNothingToTranslate; } });
|
|
81
|
+
Object.defineProperty(exports, "protectText", { enumerable: true, get: function () { return placeholder_protection_1.protectText; } });
|
|
82
|
+
Object.defineProperty(exports, "restoreText", { enumerable: true, get: function () { return placeholder_protection_1.restoreText; } });
|
|
83
|
+
Object.defineProperty(exports, "sameProtectedSpans", { enumerable: true, get: function () { return placeholder_protection_1.sameProtectedSpans; } });
|
|
84
|
+
var icu_message_1 = require("./utils/icu-message");
|
|
85
|
+
Object.defineProperty(exports, "compareIcuMessages", { enumerable: true, get: function () { return icu_message_1.compareIcuMessages; } });
|
|
86
|
+
Object.defineProperty(exports, "isIcuMessage", { enumerable: true, get: function () { return icu_message_1.isIcuMessage; } });
|
|
87
|
+
Object.defineProperty(exports, "parseIcu", { enumerable: true, get: function () { return icu_message_1.parseIcu; } });
|
|
88
|
+
Object.defineProperty(exports, "requiredPluralCategories", { enumerable: true, get: function () { return icu_message_1.requiredPluralCategories; } });
|
|
89
|
+
var translator_caller_1 = require("./utils/translator-caller");
|
|
90
|
+
Object.defineProperty(exports, "callTranslator", { enumerable: true, get: function () { return translator_caller_1.callTranslator; } });
|
|
91
|
+
Object.defineProperty(exports, "checkTranslatorHealth", { enumerable: true, get: function () { return translator_caller_1.checkTranslatorHealth; } });
|
|
92
|
+
Object.defineProperty(exports, "warmupTranslator", { enumerable: true, get: function () { return translator_caller_1.warmupTranslator; } });
|
|
93
|
+
var translator_load_balancer_1 = require("./utils/translator-load-balancer");
|
|
94
|
+
Object.defineProperty(exports, "translatorLoadBalancer", { enumerable: true, get: function () { return translator_load_balancer_1.translatorLoadBalancer; } });
|
|
95
|
+
var translation_quality_1 = require("./utils/translation-quality");
|
|
96
|
+
Object.defineProperty(exports, "validateTranslationQuality", { enumerable: true, get: function () { return translation_quality_1.validateTranslationQuality; } });
|
|
97
|
+
Object.defineProperty(exports, "validateBatchQuality", { enumerable: true, get: function () { return translation_quality_1.validateBatchQuality; } });
|
|
98
|
+
var circuit_breaker_1 = require("./utils/circuit-breaker");
|
|
99
|
+
Object.defineProperty(exports, "CircuitBreaker", { enumerable: true, get: function () { return circuit_breaker_1.CircuitBreaker; } });
|
|
100
|
+
Object.defineProperty(exports, "CircuitState", { enumerable: true, get: function () { return circuit_breaker_1.CircuitState; } });
|
|
101
|
+
Object.defineProperty(exports, "getCircuitBreaker", { enumerable: true, get: function () { return circuit_breaker_1.getCircuitBreaker; } });
|
|
102
|
+
var file_utils_1 = require("./utils/file-utils");
|
|
103
|
+
Object.defineProperty(exports, "localeExtension", { enumerable: true, get: function () { return file_utils_1.localeExtension; } });
|
|
104
|
+
// ── Local analysis and locale QA (no translation, no network) ──
|
|
105
|
+
var analyze_1 = require("./analysis/analyze");
|
|
106
|
+
Object.defineProperty(exports, "analyzeProject", { enumerable: true, get: function () { return analyze_1.analyzeProject; } });
|
|
107
|
+
Object.defineProperty(exports, "analyzeWorkspace", { enumerable: true, get: function () { return analyze_1.analyzeWorkspace; } });
|
|
108
|
+
Object.defineProperty(exports, "frameworkSupport", { enumerable: true, get: function () { return analyze_1.frameworkSupport; } });
|
|
109
|
+
var locale_qa_1 = require("./qa/locale-qa");
|
|
110
|
+
Object.defineProperty(exports, "checkLocalePair", { enumerable: true, get: function () { return locale_qa_1.checkLocalePair; } });
|
|
111
|
+
Object.defineProperty(exports, "flattenLocaleMessages", { enumerable: true, get: function () { return locale_qa_1.flattenLocaleMessages; } });
|
|
112
|
+
Object.defineProperty(exports, "tallyLocaleIssues", { enumerable: true, get: function () { return locale_qa_1.tallyLocaleIssues; } });
|
|
113
|
+
// Glossary rules: term matching, locale lookup/canonicalization, conflicts.
|
|
114
|
+
var glossary_1 = require("./modules/glossary");
|
|
115
|
+
Object.defineProperty(exports, "canonicalLocale", { enumerable: true, get: function () { return glossary_1.canonicalLocale; } });
|
|
116
|
+
Object.defineProperty(exports, "canonicalizeLocaleKeys", { enumerable: true, get: function () { return glossary_1.canonicalizeLocaleKeys; } });
|
|
117
|
+
Object.defineProperty(exports, "containsTerm", { enumerable: true, get: function () { return glossary_1.containsTerm; } });
|
|
118
|
+
Object.defineProperty(exports, "localeValue", { enumerable: true, get: function () { return glossary_1.localeValue; } });
|
|
119
|
+
Object.defineProperty(exports, "normalizeGlossary", { enumerable: true, get: function () { return glossary_1.normalizeGlossary; } });
|
|
120
|
+
Object.defineProperty(exports, "glossaryFingerprint", { enumerable: true, get: function () { return glossary_1.glossaryFingerprint; } });
|
|
121
|
+
var locale_files_1 = require("./qa/locale-files");
|
|
122
|
+
Object.defineProperty(exports, "DEFAULT_LOCALE_IGNORE_DIRS", { enumerable: true, get: function () { return locale_files_1.DEFAULT_LOCALE_IGNORE_DIRS; } });
|
|
123
|
+
Object.defineProperty(exports, "findLocaleFileSets", { enumerable: true, get: function () { return locale_files_1.findLocaleFileSets; } });
|
|
124
|
+
Object.defineProperty(exports, "groupLocaleFiles", { enumerable: true, get: function () { return locale_files_1.groupLocaleFiles; } });
|
|
125
|
+
Object.defineProperty(exports, "isIgnoredLocalePath", { enumerable: true, get: function () { return locale_files_1.isIgnoredLocalePath; } });
|
|
126
|
+
Object.defineProperty(exports, "isLocaleCode", { enumerable: true, get: function () { return locale_files_1.isLocaleCode; } });
|
|
127
|
+
Object.defineProperty(exports, "loadLocale", { enumerable: true, get: function () { return locale_files_1.loadLocale; } });
|
|
128
|
+
var review_1 = require("./qa/review");
|
|
129
|
+
Object.defineProperty(exports, "reviewLocaleChanges", { enumerable: true, get: function () { return review_1.reviewLocaleChanges; } });
|
|
130
|
+
Object.defineProperty(exports, "ReviewError", { enumerable: true, get: function () { return review_1.ReviewError; } });
|
|
131
|
+
var check_project_1 = require("./qa/check-project");
|
|
132
|
+
Object.defineProperty(exports, "checkProjectLocales", { enumerable: true, get: function () { return check_project_1.checkProjectLocales; } });
|
|
133
|
+
Object.defineProperty(exports, "localeIssueFile", { enumerable: true, get: function () { return check_project_1.localeIssueFile; } });
|
|
134
|
+
Object.defineProperty(exports, "readProjectLocaleConfig", { enumerable: true, get: function () { return check_project_1.readProjectLocaleConfig; } });
|
|
135
|
+
var cache_keys_1 = require("./utils/cache-keys");
|
|
136
|
+
Object.defineProperty(exports, "hashText", { enumerable: true, get: function () { return cache_keys_1.hashText; } });
|
|
137
|
+
Object.defineProperty(exports, "translationCacheKey", { enumerable: true, get: function () { return cache_keys_1.translationCacheKey; } });
|
|
138
|
+
Object.defineProperty(exports, "TRANSLATION_CACHE_TTL_SECONDS", { enumerable: true, get: function () { return cache_keys_1.TRANSLATION_CACHE_TTL_SECONDS; } });
|
|
139
|
+
// ── Local translation runner (CLI `babelize translate`, MCP `babelize_translate`) ──
|
|
140
|
+
__exportStar(require("./local"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import type { JsxMessage } from '../utils/jsx-message';
|
|
3
|
+
export interface MessageOptions {
|
|
4
|
+
/** Local name for react-i18next's Trans (`BabelizeTrans` when the file already binds `Trans`). */
|
|
5
|
+
transName?: string;
|
|
6
|
+
}
|
|
7
|
+
/** What a strategy renders for a JSX sentence message. */
|
|
8
|
+
export interface MessageRendering {
|
|
9
|
+
/** Replaces the element's children. */
|
|
10
|
+
node: t.JSXExpressionContainer | t.JSXElement;
|
|
11
|
+
/** Named imports the rendering needs, e.g. `Trans` from react-i18next (`local` when aliased). */
|
|
12
|
+
imports?: Array<{
|
|
13
|
+
source: string;
|
|
14
|
+
name: string;
|
|
15
|
+
local?: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export interface InjectionContext {
|
|
19
|
+
filePath: string;
|
|
20
|
+
isComponent: boolean;
|
|
21
|
+
hasUseClient: boolean;
|
|
22
|
+
/** The component the hook goes into is already `async` (set per component). */
|
|
23
|
+
isAsyncComponent?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface InjectionStrategy {
|
|
26
|
+
/**
|
|
27
|
+
* Framework identifier
|
|
28
|
+
*/
|
|
29
|
+
id: string;
|
|
30
|
+
/**
|
|
31
|
+
* Determine if an import is already present in the AST
|
|
32
|
+
*/
|
|
33
|
+
hasImport(ast: t.File): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Create the AST node for the import declaration
|
|
36
|
+
*/
|
|
37
|
+
createImport(context?: InjectionContext): t.ImportDeclaration;
|
|
38
|
+
/**
|
|
39
|
+
* Determine if the hook/setup is already present in the component body
|
|
40
|
+
*/
|
|
41
|
+
hasHook(componentPath: any): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Create the AST node(s) for the hook declaration
|
|
44
|
+
* Context allows handling async/await for server components
|
|
45
|
+
*/
|
|
46
|
+
createHook(context: InjectionContext): t.Statement[];
|
|
47
|
+
/**
|
|
48
|
+
* Return the identifier name used for translation (typically 't')
|
|
49
|
+
*/
|
|
50
|
+
getTranslationFunctionName(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Does the hook require the component function to be async?
|
|
53
|
+
*/
|
|
54
|
+
requiresAsyncComponent(context: InjectionContext): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Render a JSX sentence (named placeholders, inline tags) for `key`, e.g.
|
|
57
|
+
* `{t("key", { user })}`. Null when the strategy can't express it (rich
|
|
58
|
+
* text without a component API) — the sentence is then left as is and
|
|
59
|
+
* reported as not injected. Strategies without it render placeholders only.
|
|
60
|
+
*/
|
|
61
|
+
createMessage?(key: string, message: JsxMessage, options?: MessageOptions): MessageRendering | null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StrategyFactory = void 0;
|
|
4
|
+
const ReactI18nextStrategy_1 = require("./strategies/ReactI18nextStrategy");
|
|
5
|
+
const NextIntlStrategy_1 = require("./strategies/NextIntlStrategy");
|
|
6
|
+
const VanillaStrategy_1 = require("./strategies/VanillaStrategy");
|
|
7
|
+
const VueI18nStrategy_1 = require("./strategies/VueI18nStrategy");
|
|
8
|
+
class StrategyFactory {
|
|
9
|
+
static getStrategy(framework, existingDeps) {
|
|
10
|
+
if (existingDeps?.['react-i18next']) {
|
|
11
|
+
return new ReactI18nextStrategy_1.ReactI18nextStrategy();
|
|
12
|
+
}
|
|
13
|
+
if (existingDeps?.['next-intl']) {
|
|
14
|
+
return new NextIntlStrategy_1.NextIntlStrategy();
|
|
15
|
+
}
|
|
16
|
+
switch (framework) {
|
|
17
|
+
case 'nextjs':
|
|
18
|
+
return new NextIntlStrategy_1.NextIntlStrategy();
|
|
19
|
+
case 'react':
|
|
20
|
+
return new ReactI18nextStrategy_1.ReactI18nextStrategy();
|
|
21
|
+
case 'vue':
|
|
22
|
+
return new VueI18nStrategy_1.VueI18nStrategy();
|
|
23
|
+
case 'unknown':
|
|
24
|
+
default:
|
|
25
|
+
return new VanillaStrategy_1.VanillaStrategy();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.StrategyFactory = StrategyFactory;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FileInjection } from '../../runtime/types';
|
|
2
|
+
interface HtmlInjectOptions {
|
|
3
|
+
content: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
keyMapping: Map<string, string>;
|
|
6
|
+
injectSwitcher?: boolean;
|
|
7
|
+
targetLocales?: string[];
|
|
8
|
+
sourceLocale?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function injectHtml(options: HtmlInjectOptions): Promise<FileInjection>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.injectHtml = injectHtml;
|
|
37
|
+
const string_utils_1 = require("../../utils/string-utils");
|
|
38
|
+
const html_extractor_1 = require("../../utils/html-extractor");
|
|
39
|
+
function asElement(node) {
|
|
40
|
+
return node.nodeType === 1 ? node : null;
|
|
41
|
+
}
|
|
42
|
+
function walkHtmlNode(node, filePath, content, keyMapping, matchedIds, injections) {
|
|
43
|
+
const tagName = node.rawTagName?.toLowerCase();
|
|
44
|
+
if (!tagName)
|
|
45
|
+
return;
|
|
46
|
+
if (['script', 'style', 'noscript', 'code', 'pre', 'svg'].includes(tagName))
|
|
47
|
+
return;
|
|
48
|
+
const translatableAttrs = ['alt', 'title', 'placeholder', 'aria-label', 'aria-description'];
|
|
49
|
+
const children = node.childNodes || [];
|
|
50
|
+
let textChild = null;
|
|
51
|
+
let nonTextChild = false;
|
|
52
|
+
for (const child of children) {
|
|
53
|
+
if ((0, html_extractor_1.isTextNode)(child)) {
|
|
54
|
+
if (child.text.trim()) {
|
|
55
|
+
textChild = child;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
nonTextChild = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const element = asElement(node);
|
|
63
|
+
if (textChild && !nonTextChild && element && !element.getAttribute('data-i18n')) {
|
|
64
|
+
const text = textChild.text.trim();
|
|
65
|
+
if (node.range) {
|
|
66
|
+
const line = (content.slice(0, node.range[0]).match(/\n/g) || []).length + 1;
|
|
67
|
+
const id = `${filePath}:${line}:${(0, string_utils_1.hashString)(text)}`;
|
|
68
|
+
if (matchedIds.has(id)) {
|
|
69
|
+
const key = keyMapping.get(id);
|
|
70
|
+
if (key) {
|
|
71
|
+
element.setAttribute('data-i18n', key);
|
|
72
|
+
injections.push({
|
|
73
|
+
file: filePath,
|
|
74
|
+
line,
|
|
75
|
+
column: 0,
|
|
76
|
+
original: text,
|
|
77
|
+
replacement: `data-i18n="${key}"`,
|
|
78
|
+
key,
|
|
79
|
+
confidence: 100,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (nonTextChild && element && !element.getAttribute('data-i18n')) {
|
|
86
|
+
for (const child of children) {
|
|
87
|
+
if (!(0, html_extractor_1.isTextNode)(child) || !child.text.trim())
|
|
88
|
+
continue;
|
|
89
|
+
const text = child.text.trim();
|
|
90
|
+
if (node.range) {
|
|
91
|
+
const line = (content.slice(0, node.range[0]).match(/\n/g) || []).length + 1;
|
|
92
|
+
const id = `${filePath}:${line}:${(0, string_utils_1.hashString)(text)}`;
|
|
93
|
+
if (matchedIds.has(id)) {
|
|
94
|
+
const key = keyMapping.get(id);
|
|
95
|
+
if (key) {
|
|
96
|
+
element.setAttribute('data-i18n', key);
|
|
97
|
+
injections.push({
|
|
98
|
+
file: filePath,
|
|
99
|
+
line,
|
|
100
|
+
column: 0,
|
|
101
|
+
original: text,
|
|
102
|
+
replacement: `data-i18n="${key}"`,
|
|
103
|
+
key,
|
|
104
|
+
confidence: 100,
|
|
105
|
+
});
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!element)
|
|
113
|
+
return;
|
|
114
|
+
for (const attr of translatableAttrs) {
|
|
115
|
+
const value = element.getAttribute(attr);
|
|
116
|
+
if (!value)
|
|
117
|
+
continue;
|
|
118
|
+
if (element.getAttribute(`data-i18n-${attr}`))
|
|
119
|
+
continue;
|
|
120
|
+
if (!node.range)
|
|
121
|
+
continue;
|
|
122
|
+
const line = (content.slice(0, node.range[0]).match(/\n/g) || []).length + 1;
|
|
123
|
+
const id = `${filePath}:${line}:${(0, string_utils_1.hashString)(value)}`;
|
|
124
|
+
if (matchedIds.has(id)) {
|
|
125
|
+
const key = keyMapping.get(id);
|
|
126
|
+
if (key) {
|
|
127
|
+
element.setAttribute(`data-i18n-${attr}`, key);
|
|
128
|
+
injections.push({
|
|
129
|
+
file: filePath,
|
|
130
|
+
line,
|
|
131
|
+
column: 0,
|
|
132
|
+
original: value,
|
|
133
|
+
replacement: `data-i18n-${attr}="${key}"`,
|
|
134
|
+
key,
|
|
135
|
+
confidence: 100,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const child of children) {
|
|
141
|
+
if (child.nodeType === 1) {
|
|
142
|
+
walkHtmlNode(child, filePath, content, keyMapping, matchedIds, injections);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function injectHtml(options) {
|
|
147
|
+
const { content, filePath, keyMapping } = options;
|
|
148
|
+
const { parse } = await Promise.resolve().then(() => __importStar(require('node-html-parser')));
|
|
149
|
+
const injections = [];
|
|
150
|
+
let importAdded = false;
|
|
151
|
+
const root = parse(content, {
|
|
152
|
+
comment: false,
|
|
153
|
+
blockTextElements: { script: true, style: true, noscript: true, pre: true },
|
|
154
|
+
});
|
|
155
|
+
const htmlEl = root.querySelector('html');
|
|
156
|
+
if (!htmlEl) {
|
|
157
|
+
return { file: filePath, originalContent: content, modifiedContent: content, injections, importAdded, hookAdded: false };
|
|
158
|
+
}
|
|
159
|
+
const matchedIds = new Set(keyMapping.keys());
|
|
160
|
+
walkHtmlNode(htmlEl, filePath, content, keyMapping, matchedIds, injections);
|
|
161
|
+
let modifiedContent = root.toString();
|
|
162
|
+
const hasScript = /<script[^>]*src\s*=\s*["']i18n\.js["'][^>]*>/.test(modifiedContent);
|
|
163
|
+
if (!hasScript) {
|
|
164
|
+
if (modifiedContent.includes('</body>')) {
|
|
165
|
+
modifiedContent = modifiedContent.replace('</body>', ' <script src="i18n.js"></script>\n</body>');
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
modifiedContent = modifiedContent.replace('</head>', ' <script src="i18n.js"></script>\n</head>');
|
|
169
|
+
}
|
|
170
|
+
importAdded = true;
|
|
171
|
+
}
|
|
172
|
+
return { file: filePath, originalContent: content, modifiedContent, injections, importAdded, hookAdded: false };
|
|
173
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
import { InjectionStrategy, InjectionContext, MessageRendering } from '../InjectionStrategy';
|
|
3
|
+
import { type JsxMessage } from '../../utils/jsx-message';
|
|
4
|
+
export declare class NextIntlStrategy implements InjectionStrategy {
|
|
5
|
+
id: string;
|
|
6
|
+
hasImport(ast: t.File): boolean;
|
|
7
|
+
createImport(context: InjectionContext): t.ImportDeclaration;
|
|
8
|
+
hasHook(componentPath: any): boolean;
|
|
9
|
+
createHook(context: InjectionContext): t.Statement[];
|
|
10
|
+
getTranslationFunctionName(): string;
|
|
11
|
+
/**
|
|
12
|
+
* `{t("key", { user })}`, or with inline elements
|
|
13
|
+
* `{t.rich("key", { user, link: (chunks) => <Link href="/x">{chunks}</Link> })}`
|
|
14
|
+
* for the message "Hi {user}, read the <link>terms</link>". Works with both
|
|
15
|
+
* useTranslations() and await getTranslations().
|
|
16
|
+
*/
|
|
17
|
+
createMessage(key: string, message: JsxMessage): MessageRendering;
|
|
18
|
+
/**
|
|
19
|
+
* Never. An async component can't be rendered by a Client Component, and
|
|
20
|
+
* shared UI components often are. `useTranslations()` works in Server
|
|
21
|
+
* Components and client/shared ones as long as they aren't async, so only
|
|
22
|
+
* components that are already async get `await getTranslations()`.
|
|
23
|
+
*/
|
|
24
|
+
requiresAsyncComponent(_context?: InjectionContext): boolean;
|
|
25
|
+
}
|