@babelize/engine 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/analyze.d.ts +3 -0
- package/dist/analysis/analyze.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +16 -1
- package/dist/local/hosted-provider.js +1 -0
- package/dist/local/translate-core.d.ts +19 -2
- package/dist/local/translate-core.js +28 -9
- package/dist/local/translate-messages.d.ts +5 -0
- package/dist/local/translate-messages.js +1 -1
- package/dist/modules/extractor/extract.js +22 -5
- package/dist/modules/finalization/finalize.d.ts +6 -0
- package/dist/modules/finalization/finalize.js +25 -5
- package/dist/modules/finalization/nextjs-finalize.d.ts +63 -6
- package/dist/modules/finalization/nextjs-finalize.js +339 -26
- package/dist/modules/format-injection/index.js +3 -2
- package/dist/modules/injection/inject.js +2 -1
- package/dist/modules/locale-builder/adopted.d.ts +29 -2
- package/dist/modules/locale-builder/adopted.js +185 -16
- package/dist/modules/locale-builder/locales.js +11 -2
- package/dist/modules/locale-builder/message-modules.d.ts +40 -0
- package/dist/modules/locale-builder/message-modules.js +263 -0
- package/dist/modules/sync-detector/sync-detector.js +4 -1
- package/dist/modules/translator/client/byok.provider.js +8 -2
- package/dist/modules/translator/formality.d.ts +40 -0
- package/dist/modules/translator/formality.js +313 -0
- package/dist/modules/translator/translate.d.ts +18 -0
- package/dist/modules/translator/translate.js +78 -11
- package/dist/modules/workspace/existing-setup.d.ts +3 -1
- package/dist/modules/workspace/existing-setup.js +32 -15
- package/dist/modules/workspace/validate.js +7 -0
- package/dist/orchestrator.js +51 -7
- package/dist/providers/default-translation-provider.js +2 -2
- package/dist/providers/types.d.ts +5 -0
- package/dist/qa/check-project.d.ts +7 -0
- package/dist/qa/check-project.js +12 -2
- package/dist/qa/locale-files.d.ts +8 -5
- package/dist/qa/locale-files.js +37 -9
- package/dist/qa/locale-qa.d.ts +10 -1
- package/dist/qa/locale-qa.js +9 -0
- package/dist/qa/review.js +1 -1
- package/dist/runtime/types.d.ts +29 -1
- package/dist/types.d.ts +2 -0
- package/dist/utils/ast-helpers.js +35 -4
- package/dist/utils/source-scope.d.ts +30 -0
- package/dist/utils/source-scope.js +112 -0
- package/dist/utils/translator-caller.d.ts +19 -0
- package/dist/utils/translator-caller.js +55 -21
- package/dist/utils/ui-copy.d.ts +14 -0
- package/dist/utils/ui-copy.js +51 -0
- package/package.json +4 -2
package/dist/types.d.ts
CHANGED
|
@@ -114,6 +114,8 @@ export interface HFTranslateRequest {
|
|
|
114
114
|
brandVoice?: string;
|
|
115
115
|
/** Target locale as ISO code (keeps regional variants such as pt-BR). */
|
|
116
116
|
targetLocale?: string;
|
|
117
|
+
/** Form of address in the target language; undefined means auto. */
|
|
118
|
+
formality?: 'formal' | 'informal';
|
|
117
119
|
/** Required terminology: source term → translation. */
|
|
118
120
|
glossary?: Array<{
|
|
119
121
|
term: string;
|
|
@@ -831,6 +831,35 @@ function getParentContext(path) {
|
|
|
831
831
|
siblingGroupId: Math.abs(hash).toString(36),
|
|
832
832
|
};
|
|
833
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* A readable placeholder for an interpolated value, so translators and
|
|
836
|
+
* reviewers see `{locale}` rather than `{var1}` (#379): the identifier or
|
|
837
|
+
* property, or for a call the function's subject (`getLocaleLabel(l)` →
|
|
838
|
+
* `localeLabel`, `format(price)` → `price`).
|
|
839
|
+
*/
|
|
840
|
+
function placeholderName(expr) {
|
|
841
|
+
if (t.isIdentifier(expr))
|
|
842
|
+
return expr.name;
|
|
843
|
+
if ((t.isMemberExpression(expr) || t.isOptionalMemberExpression(expr)) && t.isIdentifier(expr.property) && !expr.computed)
|
|
844
|
+
return expr.property.name;
|
|
845
|
+
if (t.isCallExpression(expr) || t.isOptionalCallExpression(expr)) {
|
|
846
|
+
const callee = expr.callee;
|
|
847
|
+
const arg = expr.arguments[0];
|
|
848
|
+
const method = (t.isMemberExpression(callee) || t.isOptionalMemberExpression(callee)) && t.isIdentifier(callee.property) ? callee.property.name : null;
|
|
849
|
+
const fn = t.isIdentifier(callee) ? callee.name : method;
|
|
850
|
+
const subject = fn?.replace(/^(?:get|format|render|compute)(?=[A-Z])/, '');
|
|
851
|
+
if (subject && subject !== fn)
|
|
852
|
+
return subject[0].toLowerCase() + subject.slice(1);
|
|
853
|
+
// `fmt.format(price)` names its argument; `count.toFixed(1)` or `name.trim()` its receiver.
|
|
854
|
+
if (method && method !== 'format')
|
|
855
|
+
return placeholderName(callee.object);
|
|
856
|
+
if (arg)
|
|
857
|
+
return placeholderName(arg);
|
|
858
|
+
}
|
|
859
|
+
if (t.isTSAsExpression(expr) || t.isTSNonNullExpression(expr))
|
|
860
|
+
return placeholderName(expr.expression);
|
|
861
|
+
return null;
|
|
862
|
+
}
|
|
834
863
|
/**
|
|
835
864
|
* A string-building expression as one message: `\`Hi ${user.name}\`` and
|
|
836
865
|
* `'Hi ' + name` → "Hi {name}". `variables` receives the placeholder names
|
|
@@ -844,9 +873,7 @@ function extractExpressionContent(node, variables = [], expressions = []) {
|
|
|
844
873
|
let result = '';
|
|
845
874
|
const quasis = node.quasis;
|
|
846
875
|
const exprs = node.expressions;
|
|
847
|
-
const nameOf = (expr) =>
|
|
848
|
-
: t.isMemberExpression(expr) && t.isIdentifier(expr.property) ? expr.property.name
|
|
849
|
-
: `var${variables.length}`;
|
|
876
|
+
const nameOf = (expr) => placeholderName(expr) ?? `var${variables.length}`;
|
|
850
877
|
for (let i = 0; i < quasis.length; i++) {
|
|
851
878
|
// The text as it runs (`\n` is a line break), not as it's escaped in the source.
|
|
852
879
|
result += quasis[i].value.cooked ?? quasis[i].value.raw;
|
|
@@ -872,7 +899,11 @@ function extractExpressionContent(node, variables = [], expressions = []) {
|
|
|
872
899
|
+ `{${name}, plural, one {${hash}${word[1]}${suffix.one}} other {${hash}${word[1]}${suffix.other}}}`;
|
|
873
900
|
continue;
|
|
874
901
|
}
|
|
875
|
-
|
|
902
|
+
// Two different values never share a placeholder: `${a.name} and ${b.name}` → {name}, {name2}.
|
|
903
|
+
let varName = nameOf(expr);
|
|
904
|
+
const base = varName;
|
|
905
|
+
for (let n = 2; variables.some((v, j) => v === varName && !t.isNodesEquivalent(expressions[j], expr)); n++)
|
|
906
|
+
varName = `${base}${n}`;
|
|
876
907
|
variables.push(varName);
|
|
877
908
|
expressions.push(expr);
|
|
878
909
|
result += `{${varName}}`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which source files a run may extract from and rewrite, as globs relative to
|
|
3
|
+
* the workspace root (`src/app/**`, `src/registry`). From `.babelize/config.json`
|
|
4
|
+
* `include`/`exclude`, or `--include`/`--exclude` (#378). Files outside it are
|
|
5
|
+
* never read for strings or injected into, on top of the built-in exclusions.
|
|
6
|
+
*/
|
|
7
|
+
export interface SourceScope {
|
|
8
|
+
/** Only these paths (default: every source file). */
|
|
9
|
+
include?: string[];
|
|
10
|
+
/** Never these paths, even when included. */
|
|
11
|
+
exclude?: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Glob lists from config or flags: non-empty strings, `./` and trailing `/`
|
|
15
|
+
* dropped. A plain path (`src/registry`) also covers everything under it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function normalizeScopePatterns(value: unknown): string[] | undefined;
|
|
18
|
+
/** `include`/`exclude` from `.babelize/config.json`; missing or malformed is no scope. */
|
|
19
|
+
export declare function readSourceScope(workspacePath: string): Promise<SourceScope>;
|
|
20
|
+
/** The config's scope with each list given by the caller (flags) replacing the config's. */
|
|
21
|
+
export declare function mergeSourceScope(config: SourceScope, override?: SourceScope): SourceScope;
|
|
22
|
+
/** Whether `scope` limits anything. */
|
|
23
|
+
export declare function hasSourceScope(scope: SourceScope | undefined): boolean;
|
|
24
|
+
/** A test for workspace-relative paths (either separator). No scope: everything is in. */
|
|
25
|
+
export declare function createScopeMatcher(scope: SourceScope | undefined): (relPath: string) => boolean;
|
|
26
|
+
/** `files` (absolute) inside the workspace's scope. */
|
|
27
|
+
export declare function filterToScope(workspace: {
|
|
28
|
+
path: string;
|
|
29
|
+
sourceScope?: SourceScope;
|
|
30
|
+
}, files: string[]): string[];
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.normalizeScopePatterns = normalizeScopePatterns;
|
|
40
|
+
exports.readSourceScope = readSourceScope;
|
|
41
|
+
exports.mergeSourceScope = mergeSourceScope;
|
|
42
|
+
exports.hasSourceScope = hasSourceScope;
|
|
43
|
+
exports.createScopeMatcher = createScopeMatcher;
|
|
44
|
+
exports.filterToScope = filterToScope;
|
|
45
|
+
const fs_1 = require("fs");
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const picomatch_1 = __importDefault(require("picomatch"));
|
|
48
|
+
/**
|
|
49
|
+
* Glob lists from config or flags: non-empty strings, `./` and trailing `/`
|
|
50
|
+
* dropped. A plain path (`src/registry`) also covers everything under it.
|
|
51
|
+
*/
|
|
52
|
+
function normalizeScopePatterns(value) {
|
|
53
|
+
if (!Array.isArray(value))
|
|
54
|
+
return undefined;
|
|
55
|
+
const patterns = value
|
|
56
|
+
.filter((p) => typeof p === 'string')
|
|
57
|
+
.map((p) => p.trim().replace(/\\/g, '/').replace(/^\.\//, '').replace(/\/+$/, ''))
|
|
58
|
+
.filter((p) => p.length > 0 && p !== '.');
|
|
59
|
+
return patterns.length > 0 ? patterns : undefined;
|
|
60
|
+
}
|
|
61
|
+
function expand(patterns) {
|
|
62
|
+
return patterns.flatMap((p) => (picomatch_1.default.scan(p).isGlob ? [p] : [p, `${p}/**`]));
|
|
63
|
+
}
|
|
64
|
+
/** `include`/`exclude` from `.babelize/config.json`; missing or malformed is no scope. */
|
|
65
|
+
async function readSourceScope(workspacePath) {
|
|
66
|
+
let raw;
|
|
67
|
+
try {
|
|
68
|
+
raw = JSON.parse(await fs_1.promises.readFile(path.join(workspacePath, '.babelize', 'config.json'), 'utf8'));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
if (!raw || typeof raw !== 'object')
|
|
74
|
+
return {};
|
|
75
|
+
const { include, exclude } = raw;
|
|
76
|
+
return compactScope({ include: normalizeScopePatterns(include), exclude: normalizeScopePatterns(exclude) });
|
|
77
|
+
}
|
|
78
|
+
/** The config's scope with each list given by the caller (flags) replacing the config's. */
|
|
79
|
+
function mergeSourceScope(config, override = {}) {
|
|
80
|
+
return compactScope({
|
|
81
|
+
include: normalizeScopePatterns(override.include) ?? config.include,
|
|
82
|
+
exclude: normalizeScopePatterns(override.exclude) ?? config.exclude,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function compactScope(scope) {
|
|
86
|
+
return {
|
|
87
|
+
...(scope.include ? { include: scope.include } : {}),
|
|
88
|
+
...(scope.exclude ? { exclude: scope.exclude } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** Whether `scope` limits anything. */
|
|
92
|
+
function hasSourceScope(scope) {
|
|
93
|
+
return !!(scope?.include?.length || scope?.exclude?.length);
|
|
94
|
+
}
|
|
95
|
+
/** A test for workspace-relative paths (either separator). No scope: everything is in. */
|
|
96
|
+
function createScopeMatcher(scope) {
|
|
97
|
+
if (!hasSourceScope(scope))
|
|
98
|
+
return () => true;
|
|
99
|
+
const included = scope.include?.length ? (0, picomatch_1.default)(expand(scope.include), { dot: true }) : () => true;
|
|
100
|
+
const excluded = scope.exclude?.length ? (0, picomatch_1.default)(expand(scope.exclude), { dot: true }) : () => false;
|
|
101
|
+
return (relPath) => {
|
|
102
|
+
const rel = relPath.replace(/\\/g, '/').replace(/^\.\//, '');
|
|
103
|
+
return included(rel) && !excluded(rel);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** `files` (absolute) inside the workspace's scope. */
|
|
107
|
+
function filterToScope(workspace, files) {
|
|
108
|
+
if (!hasSourceScope(workspace.sourceScope))
|
|
109
|
+
return files;
|
|
110
|
+
const inScope = createScopeMatcher(workspace.sourceScope);
|
|
111
|
+
return files.filter((file) => inScope(path.relative(workspace.path, file)));
|
|
112
|
+
}
|
|
@@ -3,6 +3,7 @@ import type { ByokProvider } from '@babelize/types';
|
|
|
3
3
|
/** Options only LLM (BYOK) providers use; the NLLB service ignores them. */
|
|
4
4
|
export interface LlmRequestOptions {
|
|
5
5
|
targetLocale?: string;
|
|
6
|
+
formality?: 'formal' | 'informal';
|
|
6
7
|
glossary?: Array<{
|
|
7
8
|
term: string;
|
|
8
9
|
translation: string;
|
|
@@ -24,6 +25,24 @@ export declare function callTranslator(entries: TranslationEntry[], sourceLang:
|
|
|
24
25
|
translations: TranslationEntry[];
|
|
25
26
|
metadata?: any;
|
|
26
27
|
}>;
|
|
28
|
+
/** Pauses before asking the translator again for entries it left out. */
|
|
29
|
+
export declare const MISSING_RETRY_DELAYS_MS: number[];
|
|
30
|
+
/**
|
|
31
|
+
* When its model call fails, the translator service still answers, with only
|
|
32
|
+
* the entries it resolved from its dictionary ("Features", "Log in"). That
|
|
33
|
+
* failure comes and goes, so ask again — twice, after a pause — for just the
|
|
34
|
+
* entries that are missing. A retry that fails keeps what we already have.
|
|
35
|
+
*/
|
|
36
|
+
export declare function retryMissingEntries(entries: TranslationEntry[], first: {
|
|
37
|
+
translations: TranslationEntry[];
|
|
38
|
+
metadata?: any;
|
|
39
|
+
}, request: (batch: TranslationEntry[]) => Promise<{
|
|
40
|
+
translations: TranslationEntry[];
|
|
41
|
+
metadata?: any;
|
|
42
|
+
}>, signal?: AbortSignal, delaysMs?: number[]): Promise<{
|
|
43
|
+
translations: TranslationEntry[];
|
|
44
|
+
metadata?: any;
|
|
45
|
+
}>;
|
|
27
46
|
export declare function checkTranslatorHealth(byokConfig?: {
|
|
28
47
|
provider: ByokProvider;
|
|
29
48
|
apiKey: string;
|
|
@@ -33,7 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MISSING_RETRY_DELAYS_MS = void 0;
|
|
36
37
|
exports.callTranslator = callTranslator;
|
|
38
|
+
exports.retryMissingEntries = retryMissingEntries;
|
|
37
39
|
exports.checkTranslatorHealth = checkTranslatorHealth;
|
|
38
40
|
exports.warmupTranslator = warmupTranslator;
|
|
39
41
|
const logger_1 = require("./logger");
|
|
@@ -51,28 +53,30 @@ async function callTranslator(entries, sourceLang, targetLang, byokConfig, brand
|
|
|
51
53
|
const outerSignal = llmOptions.signal;
|
|
52
54
|
const { translatorLoadBalancer } = await Promise.resolve().then(() => __importStar(require('./translator-load-balancer')));
|
|
53
55
|
let rustResult = null;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
signal: outerSignal ? AbortSignal.any([AbortSignal.timeout(300000), outerSignal]) : AbortSignal.timeout(300000),
|
|
61
|
-
});
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
throw new Error(`Translation API error: ${response.status} ${response.statusText}`);
|
|
64
|
-
}
|
|
65
|
-
const data = await response.json();
|
|
66
|
-
if (data.metadata) {
|
|
67
|
-
logger_1.engineLogger.info('Translation metadata', {
|
|
68
|
-
dictVersion: data.metadata.dictVersion,
|
|
69
|
-
processingTimeMs: data.metadata.processingTimeMs,
|
|
70
|
-
dictionaryHits: data.metadata.dictionaryHits,
|
|
71
|
-
modelTranslations: data.metadata.modelTranslations,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return { translations: data.translations || [], metadata: data.metadata };
|
|
56
|
+
const requestRust = (batch) => translatorLoadBalancer.executeWithFailover(async (translatorUrl) => {
|
|
57
|
+
const response = await fetch(`${translatorUrl}/translate`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: { 'Content-Type': 'application/json' },
|
|
60
|
+
body: JSON.stringify({ sourceLang, targetLang, entries: batch }),
|
|
61
|
+
signal: outerSignal ? AbortSignal.any([AbortSignal.timeout(300000), outerSignal]) : AbortSignal.timeout(300000),
|
|
75
62
|
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(`Translation API error: ${response.status} ${response.statusText}`);
|
|
65
|
+
}
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
if (data.metadata) {
|
|
68
|
+
logger_1.engineLogger.info('Translation metadata', {
|
|
69
|
+
dictVersion: data.metadata.dictVersion,
|
|
70
|
+
processingTimeMs: data.metadata.processingTimeMs,
|
|
71
|
+
dictionaryHits: data.metadata.dictionaryHits,
|
|
72
|
+
modelTranslations: data.metadata.modelTranslations,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return { translations: (data.translations || []), metadata: data.metadata };
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
rustResult = await requestRust(entries);
|
|
79
|
+
rustResult = await retryMissingEntries(entries, rustResult, requestRust, outerSignal);
|
|
76
80
|
}
|
|
77
81
|
catch (err) {
|
|
78
82
|
logger_1.engineLogger.warn('Rust translator unavailable, will try HF Inference API fallback', {
|
|
@@ -109,6 +113,36 @@ async function callTranslator(entries, sourceLang, targetLang, byokConfig, brand
|
|
|
109
113
|
logger_1.engineLogger.error(`Translator unavailable for ${sourceLang} → ${targetLang}; no translations produced`);
|
|
110
114
|
return { translations: [], metadata: { translatorUnavailable: true } };
|
|
111
115
|
}
|
|
116
|
+
/** Pauses before asking the translator again for entries it left out. */
|
|
117
|
+
exports.MISSING_RETRY_DELAYS_MS = [1000, 3000];
|
|
118
|
+
/**
|
|
119
|
+
* When its model call fails, the translator service still answers, with only
|
|
120
|
+
* the entries it resolved from its dictionary ("Features", "Log in"). That
|
|
121
|
+
* failure comes and goes, so ask again — twice, after a pause — for just the
|
|
122
|
+
* entries that are missing. A retry that fails keeps what we already have.
|
|
123
|
+
*/
|
|
124
|
+
async function retryMissingEntries(entries, first, request, signal, delaysMs = exports.MISSING_RETRY_DELAYS_MS) {
|
|
125
|
+
let result = first;
|
|
126
|
+
for (const delayMs of delaysMs) {
|
|
127
|
+
const have = new Set(result.translations.map((t) => t.key));
|
|
128
|
+
const missing = entries.filter((e) => !have.has(e.key));
|
|
129
|
+
if (missing.length === 0 || signal?.aborted)
|
|
130
|
+
break;
|
|
131
|
+
logger_1.engineLogger.warn('Translator left entries out of its response; asking again for them', { missing: missing.length, of: entries.length, delayMs });
|
|
132
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
133
|
+
let retry;
|
|
134
|
+
try {
|
|
135
|
+
retry = await request(missing);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
logger_1.engineLogger.warn('Retry for missing entries failed', { error: err instanceof Error ? err.message : String(err) });
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
const wanted = new Set(missing.map((e) => e.key));
|
|
142
|
+
result = { ...result, translations: [...result.translations, ...retry.translations.filter((t) => wanted.has(t.key))] };
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
112
146
|
async function callByokTranslator(entries, sourceLang, targetLang, byokConfig, brandVoice, llmOptions = {}) {
|
|
113
147
|
const client = new byok_provider_1.BYOKTranslatorClient(byokConfig);
|
|
114
148
|
const { signal, ...promptOptions } = llmOptions;
|
package/dist/utils/ui-copy.d.ts
CHANGED
|
@@ -31,3 +31,17 @@ export declare function isUiCopyForName(name: string | null, text: string): bool
|
|
|
31
31
|
* returns, conditionals, …) aren't initializers and are left as they are.
|
|
32
32
|
*/
|
|
33
33
|
export declare function isUiCopyLiteral(node: t.Node, parent: t.Node | null | undefined, text: string): boolean;
|
|
34
|
+
export declare function isDirectionValue(text: string): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Every string in a string-literal union type declared in `ast`
|
|
37
|
+
* (`type Mode = "native" | "english"`, `dir?: "ltr" | "rtl"`). Code that
|
|
38
|
+
* assigns, returns or defaults to one of these is choosing an option, not
|
|
39
|
+
* showing copy; translating it breaks the type and the comparison (#379).
|
|
40
|
+
*/
|
|
41
|
+
export declare function literalUnionMembers(ast: t.Node): Set<string>;
|
|
42
|
+
/**
|
|
43
|
+
* `<LanguageSwitcher label="native" />`: one lowercase token given to a
|
|
44
|
+
* component (not a DOM element) is one of its options, like `variant` or
|
|
45
|
+
* `size`, not copy. Labels people read are capitalized or several words.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isComponentOptionValue(attribute: t.JSXAttribute, element: t.JSXOpeningElement, text: string): boolean;
|
package/dist/utils/ui-copy.js
CHANGED
|
@@ -38,6 +38,9 @@ exports.isMultiWordCopy = isMultiWordCopy;
|
|
|
38
38
|
exports.looksLikeCopy = looksLikeCopy;
|
|
39
39
|
exports.isUiCopyForName = isUiCopyForName;
|
|
40
40
|
exports.isUiCopyLiteral = isUiCopyLiteral;
|
|
41
|
+
exports.isDirectionValue = isDirectionValue;
|
|
42
|
+
exports.literalUnionMembers = literalUnionMembers;
|
|
43
|
+
exports.isComponentOptionValue = isComponentOptionValue;
|
|
41
44
|
const t = __importStar(require("@babel/types"));
|
|
42
45
|
/**
|
|
43
46
|
* UI copy vs program data in object / array / variable initializers.
|
|
@@ -129,3 +132,51 @@ function isUiCopyLiteral(node, parent, text) {
|
|
|
129
132
|
return looksLikeCopy(text);
|
|
130
133
|
return true;
|
|
131
134
|
}
|
|
135
|
+
/** Text direction (`dir`, `direction`): compared and passed on, never shown (#379). */
|
|
136
|
+
const DIRECTION_VALUES = new Set(['ltr', 'rtl', 'auto']);
|
|
137
|
+
function isDirectionValue(text) {
|
|
138
|
+
return DIRECTION_VALUES.has(text.trim());
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Every string in a string-literal union type declared in `ast`
|
|
142
|
+
* (`type Mode = "native" | "english"`, `dir?: "ltr" | "rtl"`). Code that
|
|
143
|
+
* assigns, returns or defaults to one of these is choosing an option, not
|
|
144
|
+
* showing copy; translating it breaks the type and the comparison (#379).
|
|
145
|
+
*/
|
|
146
|
+
function literalUnionMembers(ast) {
|
|
147
|
+
const members = new Set();
|
|
148
|
+
const visit = (node) => {
|
|
149
|
+
if (!node || typeof node !== 'object')
|
|
150
|
+
return;
|
|
151
|
+
if (Array.isArray(node)) {
|
|
152
|
+
for (const child of node)
|
|
153
|
+
visit(child);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const n = node;
|
|
157
|
+
if (t.isTSUnionType(n)) {
|
|
158
|
+
for (const type of n.types) {
|
|
159
|
+
if (t.isTSLiteralType(type) && t.isStringLiteral(type.literal))
|
|
160
|
+
members.add(type.literal.value);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (const key of t.VISITOR_KEYS[n.type] ?? [])
|
|
164
|
+
visit(n[key]);
|
|
165
|
+
};
|
|
166
|
+
visit(ast);
|
|
167
|
+
return members;
|
|
168
|
+
}
|
|
169
|
+
/** Props whose value is always shown, even as one lowercase word (`alt="logo"`). */
|
|
170
|
+
const SHOWN_PROP = /^(?:alt|placeholder|title|aria-.+|accessibility.+)$/;
|
|
171
|
+
/**
|
|
172
|
+
* `<LanguageSwitcher label="native" />`: one lowercase token given to a
|
|
173
|
+
* component (not a DOM element) is one of its options, like `variant` or
|
|
174
|
+
* `size`, not copy. Labels people read are capitalized or several words.
|
|
175
|
+
*/
|
|
176
|
+
function isComponentOptionValue(attribute, element, text) {
|
|
177
|
+
if (!t.isJSXIdentifier(attribute.name) || SHOWN_PROP.test(attribute.name.name))
|
|
178
|
+
return false;
|
|
179
|
+
const tag = element.name;
|
|
180
|
+
const isComponent = t.isJSXMemberExpression(tag) || (t.isJSXIdentifier(tag) && /^[A-Z]/.test(tag.name));
|
|
181
|
+
return isComponent && /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(text.trim());
|
|
182
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babelize/engine",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"description": "Babelize translation pipeline (extract, keygen, translate, inject). Infrastructure is injected through provider/store interfaces.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babelize",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/parser": "^7.28.5",
|
|
33
33
|
"@babel/traverse": "^7.28.5",
|
|
34
34
|
"@babel/types": "^7.29.8",
|
|
35
|
-
"@babelize/types": "^0.1.
|
|
35
|
+
"@babelize/types": "^0.1.5",
|
|
36
36
|
"@vue/compiler-dom": "^3.5",
|
|
37
37
|
"@vue/compiler-sfc": "^3.5",
|
|
38
38
|
"diff": "^8.0.4",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"gettext-parser": "^9.1.1",
|
|
42
42
|
"magic-string": "^0.30",
|
|
43
43
|
"node-html-parser": "^8.0.4",
|
|
44
|
+
"picomatch": "^2.3.2",
|
|
44
45
|
"recast": "^0.23",
|
|
45
46
|
"zod": "^4.6.6"
|
|
46
47
|
},
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"@types/fs-extra": "^11.0.4",
|
|
53
54
|
"@types/jest": "^30.0.0",
|
|
54
55
|
"@types/node": "^25.0.3",
|
|
56
|
+
"@types/picomatch": "^2.3.4",
|
|
55
57
|
"ajv": "^8.17.1",
|
|
56
58
|
"eslint": "^9.39.2",
|
|
57
59
|
"intl-messageformat": "^10.7.16",
|