@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,136 @@
|
|
|
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.GitError = void 0;
|
|
37
|
+
exports.isBabelizeReportFile = isBabelizeReportFile;
|
|
38
|
+
exports.isGitIgnored = isGitIgnored;
|
|
39
|
+
exports.assertGitRepo = assertGitRepo;
|
|
40
|
+
exports.getUncommittedChanges = getUncommittedChanges;
|
|
41
|
+
exports.assertCleanTree = assertCleanTree;
|
|
42
|
+
const node_child_process_1 = require("node:child_process");
|
|
43
|
+
const promises_1 = require("node:fs/promises");
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const node_util_1 = require("node:util");
|
|
46
|
+
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
47
|
+
/**
|
|
48
|
+
* True when `file` is a Babelize translate report: JSON whose first field is
|
|
49
|
+
* `"$schema": "https://babelize.co/schemas/translate-report.v…"`, wherever it
|
|
50
|
+
* was written (`--report <path>`). Identified by content, not by name.
|
|
51
|
+
*/
|
|
52
|
+
async function isBabelizeReportFile(file) {
|
|
53
|
+
if (!file.endsWith('.json'))
|
|
54
|
+
return false;
|
|
55
|
+
let handle;
|
|
56
|
+
try {
|
|
57
|
+
handle = await (0, promises_1.open)(file, 'r');
|
|
58
|
+
const buf = Buffer.alloc(256);
|
|
59
|
+
const { bytesRead } = await handle.read(buf, 0, buf.length, 0);
|
|
60
|
+
return REPORT_HEAD.test(buf.subarray(0, bytesRead).toString('utf8'));
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await handle?.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const REPORT_HEAD = /^\s*\{\s*"\$schema"\s*:\s*"https:\/\/babelize\.co\/schemas\/translate-report\.v\d+\.json"/;
|
|
70
|
+
/** Whether `rel` (relative to `dir`) is git-ignored. */
|
|
71
|
+
async function isGitIgnored(dir, rel) {
|
|
72
|
+
try {
|
|
73
|
+
await git(dir, ['check-ignore', '-q', '--', rel]);
|
|
74
|
+
return true; // exit 0 = ignored
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class GitError extends Error {
|
|
81
|
+
constructor(message, code, dirtyFiles = []) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.code = code;
|
|
84
|
+
this.dirtyFiles = dirtyFiles;
|
|
85
|
+
this.name = 'GitError';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.GitError = GitError;
|
|
89
|
+
async function git(cwd, args) {
|
|
90
|
+
const { stdout } = await execFileAsync('git', args, { cwd, maxBuffer: 64 * 1024 * 1024 });
|
|
91
|
+
return stdout;
|
|
92
|
+
}
|
|
93
|
+
/** Throws GitError('not_a_repo' | 'git_missing') unless `dir` is inside a git work tree. */
|
|
94
|
+
async function assertGitRepo(dir) {
|
|
95
|
+
try {
|
|
96
|
+
const out = await git(dir, ['rev-parse', '--is-inside-work-tree']);
|
|
97
|
+
if (out.trim() !== 'true')
|
|
98
|
+
throw new Error('not inside a work tree');
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (err.code === 'ENOENT') {
|
|
102
|
+
throw new GitError('git is not installed or not on PATH.', 'git_missing');
|
|
103
|
+
}
|
|
104
|
+
throw new GitError('Not a git repository. `babelize translate` writes into your working tree so you can review the result with `git diff` — run it inside a git repo (or `git init` first).', 'not_a_repo');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Uncommitted changes under `dir` (tracked edits and untracked files), as porcelain lines. */
|
|
108
|
+
async function getUncommittedChanges(dir) {
|
|
109
|
+
const out = await git(dir, ['status', '--porcelain', '--untracked-files=all', '--', '.']);
|
|
110
|
+
return out.split('\n').filter((line) => line.trim().length > 0);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Refuse to run on a dirty tree unless `force`: the result has to be reviewable
|
|
114
|
+
* as its own `git diff`, and a failed review has to be undoable with
|
|
115
|
+
* `git checkout . && git clean -fd` without losing the user's work.
|
|
116
|
+
*/
|
|
117
|
+
async function assertCleanTree(dir, force) {
|
|
118
|
+
// The QA report of an earlier run (default or --report path) is not the user's work.
|
|
119
|
+
const changes = await getUncommittedChanges(dir);
|
|
120
|
+
const root = changes.some((l) => l.startsWith('?? ')) ? (await git(dir, ['rev-parse', '--show-toplevel'])).trim() : dir;
|
|
121
|
+
const dirty = [];
|
|
122
|
+
for (const line of changes) {
|
|
123
|
+
// Porcelain paths are relative to the repository root; quoted ones (unusual characters) are kept as dirty.
|
|
124
|
+
const untracked = /^\?\? ([^"].*)$/.exec(line);
|
|
125
|
+
if (untracked && (await isBabelizeReportFile(path.join(root, untracked[1]))))
|
|
126
|
+
continue;
|
|
127
|
+
dirty.push(line);
|
|
128
|
+
}
|
|
129
|
+
if (dirty.length > 0 && !force) {
|
|
130
|
+
const preview = dirty.slice(0, 10).map((l) => ` ${l}`).join('\n');
|
|
131
|
+
const more = dirty.length > 10 ? `\n … and ${dirty.length - 10} more` : '';
|
|
132
|
+
throw new GitError(`Your working tree has uncommitted changes:\n${preview}${more}\n` +
|
|
133
|
+
'Commit or stash them first so the translation shows up as its own reviewable `git diff`, or re-run with --force.', 'dirty', dirty);
|
|
134
|
+
}
|
|
135
|
+
return dirty;
|
|
136
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { KeyResult, TranslationBatchRequest, TranslationProvider } from '../providers/types';
|
|
2
|
+
/**
|
|
3
|
+
* Babelize-hosted translation for `babelize translate`: a TranslationProvider
|
|
4
|
+
* that sends the engine's already placeholder-protected strings (never code)
|
|
5
|
+
* to POST {apiUrl}/v1/translate/batch with a Babelize API key. The engine
|
|
6
|
+
* still validates every result and runs its repair retry locally; model,
|
|
7
|
+
* quota and credits are decided by the server.
|
|
8
|
+
*/
|
|
9
|
+
/** Server limit on entries per request. */
|
|
10
|
+
export declare const HOSTED_MAX_BATCH: 100;
|
|
11
|
+
/**
|
|
12
|
+
* Per-attempt timeout. Longer than the server's total model budget (90 s),
|
|
13
|
+
* so the server finishes — or gives up uncharged — before we retry.
|
|
14
|
+
*/
|
|
15
|
+
export declare const HOSTED_REQUEST_TIMEOUT_MS = 150000;
|
|
16
|
+
/** Response header naming the model that served a batch. */
|
|
17
|
+
export declare const HOSTED_MODEL_HEADER = "x-babelize-model";
|
|
18
|
+
export declare const API_KEYS_URL = "https://app.babelize.co/api-keys";
|
|
19
|
+
export declare const BILLING_URL = "https://app.babelize.co/billing";
|
|
20
|
+
export type HostedErrorCode =
|
|
21
|
+
/** 401/403: the key is missing, wrong or revoked. */
|
|
22
|
+
'hosted_auth'
|
|
23
|
+
/** 402: the account is out of AI credits. */
|
|
24
|
+
| 'hosted_credits'
|
|
25
|
+
/** 429 after the bounded retries. */
|
|
26
|
+
| 'hosted_rate_limited'
|
|
27
|
+
/** 503 hosted translation off, 5xx or network failure after retries. */
|
|
28
|
+
| 'hosted_unavailable'
|
|
29
|
+
/** 400: the server rejected the request. */
|
|
30
|
+
| 'hosted_bad_request';
|
|
31
|
+
export declare class HostedTranslationError extends Error {
|
|
32
|
+
readonly code: HostedErrorCode;
|
|
33
|
+
readonly status?: number | undefined;
|
|
34
|
+
constructor(message: string, code: HostedErrorCode, status?: number | undefined);
|
|
35
|
+
/** Errors after which no further request can succeed in this run. */
|
|
36
|
+
get fatal(): boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface HostedProviderOptions {
|
|
39
|
+
/** Babelize API key (bblz_sk_…). Never printed. */
|
|
40
|
+
apiKey: string;
|
|
41
|
+
/** e.g. https://api.babelize.co/api */
|
|
42
|
+
apiUrl: string;
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
/** Retries after a 429/5xx/network error (default 3). */
|
|
45
|
+
maxRetries?: number;
|
|
46
|
+
/** Cap on a single Retry-After wait (default 60 s). */
|
|
47
|
+
maxRetryAfterMs?: number;
|
|
48
|
+
/** Backoff base when the server gives no Retry-After (default 1 s). */
|
|
49
|
+
baseDelayMs?: number;
|
|
50
|
+
sleep?: (ms: number) => Promise<void>;
|
|
51
|
+
/** Per-attempt timeout (default HOSTED_REQUEST_TIMEOUT_MS). */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
/** Sent as User-Agent. */
|
|
54
|
+
userAgent?: string;
|
|
55
|
+
}
|
|
56
|
+
export declare function parseRetryAfterMs(value: string | null): number | undefined;
|
|
57
|
+
export declare class HostedTranslationProvider implements TranslationProvider {
|
|
58
|
+
/** Model the server reported (X-Babelize-Model), once a request succeeded. */
|
|
59
|
+
model?: string;
|
|
60
|
+
/** Set once a request fails in a way no retry can fix (bad key, no credits). */
|
|
61
|
+
fatalError?: HostedTranslationError;
|
|
62
|
+
private readonly opts;
|
|
63
|
+
constructor(options: HostedProviderOptions);
|
|
64
|
+
translateBatch(request: TranslationBatchRequest): Promise<KeyResult[]>;
|
|
65
|
+
private post;
|
|
66
|
+
private backoff;
|
|
67
|
+
private toError;
|
|
68
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HostedTranslationProvider = exports.HostedTranslationError = exports.BILLING_URL = exports.API_KEYS_URL = exports.HOSTED_MODEL_HEADER = exports.HOSTED_REQUEST_TIMEOUT_MS = exports.HOSTED_MAX_BATCH = void 0;
|
|
4
|
+
exports.parseRetryAfterMs = parseRetryAfterMs;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const language_codes_1 = require("../modules/translator/language-codes");
|
|
7
|
+
const types_1 = require("@babelize/types");
|
|
8
|
+
/**
|
|
9
|
+
* Babelize-hosted translation for `babelize translate`: a TranslationProvider
|
|
10
|
+
* that sends the engine's already placeholder-protected strings (never code)
|
|
11
|
+
* to POST {apiUrl}/v1/translate/batch with a Babelize API key. The engine
|
|
12
|
+
* still validates every result and runs its repair retry locally; model,
|
|
13
|
+
* quota and credits are decided by the server.
|
|
14
|
+
*/
|
|
15
|
+
/** Server limit on entries per request. */
|
|
16
|
+
exports.HOSTED_MAX_BATCH = types_1.TRANSLATE_BATCH_LIMITS.maxEntries;
|
|
17
|
+
/**
|
|
18
|
+
* Per-attempt timeout. Longer than the server's total model budget (90 s),
|
|
19
|
+
* so the server finishes — or gives up uncharged — before we retry.
|
|
20
|
+
*/
|
|
21
|
+
exports.HOSTED_REQUEST_TIMEOUT_MS = 150000;
|
|
22
|
+
/** Response header naming the model that served a batch. */
|
|
23
|
+
exports.HOSTED_MODEL_HEADER = 'x-babelize-model';
|
|
24
|
+
exports.API_KEYS_URL = 'https://app.babelize.co/api-keys';
|
|
25
|
+
exports.BILLING_URL = 'https://app.babelize.co/billing';
|
|
26
|
+
class HostedTranslationError extends Error {
|
|
27
|
+
constructor(message, code, status) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.status = status;
|
|
31
|
+
this.name = 'HostedTranslationError';
|
|
32
|
+
}
|
|
33
|
+
/** Errors after which no further request can succeed in this run. */
|
|
34
|
+
get fatal() {
|
|
35
|
+
return this.code === 'hosted_auth' || this.code === 'hosted_credits';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.HostedTranslationError = HostedTranslationError;
|
|
39
|
+
const RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]);
|
|
40
|
+
function parseRetryAfterMs(value) {
|
|
41
|
+
if (!value)
|
|
42
|
+
return undefined;
|
|
43
|
+
const seconds = Number(value);
|
|
44
|
+
if (Number.isFinite(seconds) && seconds >= 0)
|
|
45
|
+
return seconds * 1000;
|
|
46
|
+
const date = Date.parse(value);
|
|
47
|
+
return Number.isNaN(date) ? undefined : Math.max(0, date - Date.now());
|
|
48
|
+
}
|
|
49
|
+
class HostedTranslationProvider {
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.opts = {
|
|
52
|
+
fetch: globalThis.fetch.bind(globalThis),
|
|
53
|
+
maxRetries: 3,
|
|
54
|
+
maxRetryAfterMs: 60000,
|
|
55
|
+
baseDelayMs: 1000,
|
|
56
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
57
|
+
timeoutMs: exports.HOSTED_REQUEST_TIMEOUT_MS,
|
|
58
|
+
...options,
|
|
59
|
+
apiUrl: options.apiUrl.replace(/\/+$/, ''),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async translateBatch(request) {
|
|
63
|
+
// Strings over the server's limits never leave the machine: they fail
|
|
64
|
+
// locally, and the rest of the batch is still sent.
|
|
65
|
+
const local = new Map();
|
|
66
|
+
const sendable = request.entries.filter((e) => {
|
|
67
|
+
if (e.value.length > types_1.TRANSLATE_BATCH_LIMITS.maxTextChars || e.key.length > types_1.TRANSLATE_BATCH_LIMITS.maxKeyChars) {
|
|
68
|
+
local.set(e.key, {
|
|
69
|
+
key: e.key,
|
|
70
|
+
status: 'failed',
|
|
71
|
+
reason: 'unsupported_by_provider',
|
|
72
|
+
retryable: false,
|
|
73
|
+
message: `longer than the hosted limit of ${types_1.TRANSLATE_BATCH_LIMITS.maxTextChars} characters — use your own LLM key for this string`,
|
|
74
|
+
});
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
const remote = new Map();
|
|
80
|
+
for (let i = 0; i < sendable.length; i += exports.HOSTED_MAX_BATCH) {
|
|
81
|
+
const entries = sendable.slice(i, i + exports.HOSTED_MAX_BATCH);
|
|
82
|
+
const keys = new Set(entries.map((e) => e.key));
|
|
83
|
+
const hints = request.hints
|
|
84
|
+
? Object.fromEntries(Object.entries(request.hints).filter(([k]) => keys.has(k)))
|
|
85
|
+
: undefined;
|
|
86
|
+
for (const r of await this.post({ ...request, entries, hints }))
|
|
87
|
+
remote.set(r.key, r);
|
|
88
|
+
}
|
|
89
|
+
return request.entries.flatMap((e) => {
|
|
90
|
+
const r = local.get(e.key) ?? remote.get(e.key);
|
|
91
|
+
return r ? [r] : [];
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async post(request) {
|
|
95
|
+
// After a bad key or empty balance every further request fails the same way.
|
|
96
|
+
if (this.fatalError)
|
|
97
|
+
throw this.fatalError;
|
|
98
|
+
// Optional extras are trimmed to the server's limits rather than failing
|
|
99
|
+
// the batch: they guide the model but aren't what gets translated.
|
|
100
|
+
const glossary = (request.glossary ?? [])
|
|
101
|
+
.filter((g) => g.term.length <= types_1.TRANSLATE_BATCH_LIMITS.maxGlossaryTermChars && g.translation.length <= types_1.TRANSLATE_BATCH_LIMITS.maxGlossaryTermChars)
|
|
102
|
+
.slice(0, types_1.TRANSLATE_BATCH_LIMITS.maxGlossary);
|
|
103
|
+
const hints = Object.fromEntries(Object.entries(request.hints ?? {}).map(([k, v]) => [k, v.slice(0, types_1.TRANSLATE_BATCH_LIMITS.maxHintChars)]));
|
|
104
|
+
const body = JSON.stringify({
|
|
105
|
+
sourceLocale: isoOf(request.sourceLang),
|
|
106
|
+
targetLocale: request.targetLocale || isoOf(request.targetLang),
|
|
107
|
+
entries: request.entries.map((e) => {
|
|
108
|
+
const element = e.extractionContext?.replace(/^hardcoded-/, '');
|
|
109
|
+
return {
|
|
110
|
+
key: e.key,
|
|
111
|
+
text: e.value,
|
|
112
|
+
...(e.parentContext && e.parentContext.length <= types_1.TRANSLATE_BATCH_LIMITS.maxContextChars ? { context: e.parentContext } : {}),
|
|
113
|
+
...(element && element.length <= types_1.TRANSLATE_BATCH_LIMITS.maxElementChars ? { element } : {}),
|
|
114
|
+
};
|
|
115
|
+
}),
|
|
116
|
+
...(glossary.length ? { glossary } : {}),
|
|
117
|
+
...(Object.keys(hints).length > 0 ? { hints } : {}),
|
|
118
|
+
...(request.brandVoice ? { brandVoice: request.brandVoice.slice(0, types_1.TRANSLATE_BATCH_LIMITS.maxBrandVoiceChars) } : {}),
|
|
119
|
+
});
|
|
120
|
+
// One key per logical batch, reused by its retries: if an earlier attempt
|
|
121
|
+
// was answered (and charged) but the response was lost, the server
|
|
122
|
+
// replays it instead of translating and charging again.
|
|
123
|
+
const idempotencyKey = (0, node_crypto_1.randomUUID)();
|
|
124
|
+
let attempt = 0;
|
|
125
|
+
for (;;) {
|
|
126
|
+
let res;
|
|
127
|
+
try {
|
|
128
|
+
res = await this.opts.fetch(`${this.opts.apiUrl}/v1/translate/batch`, {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
Authorization: `Bearer ${this.opts.apiKey}`,
|
|
133
|
+
'Idempotency-Key': idempotencyKey,
|
|
134
|
+
...(this.opts.userAgent ? { 'User-Agent': this.opts.userAgent } : {}),
|
|
135
|
+
},
|
|
136
|
+
body,
|
|
137
|
+
signal: AbortSignal.timeout(this.opts.timeoutMs),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
if (attempt < this.opts.maxRetries) {
|
|
142
|
+
await this.opts.sleep(this.backoff(attempt++));
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
throw new HostedTranslationError(`Could not reach Babelize at ${this.opts.apiUrl} (${err.message}).`, 'hosted_unavailable');
|
|
146
|
+
}
|
|
147
|
+
if (res.ok) {
|
|
148
|
+
let data;
|
|
149
|
+
try {
|
|
150
|
+
data = (await res.json());
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
// The connection dropped (or the timeout fired) while the body was
|
|
154
|
+
// being read. The server has already charged this batch, so retry
|
|
155
|
+
// with the same Idempotency-Key: it replays the stored response.
|
|
156
|
+
if (attempt < this.opts.maxRetries) {
|
|
157
|
+
await this.opts.sleep(this.backoff(attempt++));
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
throw new HostedTranslationError(`Lost the response from Babelize at ${this.opts.apiUrl} (${err.message}).`, 'hosted_unavailable');
|
|
161
|
+
}
|
|
162
|
+
this.model = res.headers.get(exports.HOSTED_MODEL_HEADER) ?? this.model;
|
|
163
|
+
return Array.isArray(data.results) ? data.results : [];
|
|
164
|
+
}
|
|
165
|
+
if (RETRYABLE_STATUS.has(res.status) && attempt < this.opts.maxRetries && !(await isHostedOff(res))) {
|
|
166
|
+
const retryAfter = parseRetryAfterMs(res.headers.get('retry-after'));
|
|
167
|
+
await this.opts.sleep(Math.min(retryAfter ?? this.backoff(attempt), this.opts.maxRetryAfterMs));
|
|
168
|
+
attempt++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const error = await this.toError(res);
|
|
172
|
+
if (error.fatal)
|
|
173
|
+
this.fatalError = error;
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
backoff(attempt) {
|
|
178
|
+
return this.opts.baseDelayMs * 2 ** attempt;
|
|
179
|
+
}
|
|
180
|
+
async toError(res) {
|
|
181
|
+
const payload = (await res.clone().json().catch(() => null));
|
|
182
|
+
const serverMessage = payload?.message ? ` (${payload.message})` : '';
|
|
183
|
+
switch (res.status) {
|
|
184
|
+
case 401:
|
|
185
|
+
case 403:
|
|
186
|
+
return new HostedTranslationError(`BABELIZE_API_KEY was rejected (${res.status}). Create a new key at ${exports.API_KEYS_URL} and set BABELIZE_API_KEY.`, 'hosted_auth', res.status);
|
|
187
|
+
case 402:
|
|
188
|
+
return new HostedTranslationError(payload?.message ??
|
|
189
|
+
`Your Babelize account is out of AI credits. Top up or upgrade at ${exports.BILLING_URL}, or use your own LLM key (e.g. set ANTHROPIC_API_KEY).`, 'hosted_credits', 402);
|
|
190
|
+
case 429:
|
|
191
|
+
return new HostedTranslationError('Babelize rate limit reached and retries ran out. Wait a minute and run translate again.', 'hosted_rate_limited', 429);
|
|
192
|
+
case 400:
|
|
193
|
+
return new HostedTranslationError(`Babelize rejected the request${serverMessage}.`, 'hosted_bad_request', 400);
|
|
194
|
+
default:
|
|
195
|
+
return new HostedTranslationError(`Babelize-hosted translation is unavailable (${res.status})${serverMessage}. Try again later or use your own LLM key.`, 'hosted_unavailable', res.status);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.HostedTranslationProvider = HostedTranslationProvider;
|
|
200
|
+
/** A 503 that means "hosted is switched off" won't get better by retrying. */
|
|
201
|
+
async function isHostedOff(res) {
|
|
202
|
+
if (res.status !== 503)
|
|
203
|
+
return false;
|
|
204
|
+
const payload = (await res.clone().json().catch(() => null));
|
|
205
|
+
return payload?.error === 'hosted_translation_unavailable';
|
|
206
|
+
}
|
|
207
|
+
/** eng_Latn → en (the engine passes FLORES codes; the API takes ISO). */
|
|
208
|
+
function isoOf(flores) {
|
|
209
|
+
try {
|
|
210
|
+
return (0, language_codes_1.fromFlores)(flores);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return flores;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local translation runner: what `babelize translate` and the MCP
|
|
3
|
+
* `babelize_translate` tool run on the user's machine. Git checks, a temp
|
|
4
|
+
* copy, the engine run, apply-back with concurrent-edit detection, provider
|
|
5
|
+
* resolution (BYOK env keys or the Babelize-hosted provider) and the report.
|
|
6
|
+
*/
|
|
7
|
+
export { BETA_LOCAL_FRAMEWORKS, buildLocaleReports, isEngineLogNoise, LOCAL_LOCKFILE, LOCAL_PROJECT_ID, LocalTranslateError, parseLocales, runLocalTranslate, sentence, SUPPORTED_LOCAL_FRAMEWORKS, validateLocales, } from './translate-core';
|
|
8
|
+
export type { FrameworkStatus, LocaleReport, LocalTranslateDeps, LocalTranslateErrorCode, LocalTranslateOptions, LocalTranslateReport, ReportProviderId, } from './translate-core';
|
|
9
|
+
export { BABELIZE_GITIGNORE, buildTranslateReport, DEFAULT_REPORT_FILE, ensureReportGitignored, TRANSLATE_REPORT_SCHEMA_ID, TRANSLATE_REPORT_SCHEMA_VERSION, writeTranslateReport, } from './report';
|
|
10
|
+
export type { KeyStatus, TranslateReport, TranslateReportKeyLocale, TranslateReportLocale } from './report';
|
|
11
|
+
export { isPseudoLocalized, PSEUDO_CLOSE, PSEUDO_OPEN, PseudoTranslationProvider } from './pseudo-provider';
|
|
12
|
+
export { translateMessages } from './translate-messages';
|
|
13
|
+
export type { TranslateMessagesOptions, TranslateMessagesResult } from './translate-messages';
|
|
14
|
+
export type { PseudoProviderOptions } from './pseudo-provider';
|
|
15
|
+
export { BABELIZE_KEY_ENV_VAR, HOSTED_PROVIDER_ID, isByokProvider, isHostedResolution, noKeyMessage, PROVIDER_ENV_VARS, resolveProvider, } from './provider';
|
|
16
|
+
export type { ProviderResolution, ResolvedHostedProvider, ResolvedProvider, ResolvedTranslator } from './provider';
|
|
17
|
+
export { API_KEYS_URL, BILLING_URL, HOSTED_MAX_BATCH, HOSTED_MODEL_HEADER, HOSTED_REQUEST_TIMEOUT_MS, HostedTranslationError, HostedTranslationProvider, parseRetryAfterMs, } from './hosted-provider';
|
|
18
|
+
export type { HostedErrorCode, HostedProviderOptions } from './hosted-provider';
|
|
19
|
+
export { assertCleanTree, assertGitRepo, getUncommittedChanges, GitError, isBabelizeReportFile, isGitIgnored } from './git';
|
|
20
|
+
export { detectFormatter, formatChangedFiles } from './formatter';
|
|
21
|
+
export type { FormatResult, FormatterName } from './formatter';
|
|
22
|
+
export { ApplyError, applyChanges, changeCount, createTempCopy, diffSnapshots, diffStats, findConflicts, listGitFiles, renderUnifiedDiff, snapshot, } from './workspace-copy';
|
|
23
|
+
export type { ApplyIo, FileDiffStat, TempWorkspace, WorkspaceChanges } from './workspace-copy';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTempCopy = exports.changeCount = exports.applyChanges = exports.ApplyError = exports.formatChangedFiles = exports.detectFormatter = exports.isGitIgnored = exports.isBabelizeReportFile = exports.GitError = exports.getUncommittedChanges = exports.assertGitRepo = exports.assertCleanTree = exports.parseRetryAfterMs = exports.HostedTranslationProvider = exports.HostedTranslationError = exports.HOSTED_REQUEST_TIMEOUT_MS = exports.HOSTED_MODEL_HEADER = exports.HOSTED_MAX_BATCH = exports.BILLING_URL = exports.API_KEYS_URL = exports.resolveProvider = exports.PROVIDER_ENV_VARS = exports.noKeyMessage = exports.isHostedResolution = exports.isByokProvider = exports.HOSTED_PROVIDER_ID = exports.BABELIZE_KEY_ENV_VAR = exports.translateMessages = exports.PseudoTranslationProvider = exports.PSEUDO_OPEN = exports.PSEUDO_CLOSE = exports.isPseudoLocalized = exports.writeTranslateReport = exports.TRANSLATE_REPORT_SCHEMA_VERSION = exports.TRANSLATE_REPORT_SCHEMA_ID = exports.ensureReportGitignored = exports.DEFAULT_REPORT_FILE = exports.buildTranslateReport = exports.BABELIZE_GITIGNORE = exports.validateLocales = exports.SUPPORTED_LOCAL_FRAMEWORKS = exports.sentence = exports.runLocalTranslate = exports.parseLocales = exports.LocalTranslateError = exports.LOCAL_PROJECT_ID = exports.LOCAL_LOCKFILE = exports.isEngineLogNoise = exports.buildLocaleReports = exports.BETA_LOCAL_FRAMEWORKS = void 0;
|
|
4
|
+
exports.snapshot = exports.renderUnifiedDiff = exports.listGitFiles = exports.findConflicts = exports.diffStats = exports.diffSnapshots = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Local translation runner: what `babelize translate` and the MCP
|
|
7
|
+
* `babelize_translate` tool run on the user's machine. Git checks, a temp
|
|
8
|
+
* copy, the engine run, apply-back with concurrent-edit detection, provider
|
|
9
|
+
* resolution (BYOK env keys or the Babelize-hosted provider) and the report.
|
|
10
|
+
*/
|
|
11
|
+
var translate_core_1 = require("./translate-core");
|
|
12
|
+
Object.defineProperty(exports, "BETA_LOCAL_FRAMEWORKS", { enumerable: true, get: function () { return translate_core_1.BETA_LOCAL_FRAMEWORKS; } });
|
|
13
|
+
Object.defineProperty(exports, "buildLocaleReports", { enumerable: true, get: function () { return translate_core_1.buildLocaleReports; } });
|
|
14
|
+
Object.defineProperty(exports, "isEngineLogNoise", { enumerable: true, get: function () { return translate_core_1.isEngineLogNoise; } });
|
|
15
|
+
Object.defineProperty(exports, "LOCAL_LOCKFILE", { enumerable: true, get: function () { return translate_core_1.LOCAL_LOCKFILE; } });
|
|
16
|
+
Object.defineProperty(exports, "LOCAL_PROJECT_ID", { enumerable: true, get: function () { return translate_core_1.LOCAL_PROJECT_ID; } });
|
|
17
|
+
Object.defineProperty(exports, "LocalTranslateError", { enumerable: true, get: function () { return translate_core_1.LocalTranslateError; } });
|
|
18
|
+
Object.defineProperty(exports, "parseLocales", { enumerable: true, get: function () { return translate_core_1.parseLocales; } });
|
|
19
|
+
Object.defineProperty(exports, "runLocalTranslate", { enumerable: true, get: function () { return translate_core_1.runLocalTranslate; } });
|
|
20
|
+
Object.defineProperty(exports, "sentence", { enumerable: true, get: function () { return translate_core_1.sentence; } });
|
|
21
|
+
Object.defineProperty(exports, "SUPPORTED_LOCAL_FRAMEWORKS", { enumerable: true, get: function () { return translate_core_1.SUPPORTED_LOCAL_FRAMEWORKS; } });
|
|
22
|
+
Object.defineProperty(exports, "validateLocales", { enumerable: true, get: function () { return translate_core_1.validateLocales; } });
|
|
23
|
+
var report_1 = require("./report");
|
|
24
|
+
Object.defineProperty(exports, "BABELIZE_GITIGNORE", { enumerable: true, get: function () { return report_1.BABELIZE_GITIGNORE; } });
|
|
25
|
+
Object.defineProperty(exports, "buildTranslateReport", { enumerable: true, get: function () { return report_1.buildTranslateReport; } });
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_REPORT_FILE", { enumerable: true, get: function () { return report_1.DEFAULT_REPORT_FILE; } });
|
|
27
|
+
Object.defineProperty(exports, "ensureReportGitignored", { enumerable: true, get: function () { return report_1.ensureReportGitignored; } });
|
|
28
|
+
Object.defineProperty(exports, "TRANSLATE_REPORT_SCHEMA_ID", { enumerable: true, get: function () { return report_1.TRANSLATE_REPORT_SCHEMA_ID; } });
|
|
29
|
+
Object.defineProperty(exports, "TRANSLATE_REPORT_SCHEMA_VERSION", { enumerable: true, get: function () { return report_1.TRANSLATE_REPORT_SCHEMA_VERSION; } });
|
|
30
|
+
Object.defineProperty(exports, "writeTranslateReport", { enumerable: true, get: function () { return report_1.writeTranslateReport; } });
|
|
31
|
+
var pseudo_provider_1 = require("./pseudo-provider");
|
|
32
|
+
Object.defineProperty(exports, "isPseudoLocalized", { enumerable: true, get: function () { return pseudo_provider_1.isPseudoLocalized; } });
|
|
33
|
+
Object.defineProperty(exports, "PSEUDO_CLOSE", { enumerable: true, get: function () { return pseudo_provider_1.PSEUDO_CLOSE; } });
|
|
34
|
+
Object.defineProperty(exports, "PSEUDO_OPEN", { enumerable: true, get: function () { return pseudo_provider_1.PSEUDO_OPEN; } });
|
|
35
|
+
Object.defineProperty(exports, "PseudoTranslationProvider", { enumerable: true, get: function () { return pseudo_provider_1.PseudoTranslationProvider; } });
|
|
36
|
+
var translate_messages_1 = require("./translate-messages");
|
|
37
|
+
Object.defineProperty(exports, "translateMessages", { enumerable: true, get: function () { return translate_messages_1.translateMessages; } });
|
|
38
|
+
var provider_1 = require("./provider");
|
|
39
|
+
Object.defineProperty(exports, "BABELIZE_KEY_ENV_VAR", { enumerable: true, get: function () { return provider_1.BABELIZE_KEY_ENV_VAR; } });
|
|
40
|
+
Object.defineProperty(exports, "HOSTED_PROVIDER_ID", { enumerable: true, get: function () { return provider_1.HOSTED_PROVIDER_ID; } });
|
|
41
|
+
Object.defineProperty(exports, "isByokProvider", { enumerable: true, get: function () { return provider_1.isByokProvider; } });
|
|
42
|
+
Object.defineProperty(exports, "isHostedResolution", { enumerable: true, get: function () { return provider_1.isHostedResolution; } });
|
|
43
|
+
Object.defineProperty(exports, "noKeyMessage", { enumerable: true, get: function () { return provider_1.noKeyMessage; } });
|
|
44
|
+
Object.defineProperty(exports, "PROVIDER_ENV_VARS", { enumerable: true, get: function () { return provider_1.PROVIDER_ENV_VARS; } });
|
|
45
|
+
Object.defineProperty(exports, "resolveProvider", { enumerable: true, get: function () { return provider_1.resolveProvider; } });
|
|
46
|
+
var hosted_provider_1 = require("./hosted-provider");
|
|
47
|
+
Object.defineProperty(exports, "API_KEYS_URL", { enumerable: true, get: function () { return hosted_provider_1.API_KEYS_URL; } });
|
|
48
|
+
Object.defineProperty(exports, "BILLING_URL", { enumerable: true, get: function () { return hosted_provider_1.BILLING_URL; } });
|
|
49
|
+
Object.defineProperty(exports, "HOSTED_MAX_BATCH", { enumerable: true, get: function () { return hosted_provider_1.HOSTED_MAX_BATCH; } });
|
|
50
|
+
Object.defineProperty(exports, "HOSTED_MODEL_HEADER", { enumerable: true, get: function () { return hosted_provider_1.HOSTED_MODEL_HEADER; } });
|
|
51
|
+
Object.defineProperty(exports, "HOSTED_REQUEST_TIMEOUT_MS", { enumerable: true, get: function () { return hosted_provider_1.HOSTED_REQUEST_TIMEOUT_MS; } });
|
|
52
|
+
Object.defineProperty(exports, "HostedTranslationError", { enumerable: true, get: function () { return hosted_provider_1.HostedTranslationError; } });
|
|
53
|
+
Object.defineProperty(exports, "HostedTranslationProvider", { enumerable: true, get: function () { return hosted_provider_1.HostedTranslationProvider; } });
|
|
54
|
+
Object.defineProperty(exports, "parseRetryAfterMs", { enumerable: true, get: function () { return hosted_provider_1.parseRetryAfterMs; } });
|
|
55
|
+
var git_1 = require("./git");
|
|
56
|
+
Object.defineProperty(exports, "assertCleanTree", { enumerable: true, get: function () { return git_1.assertCleanTree; } });
|
|
57
|
+
Object.defineProperty(exports, "assertGitRepo", { enumerable: true, get: function () { return git_1.assertGitRepo; } });
|
|
58
|
+
Object.defineProperty(exports, "getUncommittedChanges", { enumerable: true, get: function () { return git_1.getUncommittedChanges; } });
|
|
59
|
+
Object.defineProperty(exports, "GitError", { enumerable: true, get: function () { return git_1.GitError; } });
|
|
60
|
+
Object.defineProperty(exports, "isBabelizeReportFile", { enumerable: true, get: function () { return git_1.isBabelizeReportFile; } });
|
|
61
|
+
Object.defineProperty(exports, "isGitIgnored", { enumerable: true, get: function () { return git_1.isGitIgnored; } });
|
|
62
|
+
var formatter_1 = require("./formatter");
|
|
63
|
+
Object.defineProperty(exports, "detectFormatter", { enumerable: true, get: function () { return formatter_1.detectFormatter; } });
|
|
64
|
+
Object.defineProperty(exports, "formatChangedFiles", { enumerable: true, get: function () { return formatter_1.formatChangedFiles; } });
|
|
65
|
+
var workspace_copy_1 = require("./workspace-copy");
|
|
66
|
+
Object.defineProperty(exports, "ApplyError", { enumerable: true, get: function () { return workspace_copy_1.ApplyError; } });
|
|
67
|
+
Object.defineProperty(exports, "applyChanges", { enumerable: true, get: function () { return workspace_copy_1.applyChanges; } });
|
|
68
|
+
Object.defineProperty(exports, "changeCount", { enumerable: true, get: function () { return workspace_copy_1.changeCount; } });
|
|
69
|
+
Object.defineProperty(exports, "createTempCopy", { enumerable: true, get: function () { return workspace_copy_1.createTempCopy; } });
|
|
70
|
+
Object.defineProperty(exports, "diffSnapshots", { enumerable: true, get: function () { return workspace_copy_1.diffSnapshots; } });
|
|
71
|
+
Object.defineProperty(exports, "diffStats", { enumerable: true, get: function () { return workspace_copy_1.diffStats; } });
|
|
72
|
+
Object.defineProperty(exports, "findConflicts", { enumerable: true, get: function () { return workspace_copy_1.findConflicts; } });
|
|
73
|
+
Object.defineProperty(exports, "listGitFiles", { enumerable: true, get: function () { return workspace_copy_1.listGitFiles; } });
|
|
74
|
+
Object.defineProperty(exports, "renderUnifiedDiff", { enumerable: true, get: function () { return workspace_copy_1.renderUnifiedDiff; } });
|
|
75
|
+
Object.defineProperty(exports, "snapshot", { enumerable: true, get: function () { return workspace_copy_1.snapshot; } });
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ByokProvider } from '@babelize/types';
|
|
2
|
+
/**
|
|
3
|
+
* Env var holding each provider's key, in auto-detection order: the first one
|
|
4
|
+
* set wins when `--provider` isn't given.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PROVIDER_ENV_VARS: ReadonlyArray<{
|
|
7
|
+
provider: ByokProvider;
|
|
8
|
+
envVar: string;
|
|
9
|
+
}>;
|
|
10
|
+
export interface ResolvedProvider {
|
|
11
|
+
provider: ByokProvider;
|
|
12
|
+
/** Never print this. */
|
|
13
|
+
apiKey: string;
|
|
14
|
+
model: string;
|
|
15
|
+
/** Env var the key came from (safe to print). */
|
|
16
|
+
envVar: string;
|
|
17
|
+
/** True when the provider was picked from the environment, not `--provider`. */
|
|
18
|
+
autoDetected: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** Env var holding a Babelize API key for hosted translation. */
|
|
21
|
+
export declare const BABELIZE_KEY_ENV_VAR = "BABELIZE_API_KEY";
|
|
22
|
+
/** `--provider` value selecting Babelize-hosted translation. */
|
|
23
|
+
export declare const HOSTED_PROVIDER_ID = "babelize";
|
|
24
|
+
/** Babelize-hosted translation: the server picks the model and bills credits. */
|
|
25
|
+
export interface ResolvedHostedProvider {
|
|
26
|
+
provider: typeof HOSTED_PROVIDER_ID;
|
|
27
|
+
/** Never print this. */
|
|
28
|
+
apiKey: string;
|
|
29
|
+
envVar: typeof BABELIZE_KEY_ENV_VAR;
|
|
30
|
+
autoDetected: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type ResolvedTranslator = ResolvedProvider | ResolvedHostedProvider;
|
|
33
|
+
export declare function isHostedResolution(r: ResolvedTranslator): r is ResolvedHostedProvider;
|
|
34
|
+
export type ProviderResolution = {
|
|
35
|
+
ok: true;
|
|
36
|
+
value: ResolvedTranslator;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
code: 'unknown_provider' | 'missing_key' | 'no_key' | 'model_not_supported';
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function isByokProvider(value: string): value is ByokProvider;
|
|
43
|
+
/** Message shown when no key is available. Lists env vars, never values. */
|
|
44
|
+
export declare function noKeyMessage(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Pick the translator, in order of precedence:
|
|
47
|
+
* 1. `--provider` (a BYOK vendor, or `babelize`); its env var must be set.
|
|
48
|
+
* 2. The first BYOK env var set, in PROVIDER_ENV_VARS order.
|
|
49
|
+
* 3. BABELIZE_API_KEY → Babelize-hosted translation.
|
|
50
|
+
* For BYOK the model is `--model` or the provider's default from
|
|
51
|
+
* @babelize/types; hosted translation's model is chosen by the server.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolveProvider(opts: {
|
|
54
|
+
provider?: string;
|
|
55
|
+
model?: string;
|
|
56
|
+
}, env?: NodeJS.ProcessEnv): ProviderResolution;
|