@verbaly/compiler 0.84.0 → 0.85.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { kt as counted, xt as isModuleNotFound } from "./run-
|
|
1
|
+
import { kt as counted, xt as isModuleNotFound } from "./run-1p0TD3d7.js";
|
|
2
2
|
// src/exchange/providers/claude.ts
|
|
3
3
|
const DEFAULT_MODEL = "claude-sonnet-5-5";
|
|
4
4
|
const FALLBACK_MODELS = /* @__PURE__ */ new Set([
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -127,6 +127,7 @@ interface TranslateOptions {
|
|
|
127
127
|
dryRun?: boolean;
|
|
128
128
|
origins?: Record<string, string[]>;
|
|
129
129
|
onProgress?: (progress: TranslateProgress) => void;
|
|
130
|
+
onLocale?: (locale: string, keys: string[]) => void;
|
|
130
131
|
}
|
|
131
132
|
interface TranslateFailure {
|
|
132
133
|
locale: string;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as collectOrigins, A as collisionEntries, At as singleQuoted, B as loadState, C as translateProject, Ct as pluginOnlyOptions, D as translateCatalogs, Dt as warnParseError, E as resolveProvider, Et as warnOnce, F as outdatedTranslations, G as generateLocaleModule, H as readState, I as recordTranslations, J as validateMessage, K as generateRuntimeModule, L as updateState, M as formatCollision, N as formatFinding, O as writeDrafts, Ot as cliReachable, P as effectiveDrafts, Q as syncCatalogs, R as STATE_FILE, S as warningCount, St as loadConfig, T as mergeTranslations, Tt as targetLocales, U as saveState, V as markDrafts, W as generateDts, X as pruneCatalogs, Y as validatePair, Z as shippedCatalogs, _ as formatCheckResult, _t as parseCatalog, a as formatRenderWarnings, at as LOCALE_IMPORT, b as gatePasses, bt as SOURCE_FILE_RE, c as watchTree, ct as MessageRegistry, d as formatDoctorHealth, dt as formatBundleIssue, et as extractProject, f as formatStatusResult, ft as emptyCatalog, g as formatBuildReport, gt as own, h as checkNextSteps, ht as needsRelative, i as wrapProject, it as APP_ID, j as createDevReporter, jt as relativePath, k as syncProject, kt as counted, l as doctor, lt as auditBundle, m as reportOutsideInclude, mt as needsIcu, nt as analyzeFile, o as renderSite, ot as VIRTUAL_ID, p as status, pt as loadCatalogs, q as writeDts, r as formatWrapResult, rt as stableKey, s as init, st as isAppModule, t as formatCliError, tt as scannedAnalysis, u as formatDoctorEntry, ut as clientCatalogs, v as formatCheckWarnings, vt as readCatalog, w as formatTranslateFailures, wt as resolveConfig, x as relativeCheck, y as check, yt as writeCatalog, z as clearDrafts } from "./run-
|
|
1
|
+
import { $ as collectOrigins, A as collisionEntries, At as singleQuoted, B as loadState, C as translateProject, Ct as pluginOnlyOptions, D as translateCatalogs, Dt as warnParseError, E as resolveProvider, Et as warnOnce, F as outdatedTranslations, G as generateLocaleModule, H as readState, I as recordTranslations, J as validateMessage, K as generateRuntimeModule, L as updateState, M as formatCollision, N as formatFinding, O as writeDrafts, Ot as cliReachable, P as effectiveDrafts, Q as syncCatalogs, R as STATE_FILE, S as warningCount, St as loadConfig, T as mergeTranslations, Tt as targetLocales, U as saveState, V as markDrafts, W as generateDts, X as pruneCatalogs, Y as validatePair, Z as shippedCatalogs, _ as formatCheckResult, _t as parseCatalog, a as formatRenderWarnings, at as LOCALE_IMPORT, b as gatePasses, bt as SOURCE_FILE_RE, c as watchTree, ct as MessageRegistry, d as formatDoctorHealth, dt as formatBundleIssue, et as extractProject, f as formatStatusResult, ft as emptyCatalog, g as formatBuildReport, gt as own, h as checkNextSteps, ht as needsRelative, i as wrapProject, it as APP_ID, j as createDevReporter, jt as relativePath, k as syncProject, kt as counted, l as doctor, lt as auditBundle, m as reportOutsideInclude, mt as needsIcu, nt as analyzeFile, o as renderSite, ot as VIRTUAL_ID, p as status, pt as loadCatalogs, q as writeDts, r as formatWrapResult, rt as stableKey, s as init, st as isAppModule, t as formatCliError, tt as scannedAnalysis, u as formatDoctorEntry, ut as clientCatalogs, v as formatCheckWarnings, vt as readCatalog, w as formatTranslateFailures, wt as resolveConfig, x as relativeCheck, y as check, yt as writeCatalog, z as clearDrafts } from "./run-1p0TD3d7.js";
|
|
2
2
|
import picomatch from "picomatch";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
4
|
// src/scan/transform.ts
|
|
@@ -2792,6 +2792,22 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
2792
2792
|
failed: []
|
|
2793
2793
|
};
|
|
2794
2794
|
const jobs = [];
|
|
2795
|
+
const open = /* @__PURE__ */ new Map();
|
|
2796
|
+
const settle = (locale) => {
|
|
2797
|
+
const left = open.get(locale) - 1;
|
|
2798
|
+
open.set(locale, left);
|
|
2799
|
+
const keys = [...result.translated[locale] ?? []].sort();
|
|
2800
|
+
if (left > 0 || keys.length === 0 || !options.onLocale) return;
|
|
2801
|
+
try {
|
|
2802
|
+
options.onLocale(locale, keys);
|
|
2803
|
+
} catch (error) {
|
|
2804
|
+
result.failed.push({
|
|
2805
|
+
locale,
|
|
2806
|
+
keys,
|
|
2807
|
+
error: reason(error)
|
|
2808
|
+
});
|
|
2809
|
+
}
|
|
2810
|
+
};
|
|
2795
2811
|
for (const locale of targets) {
|
|
2796
2812
|
const catalog = catalogs[locale] ??= emptyCatalog();
|
|
2797
2813
|
const missing = Object.keys(source).filter((key) => source[key] && !own(catalog, key));
|
|
@@ -2801,6 +2817,7 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
2801
2817
|
continue;
|
|
2802
2818
|
}
|
|
2803
2819
|
const batches = Math.ceil(missing.length / batchSize);
|
|
2820
|
+
open.set(locale, batches);
|
|
2804
2821
|
for (let i = 0; i < missing.length; i += batchSize) {
|
|
2805
2822
|
const index = Math.floor(i / batchSize) + 1;
|
|
2806
2823
|
jobs.push({
|
|
@@ -2833,6 +2850,7 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
2833
2850
|
keys,
|
|
2834
2851
|
error: message
|
|
2835
2852
|
});
|
|
2853
|
+
settle(locale);
|
|
2836
2854
|
options.onProgress?.({
|
|
2837
2855
|
...progressOf(job),
|
|
2838
2856
|
error: message
|
|
@@ -2846,6 +2864,7 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
2846
2864
|
(result.translated[locale] ??= []).push(key);
|
|
2847
2865
|
} else (result.invalid[locale] ??= []).push(key);
|
|
2848
2866
|
}
|
|
2867
|
+
settle(locale);
|
|
2849
2868
|
options.onProgress?.(progressOf(job));
|
|
2850
2869
|
});
|
|
2851
2870
|
for (const locale of Object.keys(result.translated)) result.translated[locale].sort();
|
|
@@ -2856,18 +2875,25 @@ async function translateCatalogs(cfg, catalogs, provider, options = {}) {
|
|
|
2856
2875
|
function compare(a, b) {
|
|
2857
2876
|
return byCodeUnit(a[0] ?? "", b[0] ?? "");
|
|
2858
2877
|
}
|
|
2859
|
-
function
|
|
2878
|
+
function mergePlan(cfg, locale, translated, keys) {
|
|
2860
2879
|
const source = readCatalog(cfg, cfg.sourceLocale);
|
|
2861
2880
|
const current = readCatalog(cfg, locale);
|
|
2862
|
-
const
|
|
2881
|
+
const landed = [];
|
|
2863
2882
|
for (const key of keys) {
|
|
2864
2883
|
const text = own(translated, key);
|
|
2865
2884
|
if (!source[key] || current[key] || !text) continue;
|
|
2866
2885
|
current[key] = text;
|
|
2867
|
-
|
|
2886
|
+
landed.push(key);
|
|
2868
2887
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2888
|
+
return {
|
|
2889
|
+
current,
|
|
2890
|
+
landed
|
|
2891
|
+
};
|
|
2892
|
+
}
|
|
2893
|
+
function mergeTranslations(cfg, locale, translated, keys) {
|
|
2894
|
+
const { current, landed } = mergePlan(cfg, locale, translated, keys);
|
|
2895
|
+
if (landed.length > 0) writeCatalog(cfg, locale, current);
|
|
2896
|
+
return landed;
|
|
2871
2897
|
}
|
|
2872
2898
|
function writeDrafts(cfg, locale, entries, options = {}) {
|
|
2873
2899
|
const typo = strangerLocales(cfg, "locale", [locale]);
|
|
@@ -2895,7 +2921,6 @@ function writeDrafts(cfg, locale, entries, options = {}) {
|
|
|
2895
2921
|
}
|
|
2896
2922
|
}
|
|
2897
2923
|
if (result.written.length > 0) {
|
|
2898
|
-
writeCatalog(cfg, locale, current);
|
|
2899
2924
|
const written = result.written.map((key) => ({
|
|
2900
2925
|
key,
|
|
2901
2926
|
text: current[key]
|
|
@@ -2906,6 +2931,7 @@ function writeDrafts(cfg, locale, entries, options = {}) {
|
|
|
2906
2931
|
entries: written,
|
|
2907
2932
|
draft: true
|
|
2908
2933
|
}]);
|
|
2934
|
+
writeCatalog(cfg, locale, current);
|
|
2909
2935
|
const lock = lockNews(cfg, before);
|
|
2910
2936
|
if (lock) result.lock = lock;
|
|
2911
2937
|
}
|
|
@@ -2926,7 +2952,7 @@ function formatTranslateFailures(failed) {
|
|
|
2926
2952
|
async function resolveProvider(cfg, model) {
|
|
2927
2953
|
const configured = cfg.translate.provider;
|
|
2928
2954
|
if (typeof configured === "function") return configured;
|
|
2929
|
-
const { claudeProvider } = await import("./claude-
|
|
2955
|
+
const { claudeProvider } = await import("./claude-Cf5p2nJo.js");
|
|
2930
2956
|
return claudeProvider({ model: model ?? cfg.translate.model });
|
|
2931
2957
|
}
|
|
2932
2958
|
function progressOf(job) {
|
|
@@ -2956,14 +2982,45 @@ async function translateProject(cfg, options = {}) {
|
|
|
2956
2982
|
if (!dryRun) loadState(cfg);
|
|
2957
2983
|
const registry = await extractProject(cfg);
|
|
2958
2984
|
const catalogs = shippedCatalogs(cfg, loadCatalogs(cfg), registry, { newKeys: false });
|
|
2959
|
-
const
|
|
2985
|
+
const provider = options.provider ?? await resolveProvider(cfg, options.model);
|
|
2986
|
+
const source = catalogs[cfg.sourceLocale] ?? {};
|
|
2987
|
+
const written = emptyCatalog();
|
|
2988
|
+
const kept = emptyCatalog();
|
|
2989
|
+
let before;
|
|
2990
|
+
const save = (locale, keys) => {
|
|
2991
|
+
const catalog = catalogs[locale] ?? {};
|
|
2992
|
+
try {
|
|
2993
|
+
const { current, landed } = mergePlan(cfg, locale, catalog, keys);
|
|
2994
|
+
if (landed.length > 0) {
|
|
2995
|
+
const entries = landed.map((key) => ({
|
|
2996
|
+
key,
|
|
2997
|
+
text: catalog[key]
|
|
2998
|
+
}));
|
|
2999
|
+
before ??= { file: stateFile(cfg) };
|
|
3000
|
+
recordTranslations(cfg, source, [{
|
|
3001
|
+
locale,
|
|
3002
|
+
draft: true,
|
|
3003
|
+
entries
|
|
3004
|
+
}]);
|
|
3005
|
+
writeCatalog(cfg, locale, current);
|
|
3006
|
+
written[locale] = landed;
|
|
3007
|
+
}
|
|
3008
|
+
const left = keys.filter((key) => !landed.includes(key));
|
|
3009
|
+
if (left.length > 0) kept[locale] = left;
|
|
3010
|
+
} catch (error) {
|
|
3011
|
+
const why = error instanceof Error ? error.message : String(error);
|
|
3012
|
+
throw new Error(`could not be saved: ${why}`, { cause: error });
|
|
3013
|
+
}
|
|
3014
|
+
};
|
|
3015
|
+
const run = await translateCatalogs(cfg, catalogs, provider, {
|
|
2960
3016
|
locales: options.locales,
|
|
2961
3017
|
batchSize: cfg.translate.batchSize,
|
|
2962
3018
|
concurrency: cfg.translate.concurrency,
|
|
2963
3019
|
retries: cfg.translate.retries,
|
|
2964
3020
|
dryRun,
|
|
2965
3021
|
origins: dryRun ? void 0 : await collectOrigins(cfg, registry),
|
|
2966
|
-
onProgress: dryRun ? void 0 : options.onProgress
|
|
3022
|
+
onProgress: dryRun ? void 0 : options.onProgress,
|
|
3023
|
+
onLocale: dryRun ? void 0 : save
|
|
2967
3024
|
});
|
|
2968
3025
|
const result = {
|
|
2969
3026
|
pending: run.pending,
|
|
@@ -2973,26 +3030,11 @@ async function translateProject(cfg, options = {}) {
|
|
|
2973
3030
|
failed: run.failed
|
|
2974
3031
|
};
|
|
2975
3032
|
if (dryRun) return result;
|
|
2976
|
-
const
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
const landed = mergeTranslations(cfg, locale, catalog, keys);
|
|
2980
|
-
const left = keys.filter((key) => !landed.includes(key));
|
|
2981
|
-
if (left.length > 0) result.kept[locale] = left;
|
|
2982
|
-
if (landed.length === 0) continue;
|
|
2983
|
-
result.written[locale] = landed;
|
|
2984
|
-
writes.push({
|
|
2985
|
-
locale,
|
|
2986
|
-
draft: true,
|
|
2987
|
-
entries: landed.map((key) => ({
|
|
2988
|
-
key,
|
|
2989
|
-
text: catalog[key]
|
|
2990
|
-
}))
|
|
2991
|
-
});
|
|
3033
|
+
for (const locale of targetLocales(cfg, options.locales)) {
|
|
3034
|
+
if (written[locale]) result.written[locale] = written[locale];
|
|
3035
|
+
if (kept[locale]) result.kept[locale] = kept[locale];
|
|
2992
3036
|
}
|
|
2993
|
-
const
|
|
2994
|
-
if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
|
|
2995
|
-
const lock = lockNews(cfg, before);
|
|
3037
|
+
const lock = before && lockNews(cfg, before.file);
|
|
2996
3038
|
if (lock) result.lock = lock;
|
|
2997
3039
|
return result;
|
|
2998
3040
|
}
|
|
@@ -4693,27 +4735,29 @@ async function importCommand(cfg, values, positionals) {
|
|
|
4693
4735
|
process.exitCode = 1;
|
|
4694
4736
|
}
|
|
4695
4737
|
const writes = [];
|
|
4696
|
-
for (const [locale, keys] of Object.entries(result.imported)) {
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
draft: values.draft === true
|
|
4710
|
-
});
|
|
4711
|
-
}
|
|
4712
|
-
const verb = values["dry-run"] ? "would import" : "imported";
|
|
4713
|
-
console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
|
|
4738
|
+
if (!values["dry-run"]) for (const [locale, keys] of Object.entries(result.imported)) {
|
|
4739
|
+
const catalog = catalogs[locale] ?? {};
|
|
4740
|
+
const seen = result.sources[locale] ?? {};
|
|
4741
|
+
const entries = keys.map((key) => ({
|
|
4742
|
+
key,
|
|
4743
|
+
text: catalog[key],
|
|
4744
|
+
source: seen[key]
|
|
4745
|
+
}));
|
|
4746
|
+
writes.push({
|
|
4747
|
+
locale,
|
|
4748
|
+
entries,
|
|
4749
|
+
draft: values.draft === true
|
|
4750
|
+
});
|
|
4714
4751
|
}
|
|
4715
4752
|
const lockBefore = stateFile(cfg);
|
|
4716
|
-
|
|
4753
|
+
const record = () => {
|
|
4754
|
+
if (writes.length > 0) recordTranslations(cfg, catalogs[cfg.sourceLocale] ?? {}, writes);
|
|
4755
|
+
};
|
|
4756
|
+
if (values.draft) record();
|
|
4757
|
+
for (const { locale } of writes) writeCatalog(cfg, locale, catalogs[locale] ?? {});
|
|
4758
|
+
if (!values.draft) record();
|
|
4759
|
+
const verb = values["dry-run"] ? "would import" : "imported";
|
|
4760
|
+
for (const [locale, keys] of Object.entries(result.imported)) console.log(` ${locale}: +${keys.length} ${verb}${values.draft ? " (draft)" : ""}`);
|
|
4717
4761
|
sayLockNews(cfg, lockBefore);
|
|
4718
4762
|
for (const [locale, keys] of Object.entries(result.skipped)) console.log(` ${locale}: ${keys.length} already translated, kept (use --overwrite to replace)`);
|
|
4719
4763
|
for (const [locale, keys] of Object.entries(result.rejected)) console.warn(` ${locale}: ${keys.length} rejected (params/tags not preserved): ${keys.join(", ")}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.85.0",
|
|
4
4
|
"description": "Message extraction and type-safe codegen for Verbaly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"magic-string": "^1.4.5",
|
|
53
53
|
"picomatch": "^4.0.7",
|
|
54
54
|
"tinyglobby": "^0.2.17",
|
|
55
|
-
"verbaly": "0.
|
|
55
|
+
"verbaly": "0.85.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@anthropic-ai/sdk": ">=0.110.0"
|