@babelize/engine 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/LICENSE +202 -0
  2. package/dist/BabelizeEngine.d.ts +12 -0
  3. package/dist/BabelizeEngine.js +47 -0
  4. package/dist/analysis/analyze.d.ts +106 -0
  5. package/dist/analysis/analyze.js +323 -0
  6. package/dist/config/env.d.ts +9 -0
  7. package/dist/config/env.js +16 -0
  8. package/dist/config.d.ts +74 -0
  9. package/dist/config.js +47 -0
  10. package/dist/index.d.ts +54 -0
  11. package/dist/index.js +126 -0
  12. package/dist/injection/InjectionStrategy.d.ts +62 -0
  13. package/dist/injection/InjectionStrategy.js +2 -0
  14. package/dist/injection/StrategyFactory.d.ts +4 -0
  15. package/dist/injection/StrategyFactory.js +29 -0
  16. package/dist/injection/django/django-template-injector.d.ts +29 -0
  17. package/dist/injection/django/django-template-injector.js +216 -0
  18. package/dist/injection/html/html-injector.d.ts +11 -0
  19. package/dist/injection/html/html-injector.js +173 -0
  20. package/dist/injection/strategies/NextIntlStrategy.d.ts +25 -0
  21. package/dist/injection/strategies/NextIntlStrategy.js +141 -0
  22. package/dist/injection/strategies/ReactI18nextStrategy.d.ts +19 -0
  23. package/dist/injection/strategies/ReactI18nextStrategy.js +116 -0
  24. package/dist/injection/strategies/VanillaStrategy.d.ts +11 -0
  25. package/dist/injection/strategies/VanillaStrategy.js +73 -0
  26. package/dist/injection/strategies/VueI18nStrategy.d.ts +11 -0
  27. package/dist/injection/strategies/VueI18nStrategy.js +84 -0
  28. package/dist/local/formatter.d.ts +26 -0
  29. package/dist/local/formatter.js +105 -0
  30. package/dist/local/git.d.ts +23 -0
  31. package/dist/local/git.js +136 -0
  32. package/dist/local/hosted-provider.d.ts +68 -0
  33. package/dist/local/hosted-provider.js +215 -0
  34. package/dist/local/index.d.ts +23 -0
  35. package/dist/local/index.js +75 -0
  36. package/dist/local/provider.d.ts +56 -0
  37. package/dist/local/provider.js +119 -0
  38. package/dist/local/pseudo-provider.d.ts +18 -0
  39. package/dist/local/pseudo-provider.js +207 -0
  40. package/dist/local/report.d.ts +177 -0
  41. package/dist/local/report.js +186 -0
  42. package/dist/local/translate-core.d.ts +215 -0
  43. package/dist/local/translate-core.js +461 -0
  44. package/dist/local/translate-messages.d.ts +49 -0
  45. package/dist/local/translate-messages.js +91 -0
  46. package/dist/local/workspace-copy.d.ts +91 -0
  47. package/dist/local/workspace-copy.js +355 -0
  48. package/dist/modules/extractor/extract.d.ts +20 -0
  49. package/dist/modules/extractor/extract.js +701 -0
  50. package/dist/modules/extractor/index.d.ts +2 -0
  51. package/dist/modules/extractor/index.js +63 -0
  52. package/dist/modules/finalization/django-finalize.d.ts +13 -0
  53. package/dist/modules/finalization/django-finalize.js +275 -0
  54. package/dist/modules/finalization/finalize.d.ts +36 -0
  55. package/dist/modules/finalization/finalize.js +717 -0
  56. package/dist/modules/finalization/index.d.ts +1 -0
  57. package/dist/modules/finalization/index.js +5 -0
  58. package/dist/modules/finalization/nextjs-finalize.d.ts +37 -0
  59. package/dist/modules/finalization/nextjs-finalize.js +329 -0
  60. package/dist/modules/finalization/static-runtime.d.ts +9 -0
  61. package/dist/modules/finalization/static-runtime.js +261 -0
  62. package/dist/modules/format-injection/index.d.ts +19 -0
  63. package/dist/modules/format-injection/index.js +272 -0
  64. package/dist/modules/format-injection/inject-formats.d.ts +31 -0
  65. package/dist/modules/format-injection/inject-formats.js +208 -0
  66. package/dist/modules/glossary/glossary.d.ts +9 -0
  67. package/dist/modules/glossary/glossary.js +27 -0
  68. package/dist/modules/glossary/index.d.ts +3 -0
  69. package/dist/modules/glossary/index.js +8 -0
  70. package/dist/modules/glossary/masker.d.ts +23 -0
  71. package/dist/modules/glossary/masker.js +56 -0
  72. package/dist/modules/glossary/types.d.ts +22 -0
  73. package/dist/modules/glossary/types.js +2 -0
  74. package/dist/modules/injection/index.d.ts +1 -0
  75. package/dist/modules/injection/index.js +6 -0
  76. package/dist/modules/injection/inject.d.ts +29 -0
  77. package/dist/modules/injection/inject.js +1066 -0
  78. package/dist/modules/keygen/index.d.ts +1 -0
  79. package/dist/modules/keygen/index.js +11 -0
  80. package/dist/modules/keygen/keygen.d.ts +4 -0
  81. package/dist/modules/keygen/keygen.js +116 -0
  82. package/dist/modules/keygen/locale-data.d.ts +7 -0
  83. package/dist/modules/keygen/locale-data.js +73 -0
  84. package/dist/modules/keygen/public.d.ts +2 -0
  85. package/dist/modules/keygen/public.js +12 -0
  86. package/dist/modules/locale-builder/index.d.ts +1 -0
  87. package/dist/modules/locale-builder/index.js +7 -0
  88. package/dist/modules/locale-builder/locales.d.ts +13 -0
  89. package/dist/modules/locale-builder/locales.js +107 -0
  90. package/dist/modules/locale-builder/po.d.ts +33 -0
  91. package/dist/modules/locale-builder/po.js +131 -0
  92. package/dist/modules/lockfile/hasher.d.ts +7 -0
  93. package/dist/modules/lockfile/hasher.js +13 -0
  94. package/dist/modules/lockfile/index.d.ts +3 -0
  95. package/dist/modules/lockfile/index.js +21 -0
  96. package/dist/modules/lockfile/lockfile-manager.d.ts +90 -0
  97. package/dist/modules/lockfile/lockfile-manager.js +482 -0
  98. package/dist/modules/lockfile/schema.d.ts +154 -0
  99. package/dist/modules/lockfile/schema.js +45 -0
  100. package/dist/modules/parser/index.d.ts +2 -0
  101. package/dist/modules/parser/index.js +9 -0
  102. package/dist/modules/summary/index.d.ts +1 -0
  103. package/dist/modules/summary/index.js +7 -0
  104. package/dist/modules/summary/summary.d.ts +9 -0
  105. package/dist/modules/summary/summary.js +195 -0
  106. package/dist/modules/sync-detector/index.d.ts +2 -0
  107. package/dist/modules/sync-detector/index.js +7 -0
  108. package/dist/modules/sync-detector/reporter.d.ts +3 -0
  109. package/dist/modules/sync-detector/reporter.js +16 -0
  110. package/dist/modules/sync-detector/sync-detector.d.ts +39 -0
  111. package/dist/modules/sync-detector/sync-detector.js +374 -0
  112. package/dist/modules/translator/batch-optimizer.d.ts +12 -0
  113. package/dist/modules/translator/batch-optimizer.js +30 -0
  114. package/dist/modules/translator/client/byok.provider.d.ts +64 -0
  115. package/dist/modules/translator/client/byok.provider.js +319 -0
  116. package/dist/modules/translator/client/direct-translator.client.d.ts +12 -0
  117. package/dist/modules/translator/client/direct-translator.client.js +71 -0
  118. package/dist/modules/translator/client/gemini.provider.d.ts +1 -0
  119. package/dist/modules/translator/client/gemini.provider.js +110 -0
  120. package/dist/modules/translator/client/groq.provider.d.ts +1 -0
  121. package/dist/modules/translator/client/groq.provider.js +111 -0
  122. package/dist/modules/translator/client/request.types.d.ts +1 -0
  123. package/dist/modules/translator/client/request.types.js +2 -0
  124. package/dist/modules/translator/client/retry.d.ts +29 -0
  125. package/dist/modules/translator/client/retry.js +94 -0
  126. package/dist/modules/translator/client/test-utils/mock.client.d.ts +31 -0
  127. package/dist/modules/translator/client/test-utils/mock.client.js +59 -0
  128. package/dist/modules/translator/client/translator.interface.d.ts +1 -0
  129. package/dist/modules/translator/client/translator.interface.js +2 -0
  130. package/dist/modules/translator/language-codes/errors.d.ts +10 -0
  131. package/dist/modules/translator/language-codes/errors.js +18 -0
  132. package/dist/modules/translator/language-codes/flores-map.d.ts +1 -0
  133. package/dist/modules/translator/language-codes/flores-map.js +107 -0
  134. package/dist/modules/translator/language-codes/index.d.ts +11 -0
  135. package/dist/modules/translator/language-codes/index.js +24 -0
  136. package/dist/modules/translator/language-codes/language-mapper.d.ts +25 -0
  137. package/dist/modules/translator/language-codes/language-mapper.js +132 -0
  138. package/dist/modules/translator/language-codes/rtl-languages.d.ts +2 -0
  139. package/dist/modules/translator/language-codes/rtl-languages.js +9 -0
  140. package/dist/modules/translator/memory/memory-matcher.d.ts +8 -0
  141. package/dist/modules/translator/memory/memory-matcher.js +218 -0
  142. package/dist/modules/translator/memory/types.d.ts +22 -0
  143. package/dist/modules/translator/memory/types.js +2 -0
  144. package/dist/modules/translator/translate.d.ts +38 -0
  145. package/dist/modules/translator/translate.js +932 -0
  146. package/dist/modules/translator/translator.d.ts +5 -0
  147. package/dist/modules/translator/translator.js +46 -0
  148. package/dist/modules/vue/migrate.d.ts +13 -0
  149. package/dist/modules/vue/migrate.js +40 -0
  150. package/dist/modules/vue/script-inject.d.ts +16 -0
  151. package/dist/modules/vue/script-inject.js +115 -0
  152. package/dist/modules/vue/sfc.d.ts +11 -0
  153. package/dist/modules/vue/sfc.js +51 -0
  154. package/dist/modules/vue/template-rewrite.d.ts +25 -0
  155. package/dist/modules/vue/template-rewrite.js +76 -0
  156. package/dist/modules/vue/template-scan.d.ts +29 -0
  157. package/dist/modules/vue/template-scan.js +264 -0
  158. package/dist/modules/workspace/index.d.ts +1 -0
  159. package/dist/modules/workspace/index.js +5 -0
  160. package/dist/modules/workspace/validate.d.ts +13 -0
  161. package/dist/modules/workspace/validate.js +298 -0
  162. package/dist/orchestrator.d.ts +8 -0
  163. package/dist/orchestrator.js +616 -0
  164. package/dist/providers/default-translation-provider.d.ts +20 -0
  165. package/dist/providers/default-translation-provider.js +30 -0
  166. package/dist/providers/index.d.ts +2 -0
  167. package/dist/providers/index.js +21 -0
  168. package/dist/providers/types.d.ts +145 -0
  169. package/dist/providers/types.js +2 -0
  170. package/dist/qa/check-project.d.ts +49 -0
  171. package/dist/qa/check-project.js +150 -0
  172. package/dist/qa/locale-files.d.ts +44 -0
  173. package/dist/qa/locale-files.js +159 -0
  174. package/dist/qa/locale-qa.d.ts +61 -0
  175. package/dist/qa/locale-qa.js +325 -0
  176. package/dist/qa/review.d.ts +43 -0
  177. package/dist/qa/review.js +175 -0
  178. package/dist/runtime/config.d.ts +8 -0
  179. package/dist/runtime/config.js +36 -0
  180. package/dist/runtime/index.d.ts +3 -0
  181. package/dist/runtime/index.js +8 -0
  182. package/dist/runtime/types.d.ts +363 -0
  183. package/dist/runtime/types.js +38 -0
  184. package/dist/types.d.ts +134 -0
  185. package/dist/types.js +12 -0
  186. package/dist/utils/ast-helpers.d.ts +57 -0
  187. package/dist/utils/ast-helpers.js +608 -0
  188. package/dist/utils/cache-keys.d.ts +8 -0
  189. package/dist/utils/cache-keys.js +18 -0
  190. package/dist/utils/circuit-breaker.d.ts +43 -0
  191. package/dist/utils/circuit-breaker.js +119 -0
  192. package/dist/utils/concurrent-map.d.ts +4 -0
  193. package/dist/utils/concurrent-map.js +21 -0
  194. package/dist/utils/detect-format.d.ts +5 -0
  195. package/dist/utils/detect-format.js +125 -0
  196. package/dist/utils/dtl-mask.d.ts +25 -0
  197. package/dist/utils/dtl-mask.js +58 -0
  198. package/dist/utils/extraction-options.d.ts +23 -0
  199. package/dist/utils/extraction-options.js +23 -0
  200. package/dist/utils/file-utils.d.ts +33 -0
  201. package/dist/utils/file-utils.js +262 -0
  202. package/dist/utils/glossary-match.d.ts +9 -0
  203. package/dist/utils/glossary-match.js +25 -0
  204. package/dist/utils/html-extractor.d.ts +8 -0
  205. package/dist/utils/html-extractor.js +317 -0
  206. package/dist/utils/i18next-icu.d.ts +38 -0
  207. package/dist/utils/i18next-icu.js +159 -0
  208. package/dist/utils/icu-message.d.ts +65 -0
  209. package/dist/utils/icu-message.js +346 -0
  210. package/dist/utils/icu-spans.d.ts +10 -0
  211. package/dist/utils/icu-spans.js +126 -0
  212. package/dist/utils/jsx-message.d.ts +93 -0
  213. package/dist/utils/jsx-message.js +621 -0
  214. package/dist/utils/key-usage.d.ts +35 -0
  215. package/dist/utils/key-usage.js +247 -0
  216. package/dist/utils/logger.d.ts +24 -0
  217. package/dist/utils/logger.js +33 -0
  218. package/dist/utils/metadata.d.ts +80 -0
  219. package/dist/utils/metadata.js +255 -0
  220. package/dist/utils/module-constants.d.ts +30 -0
  221. package/dist/utils/module-constants.js +265 -0
  222. package/dist/utils/not-injected.d.ts +6 -0
  223. package/dist/utils/not-injected.js +36 -0
  224. package/dist/utils/placeholder-protection.d.ts +57 -0
  225. package/dist/utils/placeholder-protection.js +136 -0
  226. package/dist/utils/pseudo-markers.d.ts +9 -0
  227. package/dist/utils/pseudo-markers.js +16 -0
  228. package/dist/utils/py-extractor.d.ts +14 -0
  229. package/dist/utils/py-extractor.js +285 -0
  230. package/dist/utils/string-utils.d.ts +52 -0
  231. package/dist/utils/string-utils.js +270 -0
  232. package/dist/utils/translation-quality.d.ts +34 -0
  233. package/dist/utils/translation-quality.js +156 -0
  234. package/dist/utils/translation-sanitizer.d.ts +10 -0
  235. package/dist/utils/translation-sanitizer.js +57 -0
  236. package/dist/utils/translator-caller.d.ts +32 -0
  237. package/dist/utils/translator-caller.js +217 -0
  238. package/dist/utils/translator-load-balancer.d.ts +73 -0
  239. package/dist/utils/translator-load-balancer.js +293 -0
  240. package/dist/utils/ui-copy.d.ts +32 -0
  241. package/dist/utils/ui-copy.js +126 -0
  242. package/dist/utils/workspace.d.ts +14 -0
  243. package/dist/utils/workspace.js +89 -0
  244. package/package.json +64 -4
  245. package/schemas/translate-report.schema.json +297 -0
  246. package/README.md +0 -3
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Engine v2 runtime types (backend-facing).
3
+ *
4
+ * This file intentionally keeps the operational contract that the backend
5
+ * workers/controllers already rely on (stats/locales/injections/diffs), while
6
+ * allowing the v2 engine to add richer metrics needed for Target.md.
7
+ */
8
+ import type { ByokProvider, FormatLocaleConfig, Framework } from '@babelize/types';
9
+ import type { EngineProviders, TranslationFailure } from '../providers/types';
10
+ import type { EngineLogger } from '../utils/logger';
11
+ export interface EngineConfigV2 {
12
+ /** Path to the workspace directory */
13
+ workspacePath: string;
14
+ /** Source input type */
15
+ inputType: 'github' | 'zip';
16
+ /** Source locale code (e.g., 'en') */
17
+ sourceLocale: string;
18
+ /** Target locale codes (e.g., ['fr', 'de', 'es']) */
19
+ targetLocales: string[];
20
+ /** Detected or specified framework */
21
+ framework?: Framework;
22
+ /** Minimum confidence level for AST injection (0-100) */
23
+ confidenceThreshold: number;
24
+ /** If true, don't write any files - just return what would be changed */
25
+ dryRun: boolean;
26
+ /** Force translation even if locale files exist */
27
+ forceTranslation?: boolean;
28
+ /** Project ID for scoping lockfile/memory */
29
+ projectId?: string;
30
+ /**
31
+ * Directory holding `.babelize/<projectId>/babelize-lock.json`. Default:
32
+ * $BABELIZE_DATA_DIR, else the process cwd (the cloud backend). Local runs
33
+ * pass their temp copy, so concurrent runs never share global state.
34
+ */
35
+ dataDir?: string;
36
+ /** Logger for this run only (default: the one set with setEngineLogger). */
37
+ logger?: EngineLogger;
38
+ /** Callback for progress updates */
39
+ onProgress?: (message: string, step?: string, status?: 'running' | 'success' | 'error' | 'warning') => void;
40
+ /**
41
+ * Infrastructure the engine uses (translator, translation memory, project
42
+ * glossary/brand voice, cache). Anything omitted is simply not used.
43
+ */
44
+ providers?: EngineProviders;
45
+ /** BYOK (Bring Your Own Key) translation provider config */
46
+ byok?: {
47
+ provider: ByokProvider;
48
+ apiKey: string;
49
+ /** Optional model override (used by OpenRouter, Groq, etc.) */
50
+ model?: string;
51
+ };
52
+ /**
53
+ * Run the package manager when finalization adds i18n dependencies to
54
+ * package.json. Default true; local CLI runs pass false and tell the user
55
+ * to install instead.
56
+ */
57
+ installDependencies?: boolean;
58
+ /** Optional: only scan and process these specific files (e.g. for sync-triggered runs) */
59
+ filesToProcess?: string[];
60
+ /** Format localization config. null/undefined = skip format localization entirely. */
61
+ formatConfig?: FormatLocaleConfig;
62
+ /**
63
+ * What the run's translator can do. `icu`: translate ICU plural messages
64
+ * (an LLM provider). Defaults to true with BYOK or an injected translator,
65
+ * false for the NLLB service — then JSX sentences keep a plain `{count}`.
66
+ */
67
+ capabilities?: {
68
+ icu?: boolean;
69
+ };
70
+ /** Static HTML runtime options */
71
+ staticRuntime?: {
72
+ injectSwitcher?: boolean;
73
+ wrapMixedContent?: boolean;
74
+ };
75
+ }
76
+ export interface WorkspaceInfo {
77
+ path: string;
78
+ framework: Framework;
79
+ sourceDirs: string[];
80
+ hasLocalesDir: boolean;
81
+ existingLocales: string[];
82
+ publicDir: string;
83
+ packageJson?: Record<string, any>;
84
+ /** Output locale file format (e.g., 'json' for React, 'po' for Django) */
85
+ localeFormat: 'json' | 'po' | 'arb';
86
+ /** Format localization config propagated from EngineConfigV2 */
87
+ formatConfig?: FormatLocaleConfig;
88
+ /** Static HTML runtime options propagated from EngineConfigV2 */
89
+ staticRuntime?: {
90
+ injectSwitcher?: boolean;
91
+ wrapMixedContent?: boolean;
92
+ };
93
+ }
94
+ /**
95
+ * Frameworks that the engine pipeline will actively process.
96
+ * Runtime detection may produce other identifiers (e.g. 'unknown');
97
+ * those are validated against this list and rejected if not supported.
98
+ *
99
+ * @deprecated Import SUPPORTED_FRAMEWORKS from @babelize/types instead
100
+ */
101
+ export type FormatClass = 'currency' | 'date' | 'number' | 'unknown';
102
+ export interface DetectedFormat {
103
+ class: FormatClass;
104
+ rawValue: string;
105
+ originalString: string;
106
+ confidence: number;
107
+ detectedCurrency?: string;
108
+ dateOptions?: Intl.DateTimeFormatOptions;
109
+ dateSource?: string;
110
+ numberOptions?: Intl.NumberFormatOptions;
111
+ }
112
+ export interface ExtractedString {
113
+ text: string;
114
+ file: string;
115
+ line: number;
116
+ column: number;
117
+ context: 'jsx-text' | 'jsx-attr' | 'string-literal' | 'template-literal' | 'hardcoded-date' | 'hardcoded-currency' | 'format-string';
118
+ id: string;
119
+ variables?: string[];
120
+ parentContext?: string;
121
+ siblingGroupId?: string;
122
+ detectedFormat?: DetectedFormat;
123
+ /**
124
+ * A whole JSX sentence (text + `{expressions}` + inline elements) as one ICU
125
+ * message with named placeholders, rich-text tags and possibly a plural.
126
+ * Keys are named from its words only, and the message carries its own
127
+ * plural forms (no `_one`/`_other` key variants).
128
+ */
129
+ icuMessage?: boolean;
130
+ /**
131
+ * Source offsets of every node this id stands for. Injection replaces
132
+ * exactly these nodes (not others with the same text on the same line).
133
+ */
134
+ offsets?: number[];
135
+ }
136
+ export interface ExtractionResult {
137
+ strings: ExtractedString[];
138
+ filesAnalyzed: string[];
139
+ skippedFiles: SkippedFile[];
140
+ warnings?: Warning[];
141
+ /** UI strings found but deliberately not extracted (e.g. module-level constants that are also data). */
142
+ notInjected?: NotInjectedString[];
143
+ }
144
+ export interface GeneratedKey {
145
+ key: string;
146
+ namespace: string;
147
+ value: string;
148
+ extractionId: string;
149
+ isPlural?: boolean;
150
+ pluralCategory?: 'zero' | 'one' | 'two' | 'few' | 'many' | 'other';
151
+ parentContext?: string;
152
+ extractionContext?: string;
153
+ }
154
+ export interface KeyGenerationResult {
155
+ keys: GeneratedKey[];
156
+ duplicates: Array<{
157
+ original: string;
158
+ renamed: string;
159
+ }>;
160
+ }
161
+ export interface LocaleData {
162
+ [key: string]: string | LocaleData;
163
+ }
164
+ export interface LocaleFile {
165
+ locale: string;
166
+ path: string;
167
+ data: LocaleData;
168
+ isNew: boolean;
169
+ isRTL?: boolean;
170
+ }
171
+ export interface LocaleHandlingResult {
172
+ sourceLocale: LocaleFile;
173
+ newKeysCount: number;
174
+ existingKeysCount: number;
175
+ }
176
+ export interface TranslationEntry {
177
+ key: string;
178
+ value: string;
179
+ confidence?: number;
180
+ engine?: string;
181
+ warnings?: string[];
182
+ parentContext?: string;
183
+ extractionContext?: string;
184
+ }
185
+ export interface TranslationRequest {
186
+ sourceLang: string;
187
+ targetLang: string;
188
+ entries: TranslationEntry[];
189
+ }
190
+ export interface TranslationResponse {
191
+ translations: TranslationEntry[];
192
+ metadata?: {
193
+ dictVersion?: string;
194
+ processingTimeMs?: number;
195
+ dictionaryHits?: number;
196
+ modelTranslations?: number;
197
+ };
198
+ }
199
+ export interface TranslationResult {
200
+ locales: LocaleFile[];
201
+ errors: Array<{
202
+ locale: string;
203
+ error: string;
204
+ }>;
205
+ /** Keys with no translation for a locale this run (not written, retried next run). */
206
+ failures?: TranslationFailure[];
207
+ }
208
+ export interface InjectionLocation {
209
+ file: string;
210
+ line: number;
211
+ column: number;
212
+ original: string;
213
+ replacement: string;
214
+ key: string;
215
+ confidence: number;
216
+ formatClass?: string;
217
+ }
218
+ export interface FileInjection {
219
+ file: string;
220
+ originalContent: string;
221
+ modifiedContent: string;
222
+ injections: InjectionLocation[];
223
+ importAdded: boolean;
224
+ hookAdded: boolean;
225
+ }
226
+ export interface InjectionResult {
227
+ modifiedFiles: FileInjection[];
228
+ skippedFiles: SkippedFile[];
229
+ totalInjections: number;
230
+ }
231
+ export interface SkippedFile {
232
+ file: string;
233
+ reason: 'syntax-error' | 'low-confidence' | 'already-translated' | 'binary' | 'excluded' | 'parse-error' | 'format-injection-failed' | 'format-ast-build-failed';
234
+ details?: string;
235
+ }
236
+ export interface Warning {
237
+ type: 'low-confidence' | 'duplicate-key' | 'complex-expression' | 'dynamic-string' | 'malformed-ast' | 'parse-warning' | 'hardcoded-currency' | 'hardcoded-date' | 'hardcoded-plural' | 'ambiguous-format' | 'overflow' | 'rtl';
238
+ file: string;
239
+ line?: number;
240
+ key?: string;
241
+ locale?: string;
242
+ severity?: 'warning' | 'critical';
243
+ dismissible?: boolean;
244
+ message: string;
245
+ }
246
+ export interface DiffMetadata {
247
+ file: string;
248
+ changeType: 'created' | 'modified';
249
+ linesAdded: number;
250
+ linesRemoved: number;
251
+ diff?: string;
252
+ }
253
+ export interface ProcessingStats {
254
+ filesScanned: number;
255
+ filesWithStrings: number;
256
+ stringsExtracted: number;
257
+ keysGenerated: number;
258
+ filesModified: number;
259
+ injectionsApplied: number;
260
+ localeFilesCreated: number;
261
+ processingTimeMs: number;
262
+ stringsNeedingTranslation?: number;
263
+ translationsFromMemory?: number;
264
+ translationsFromLockfile?: number;
265
+ translationsFromHF?: number;
266
+ /** True when engine ran with a project-scoped lockfile */
267
+ lockfileUsed?: boolean;
268
+ /** Keys sent to the translator (new + source-changed + missing locale) */
269
+ lockfileKeysTranslated?: number;
270
+ /** Keys whose source text changed vs the lockfile */
271
+ lockfileKeysChanged?: number;
272
+ /**
273
+ * (key, locale) translations the translator actually produced this run —
274
+ * the billable work. Excludes lockfile, translation-memory and cache reuse,
275
+ * and failed keys.
276
+ */
277
+ translatedThisRun?: number;
278
+ }
279
+ export interface NotInjectedString {
280
+ file: string;
281
+ key: string;
282
+ text: string;
283
+ reason: string;
284
+ }
285
+ export interface KeyUsageReport {
286
+ /**
287
+ * Source-locale keys that no code references any more (and weren't
288
+ * extracted this run). Not translated, not deleted.
289
+ */
290
+ unused: string[];
291
+ /**
292
+ * Files with translation calls whose key isn't a literal. When non-empty,
293
+ * every key is treated as live and `unused` is empty.
294
+ */
295
+ dynamicFiles: string[];
296
+ }
297
+ export interface EngineResultV2 {
298
+ success: boolean;
299
+ error?: string;
300
+ /**
301
+ * Keys that could not be translated, per locale, with the reason. They are
302
+ * absent from the locale files and the lockfile, so the next run retries
303
+ * them. Never filled with source text.
304
+ */
305
+ translationFailures?: TranslationFailure[];
306
+ stats: ProcessingStats;
307
+ locales: LocaleFile[];
308
+ injections: InjectionResult;
309
+ warnings: Warning[];
310
+ skipped: SkippedFile[];
311
+ diffs: DiffMetadata[];
312
+ /**
313
+ * Human-readable notes from finalization (dependencies added to
314
+ * package.json, i18n config created, ...) that need the user's attention.
315
+ */
316
+ notes?: string[];
317
+ /** Which source keys are still used (lockfile runs only). */
318
+ keyUsage?: KeyUsageReport;
319
+ /**
320
+ * Strings that were extracted and got a key (and translations) but could
321
+ * not be wired into the code, so the literal is still there.
322
+ */
323
+ notInjected?: NotInjectedString[];
324
+ results?: {
325
+ source: Record<string, string>;
326
+ targets: Record<string, Record<string, string>>;
327
+ metadata?: Record<string, Record<string, any>>;
328
+ };
329
+ }
330
+ export interface Phase0Result {
331
+ workspace: WorkspaceInfo;
332
+ }
333
+ export interface Phase1Result {
334
+ extraction: ExtractionResult;
335
+ }
336
+ export interface Phase2Result {
337
+ keyGeneration: KeyGenerationResult;
338
+ }
339
+ export interface Phase3Result {
340
+ localeHandling: LocaleHandlingResult;
341
+ }
342
+ export interface Phase4Result {
343
+ translation: TranslationResult;
344
+ }
345
+ export interface Phase5Result {
346
+ injection: InjectionResult;
347
+ }
348
+ export interface Phase6Result {
349
+ stats: ProcessingStats;
350
+ warnings: Warning[];
351
+ diffs: DiffMetadata[];
352
+ }
353
+ export interface Phase7Result {
354
+ finalization: {
355
+ dependenciesInvalid: boolean;
356
+ configFileCreated: boolean;
357
+ entryPointModified: boolean;
358
+ warnings: string[];
359
+ };
360
+ }
361
+ export declare const SUPPORTED_EXTENSIONS: string[];
362
+ export declare const EXCLUDED_PATTERNS: string[];
363
+ export declare const JSX_TRANSLATABLE_ATTRS: string[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * Engine v2 runtime types (backend-facing).
4
+ *
5
+ * This file intentionally keeps the operational contract that the backend
6
+ * workers/controllers already rely on (stats/locales/injections/diffs), while
7
+ * allowing the v2 engine to add richer metrics needed for Target.md.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.JSX_TRANSLATABLE_ATTRS = exports.EXCLUDED_PATTERNS = exports.SUPPORTED_EXTENSIONS = void 0;
11
+ // ============ Constants ============
12
+ exports.SUPPORTED_EXTENSIONS = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.html'];
13
+ exports.EXCLUDED_PATTERNS = [
14
+ 'node_modules',
15
+ '.git',
16
+ '.next',
17
+ 'dist',
18
+ 'build',
19
+ 'coverage',
20
+ '__tests__',
21
+ 'vendor',
22
+ 'lib',
23
+ 'libs',
24
+ '*.test.*',
25
+ '*.spec.*',
26
+ '*.d.ts',
27
+ '*.min.js',
28
+ '*.min.css',
29
+ ];
30
+ exports.JSX_TRANSLATABLE_ATTRS = [
31
+ 'title',
32
+ 'placeholder',
33
+ 'alt',
34
+ 'aria-label',
35
+ 'aria-description',
36
+ 'label',
37
+ 'description',
38
+ ];
@@ -0,0 +1,134 @@
1
+ import type { z } from 'zod';
2
+ import type { Framework } from '@babelize/types';
3
+ export declare const ISO639_1_REGEX: RegExp;
4
+ export interface BabelizeConfig {
5
+ /** Workspace path */
6
+ workspacePath: string;
7
+ /** Source locale (ISO 639-1) */
8
+ sourceLocale: string;
9
+ /** Target locales (ISO 639-1) */
10
+ targetLocales: string[];
11
+ /** Optional framework hint (otherwise auto-detected by extractor later) */
12
+ framework?: Framework;
13
+ /** If true, do not write files or open PRs */
14
+ dryRun?: boolean;
15
+ /** Project id (used for translation memory scoping) */
16
+ projectId?: string;
17
+ /** Optional path overrides */
18
+ sourceDir?: string;
19
+ localesDir?: string;
20
+ /** Glossary */
21
+ glossary?: GlossaryConfig;
22
+ /** Lockfile path */
23
+ lockfilePath?: string;
24
+ }
25
+ export type BabelizeConfigSchema = z.ZodType<BabelizeConfig>;
26
+ export interface GlossaryConfig {
27
+ neverTranslate?: string[];
28
+ alwaysTranslateAs?: Array<{
29
+ term: string;
30
+ translations: Record<string, string>;
31
+ }>;
32
+ }
33
+ export type ExtractedStringContext = 'jsx-text' | 'jsx-attr' | 'string-literal' | 'template-literal' | 'hardcoded-date' | 'hardcoded-currency';
34
+ export interface ExtractedString {
35
+ id: string;
36
+ text: string;
37
+ filePath: string;
38
+ line: number;
39
+ column: number;
40
+ context: ExtractedStringContext;
41
+ }
42
+ export interface TranslationUnit {
43
+ sourceText: string;
44
+ sourceLocale: string;
45
+ targetLocale: string;
46
+ /** Masked text sent to model (after glossary masking), if applicable */
47
+ maskedSourceText?: string;
48
+ }
49
+ export interface TranslationResult {
50
+ sourceText: string;
51
+ sourceLocale: string;
52
+ targetLocale: string;
53
+ translatedText: string;
54
+ /** "memory" | "hf" | "lockfile" */
55
+ provider: 'memory' | 'hf' | 'lockfile';
56
+ model?: string;
57
+ }
58
+ export interface BabelRunStats {
59
+ stringsExtracted: number;
60
+ stringsNeedingTranslation: number;
61
+ translationsFromMemory: number;
62
+ translationsFromLockfile: number;
63
+ translationsFromHF: number;
64
+ }
65
+ export interface BabelRunResult {
66
+ success: boolean;
67
+ error?: string;
68
+ stats: BabelRunStats;
69
+ warnings: any[];
70
+ }
71
+ export interface FileSystem {
72
+ readFile(filePath: string): Promise<string>;
73
+ writeFile(filePath: string, contents: string): Promise<void>;
74
+ exists(filePath: string): Promise<boolean>;
75
+ listDir(dirPath: string): Promise<string[]>;
76
+ mkdir(dirPath: string): Promise<void>;
77
+ deleteFile(filePath: string): Promise<void>;
78
+ }
79
+ export interface Cache {
80
+ get(key: string): Promise<string | null>;
81
+ set(key: string, value: string, ttlSeconds?: number): Promise<void>;
82
+ delete(key: string): Promise<void>;
83
+ invalidate(prefix: string): Promise<void>;
84
+ }
85
+ export interface GitHubProvider {
86
+ openPR(params: {
87
+ title: string;
88
+ body: string;
89
+ head: string;
90
+ base: string;
91
+ }): Promise<string>;
92
+ }
93
+ export interface TranslatorClient {
94
+ health(): Promise<boolean>;
95
+ warmup(): Promise<boolean>;
96
+ translate(req: HFTranslateRequest): Promise<HFTranslateResponse>;
97
+ }
98
+ export interface BabelizeEngineDependencies {
99
+ fs: FileSystem;
100
+ translatorClient: TranslatorClient;
101
+ cache?: Cache;
102
+ github?: GitHubProvider;
103
+ }
104
+ export interface HFTranslateRequest {
105
+ entries: Array<{
106
+ key: string;
107
+ value: string;
108
+ context?: string;
109
+ extractionContext?: string;
110
+ }>;
111
+ sourceLang: string;
112
+ targetLang: string;
113
+ /** Optional brand voice guideline for BYOK LLM providers */
114
+ brandVoice?: string;
115
+ /** Target locale as ISO code (keeps regional variants such as pt-BR). */
116
+ targetLocale?: string;
117
+ /** Required terminology: source term → translation. */
118
+ glossary?: Array<{
119
+ term: string;
120
+ translation: string;
121
+ }>;
122
+ /** Per-key notes for a repair attempt. */
123
+ hints?: Record<string, string>;
124
+ }
125
+ export interface HFTranslateResponse {
126
+ translations: Array<{
127
+ key?: string;
128
+ value: string;
129
+ }>;
130
+ model?: string;
131
+ metadata?: any;
132
+ }
133
+ export type { Phase7Result } from './runtime/types';
134
+ export { SUPPORTED_EXTENSIONS, EXCLUDED_PATTERNS, JSX_TRANSLATABLE_ATTRS, } from './runtime/types';
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSX_TRANSLATABLE_ATTRS = exports.EXCLUDED_PATTERNS = exports.SUPPORTED_EXTENSIONS = exports.ISO639_1_REGEX = void 0;
4
+ // ─────────────────────────────────────────────────────────────
5
+ // Config
6
+ // ─────────────────────────────────────────────────────────────
7
+ exports.ISO639_1_REGEX = /^[a-z]{2}$/;
8
+ // Re-export constants from runtime/types (single source of truth)
9
+ var types_1 = require("./runtime/types");
10
+ Object.defineProperty(exports, "SUPPORTED_EXTENSIONS", { enumerable: true, get: function () { return types_1.SUPPORTED_EXTENSIONS; } });
11
+ Object.defineProperty(exports, "EXCLUDED_PATTERNS", { enumerable: true, get: function () { return types_1.EXCLUDED_PATTERNS; } });
12
+ Object.defineProperty(exports, "JSX_TRANSLATABLE_ATTRS", { enumerable: true, get: function () { return types_1.JSX_TRANSLATABLE_ATTRS; } });
@@ -0,0 +1,57 @@
1
+ import type { NodePath } from '@babel/traverse';
2
+ import generate from '@babel/generator';
3
+ import traverse from '@babel/traverse';
4
+ import * as t from '@babel/types';
5
+ /**
6
+ * Engine v2 AST helpers.
7
+ *
8
+ * Copied from v1 to preserve parsing/transformation behavior while v2 is
9
+ * stabilized.
10
+ */
11
+ export interface ParseOptions {
12
+ sourceType?: 'module' | 'script' | 'unambiguous';
13
+ isTypeScript?: boolean;
14
+ isJSX?: boolean;
15
+ filename?: string;
16
+ }
17
+ export declare function parseCode(code: string, options?: ParseOptions): t.File;
18
+ export declare function generateCode(ast: t.File, originalCode?: string): string;
19
+ /**
20
+ * With `retainLines`, statements the injector adds (which have no source
21
+ * location) are printed on the line of the preceding token, e.g.
22
+ * `function Page() {const t = useTranslations();`. Move each such statement
23
+ * that directly follows a `{` onto its own line, indented like the body.
24
+ */
25
+ export declare function placeStatementsOnOwnLines(code: string, statements: string[]): string;
26
+ export declare function isJSXText(node: t.Node): node is t.JSXText;
27
+ export declare function isAlreadyTranslated(node: t.Node, path: NodePath): boolean;
28
+ export declare function isNonTranslatableContext(path: NodePath): boolean;
29
+ export declare function getComponentName(path: NodePath): string | null;
30
+ export declare function isInsideComponent(path: NodePath): boolean;
31
+ /**
32
+ * The block body of the component `path` is in — where the translation hook
33
+ * goes. Skips callbacks (a hook inside `.map(…)` breaks the rules of hooks);
34
+ * null when there's no component with a block body.
35
+ */
36
+ export declare function findComponentBody(path: NodePath): NodePath | null;
37
+ export declare function hasTranslationImport(ast: t.File): boolean;
38
+ export declare function hasTranslationHook(functionPath: NodePath): boolean;
39
+ export declare function createTranslationImport(): t.ImportDeclaration;
40
+ export declare function createTranslationHook(): t.VariableDeclaration;
41
+ export declare function createTCall(key: string): t.CallExpression;
42
+ export declare function createJSXTCall(key: string): t.JSXExpressionContainer;
43
+ export declare function extractJSXTextContent(node: t.JSXText): string;
44
+ export declare function getParentContext(path: NodePath): {
45
+ parentContext: string;
46
+ siblingGroupId: string;
47
+ } | null;
48
+ export declare function extractExpressionContent(node: t.Node, variables?: string[]): string | null;
49
+ export declare function extractConditionalContent(node: t.ConditionalExpression): {
50
+ consequent: string | null;
51
+ alternate: string | null;
52
+ };
53
+ /**
54
+ * Check if the file has a 'use client' directive
55
+ */
56
+ export declare function hasUseClientDirective(ast: t.File): boolean;
57
+ export { generate, t, traverse };