@babelize/engine 0.3.7 → 0.3.8
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/index.d.ts +2 -0
- package/dist/index.js +11 -1
- package/dist/local/hosted-provider.js +1 -0
- package/dist/local/translate-core.d.ts +13 -2
- package/dist/local/translate-core.js +27 -9
- package/dist/local/translate-messages.d.ts +5 -0
- package/dist/local/translate-messages.js +1 -1
- package/dist/modules/finalization/nextjs-finalize.d.ts +19 -2
- package/dist/modules/finalization/nextjs-finalize.js +46 -4
- 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/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/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 +21 -1
- package/dist/types.d.ts +2 -0
- package/dist/utils/translator-caller.d.ts +19 -0
- package/dist/utils/translator-caller.js +55 -21
- package/package.json +2 -2
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babelize/engine",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
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",
|