@scoutello/i18n-magic 0.57.2 ā 0.57.3
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/commands/sync-locales.d.ts.map +1 -1
- package/dist/commands/sync-locales.js +186 -98
- package/dist/commands/sync-locales.js.map +1 -1
- package/dist/lib/utils.d.ts +6 -2
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +17 -12
- package/dist/lib/utils.js.map +1 -1
- package/package.json +10 -8
- package/src/commands/sync-locales.ts +254 -155
- package/src/lib/utils.ts +19 -10
- package/dist/commands/create-pruned-namespace-automated.d.ts +0 -20
- package/dist/commands/create-pruned-namespace-automated.d.ts.map +0 -1
- package/dist/commands/create-pruned-namespace-automated.js +0 -98
- package/dist/commands/create-pruned-namespace-automated.js.map +0 -1
- package/dist/commands/create-pruned-namespace.d.ts +0 -3
- package/dist/commands/create-pruned-namespace.d.ts.map +0 -1
- package/dist/commands/create-pruned-namespace.js +0 -123
- package/dist/commands/create-pruned-namespace.js.map +0 -1
- package/dist/i18n-magic.cjs.development.js +0 -1787
- package/dist/i18n-magic.cjs.development.js.map +0 -1
- package/dist/i18n-magic.cjs.production.min.js +0 -2
- package/dist/i18n-magic.cjs.production.min.js.map +0 -1
- package/dist/i18n-magic.esm.js +0 -1776
- package/dist/i18n-magic.esm.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-locales.d.ts","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync-locales.d.ts","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAepD,eAAO,MAAM,WAAW,GAAU,QAAQ,aAAa,kBA4TtD,CAAA"}
|
|
@@ -1,10 +1,59 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import cliProgress from "cli-progress";
|
|
2
4
|
import { TranslationError, loadLocalesFile, translateKey, writeLocalesFile, findExistingTranslations, } from "../lib/utils.js";
|
|
5
|
+
import { languages } from "../lib/languges.js";
|
|
6
|
+
const getLanguageLabel = (locale) => {
|
|
7
|
+
const lang = languages.find((l) => l.value === locale);
|
|
8
|
+
return lang?.label || locale;
|
|
9
|
+
};
|
|
3
10
|
export const syncLocales = async (config) => {
|
|
4
11
|
const { loadPath, savePath, defaultLocale, namespaces, locales, context, openai, } = config;
|
|
5
|
-
|
|
6
|
-
console.log(
|
|
7
|
-
console.log(
|
|
12
|
+
const localesToProcess = locales.filter((l) => l !== defaultLocale);
|
|
13
|
+
console.log(chalk.cyan("\nš Syncing translations\n"));
|
|
14
|
+
console.log(chalk.dim(` Default locale: ${chalk.white(getLanguageLabel(defaultLocale))}`));
|
|
15
|
+
console.log(chalk.dim(` Namespaces: ${chalk.white(namespaces.join(", "))}`));
|
|
16
|
+
console.log(chalk.dim(` Target languages: ${chalk.white(localesToProcess.length)}\n`));
|
|
17
|
+
// Create multi-bar container
|
|
18
|
+
const multibar = new cliProgress.MultiBar({
|
|
19
|
+
clearOnComplete: false,
|
|
20
|
+
hideCursor: true,
|
|
21
|
+
format: (options, params, payload) => {
|
|
22
|
+
const lang = payload.language || "unknown";
|
|
23
|
+
const status = payload.status || "";
|
|
24
|
+
const bar = options.barCompleteString?.substring(0, Math.round(params.progress * options.barsize)) || "";
|
|
25
|
+
const emptyBar = options.barIncompleteString?.substring(0, options.barsize - bar.length) || "";
|
|
26
|
+
// Color the bar based on progress
|
|
27
|
+
let coloredBar;
|
|
28
|
+
if (params.progress >= 1) {
|
|
29
|
+
coloredBar = chalk.green(bar) + chalk.gray(emptyBar);
|
|
30
|
+
}
|
|
31
|
+
else if (params.progress >= 0.5) {
|
|
32
|
+
coloredBar = chalk.yellow(bar) + chalk.gray(emptyBar);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
coloredBar = chalk.cyan(bar) + chalk.gray(emptyBar);
|
|
36
|
+
}
|
|
37
|
+
const percentage = Math.round(params.progress * 100);
|
|
38
|
+
const paddedLang = lang.padEnd(12);
|
|
39
|
+
const paddedStatus = status.padEnd(20);
|
|
40
|
+
return ` ${chalk.white(paddedLang)} ${coloredBar} ${chalk.dim(percentage.toString().padStart(3))}% ${chalk.dim(paddedStatus)}`;
|
|
41
|
+
},
|
|
42
|
+
barCompleteChar: "ā",
|
|
43
|
+
barIncompleteChar: "ā",
|
|
44
|
+
barsize: 25,
|
|
45
|
+
}, cliProgress.Presets.shades_classic);
|
|
46
|
+
// Create a progress bar for each locale
|
|
47
|
+
const progressBars = {};
|
|
48
|
+
const localeStats = {};
|
|
49
|
+
for (const locale of localesToProcess) {
|
|
50
|
+
const langLabel = getLanguageLabel(locale);
|
|
51
|
+
progressBars[locale] = multibar.create(100, 0, {
|
|
52
|
+
language: langLabel,
|
|
53
|
+
status: "Waiting...",
|
|
54
|
+
});
|
|
55
|
+
localeStats[locale] = { missing: 0, reused: 0, translated: 0 };
|
|
56
|
+
}
|
|
8
57
|
try {
|
|
9
58
|
// Helper to ensure a locale/namespace file exists before we add keys
|
|
10
59
|
const ensureLocaleNamespaceFile = async (locale, namespace) => {
|
|
@@ -13,7 +62,6 @@ export const syncLocales = async (config) => {
|
|
|
13
62
|
.replace("{{lng}}", locale)
|
|
14
63
|
.replace("{{ns}}", namespace);
|
|
15
64
|
if (!fs.existsSync(filePath)) {
|
|
16
|
-
console.log(`š Creating missing namespace file: ${filePath}`);
|
|
17
65
|
await writeLocalesFile(savePath, locale, namespace, {});
|
|
18
66
|
}
|
|
19
67
|
}
|
|
@@ -21,116 +69,156 @@ export const syncLocales = async (config) => {
|
|
|
21
69
|
// Ensure all default-locale namespace files exist first
|
|
22
70
|
await Promise.all(namespaces.map((namespace) => ensureLocaleNamespaceFile(defaultLocale, namespace)));
|
|
23
71
|
// Process all non-default locales in parallel
|
|
24
|
-
const localesToProcess = locales.filter((l) => l !== defaultLocale);
|
|
25
72
|
await Promise.all(localesToProcess.map(async (locale) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
allMissingKeys[key]
|
|
56
|
-
|
|
57
|
-
namespaces
|
|
58
|
-
}
|
|
73
|
+
const bar = progressBars[locale];
|
|
74
|
+
const stats = localeStats[locale];
|
|
75
|
+
try {
|
|
76
|
+
// Stage 1: Loading (0-20%)
|
|
77
|
+
bar.update(5, { status: "Loading files..." });
|
|
78
|
+
// Ensure all namespace files for this locale exist before filling keys
|
|
79
|
+
await Promise.all(namespaces.map((namespace) => ensureLocaleNamespaceFile(locale, namespace)));
|
|
80
|
+
bar.update(10, { status: "Analyzing keys..." });
|
|
81
|
+
// Collect all missing keys for this locale across all namespaces
|
|
82
|
+
const allMissingKeys = {};
|
|
83
|
+
const namespaceKeys = {};
|
|
84
|
+
// Load existing keys for all namespaces in parallel
|
|
85
|
+
const namespaceResults = await Promise.all(namespaces.map(async (namespace) => {
|
|
86
|
+
const defaultLocaleKeys = await loadLocalesFile(loadPath, defaultLocale, namespace, { silent: true });
|
|
87
|
+
const localeKeys = await loadLocalesFile(loadPath, locale, namespace, { silent: true });
|
|
88
|
+
return {
|
|
89
|
+
namespace,
|
|
90
|
+
defaultLocaleKeys,
|
|
91
|
+
localeKeys,
|
|
92
|
+
};
|
|
93
|
+
}));
|
|
94
|
+
bar.update(20, { status: "Finding missing..." });
|
|
95
|
+
// Process results and collect missing keys
|
|
96
|
+
for (const result of namespaceResults) {
|
|
97
|
+
const { namespace, defaultLocaleKeys, localeKeys } = result;
|
|
98
|
+
namespaceKeys[namespace] = localeKeys;
|
|
99
|
+
// Check which keys from default locale are missing in current locale
|
|
100
|
+
for (const [key, value] of Object.entries(defaultLocaleKeys)) {
|
|
101
|
+
if (!localeKeys[key]) {
|
|
102
|
+
if (allMissingKeys[key]) {
|
|
103
|
+
// Key already exists, add this namespace to the list
|
|
104
|
+
allMissingKeys[key].namespaces.push(namespace);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// New missing key
|
|
108
|
+
allMissingKeys[key] = {
|
|
109
|
+
value,
|
|
110
|
+
namespaces: [namespace],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
59
113
|
}
|
|
60
114
|
}
|
|
61
115
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
console.log(`Found ${missingKeysList.length} unique missing keys in ${locale}`);
|
|
69
|
-
// Check for existing translations of these keys in other namespaces (parallelized)
|
|
70
|
-
const keysToTranslate = {};
|
|
71
|
-
const existingTranslations = {};
|
|
72
|
-
const existingTranslationResults = await findExistingTranslations(missingKeysList, namespaces, locale, loadPath);
|
|
73
|
-
const reusedKeys = [];
|
|
74
|
-
for (const key of missingKeysList) {
|
|
75
|
-
const existingValue = existingTranslationResults[key];
|
|
76
|
-
// Use explicit null check instead of truthy check to handle empty string values
|
|
77
|
-
if (existingValue !== null) {
|
|
78
|
-
existingTranslations[key] = existingValue;
|
|
79
|
-
reusedKeys.push(key);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
keysToTranslate[key] = allMissingKeys[key].value;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Batch log reused translations
|
|
86
|
-
if (reusedKeys.length > 0) {
|
|
87
|
-
console.log(`š Reusing ${reusedKeys.length} existing translations for ${locale}`);
|
|
88
|
-
}
|
|
89
|
-
let translatedValues = {};
|
|
90
|
-
// Translate only the keys that don't have existing translations
|
|
91
|
-
if (Object.keys(keysToTranslate).length > 0) {
|
|
92
|
-
console.log(`š¤ Translating ${Object.keys(keysToTranslate).length} new keys for ${locale}`);
|
|
93
|
-
try {
|
|
94
|
-
translatedValues = await translateKey({
|
|
95
|
-
inputLanguage: defaultLocale,
|
|
96
|
-
outputLanguage: locale,
|
|
97
|
-
context,
|
|
98
|
-
object: keysToTranslate,
|
|
99
|
-
openai,
|
|
100
|
-
model: config.model,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
throw new TranslationError(`Failed to translate keys for locale "${locale}"`, locale, undefined, error instanceof Error ? error : undefined);
|
|
116
|
+
const missingKeysList = Object.keys(allMissingKeys);
|
|
117
|
+
stats.missing = missingKeysList.length;
|
|
118
|
+
if (missingKeysList.length === 0) {
|
|
119
|
+
bar.update(100, { status: chalk.green("ā Up to date") });
|
|
120
|
+
return;
|
|
105
121
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const updatedKeys = { ...namespaceKeys[namespace] };
|
|
122
|
+
// Stage 2: Check for existing translations (20-40%)
|
|
123
|
+
bar.update(25, { status: `Checking ${missingKeysList.length} keys...` });
|
|
124
|
+
const keysToTranslate = {};
|
|
125
|
+
const existingTranslations = {};
|
|
126
|
+
const existingTranslationResults = await findExistingTranslations(missingKeysList, namespaces, locale, loadPath, { silent: true });
|
|
127
|
+
bar.update(40, { status: "Processing results..." });
|
|
113
128
|
for (const key of missingKeysList) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
const existingValue = existingTranslationResults[key];
|
|
130
|
+
// Use explicit null check instead of truthy check to handle empty string values
|
|
131
|
+
if (existingValue !== null) {
|
|
132
|
+
existingTranslations[key] = existingValue;
|
|
133
|
+
stats.reused++;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
keysToTranslate[key] = allMissingKeys[key].value;
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
|
-
|
|
139
|
+
let translatedValues = {};
|
|
140
|
+
// Stage 3: Translate (40-80%)
|
|
141
|
+
if (Object.keys(keysToTranslate).length > 0) {
|
|
142
|
+
const keysCount = Object.keys(keysToTranslate).length;
|
|
143
|
+
bar.update(45, { status: `Translating ${keysCount} keys...` });
|
|
121
144
|
try {
|
|
122
|
-
await
|
|
123
|
-
|
|
124
|
-
|
|
145
|
+
translatedValues = await translateKey({
|
|
146
|
+
inputLanguage: defaultLocale,
|
|
147
|
+
outputLanguage: locale,
|
|
148
|
+
context,
|
|
149
|
+
object: keysToTranslate,
|
|
150
|
+
openai,
|
|
151
|
+
model: config.model,
|
|
152
|
+
});
|
|
153
|
+
stats.translated = Object.keys(translatedValues).length;
|
|
125
154
|
}
|
|
126
155
|
catch (error) {
|
|
127
|
-
|
|
156
|
+
bar.update(100, { status: chalk.red("ā Translation failed") });
|
|
157
|
+
throw new TranslationError(`Failed to translate keys for locale "${locale}"`, locale, undefined, error instanceof Error ? error : undefined);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
bar.update(80, { status: "Saving files..." });
|
|
161
|
+
// Stage 4: Save (80-100%)
|
|
162
|
+
// Combine existing translations with new translations
|
|
163
|
+
const allTranslations = { ...existingTranslations, ...translatedValues };
|
|
164
|
+
// Distribute translations to all relevant namespaces in parallel
|
|
165
|
+
await Promise.all(namespaces.map(async (namespace) => {
|
|
166
|
+
let hasChanges = false;
|
|
167
|
+
const updatedKeys = { ...namespaceKeys[namespace] };
|
|
168
|
+
for (const key of missingKeysList) {
|
|
169
|
+
if (allMissingKeys[key].namespaces.includes(namespace)) {
|
|
170
|
+
const translation = allTranslations[key] || "";
|
|
171
|
+
updatedKeys[key] = translation;
|
|
172
|
+
hasChanges = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (hasChanges) {
|
|
176
|
+
try {
|
|
177
|
+
await writeLocalesFile(savePath, locale, namespace, updatedKeys);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
throw new TranslationError(`Failed to save translations for locale "${locale}" (namespace: ${namespace})`, locale, namespace, error instanceof Error ? error : undefined);
|
|
181
|
+
}
|
|
128
182
|
}
|
|
183
|
+
}));
|
|
184
|
+
// Complete!
|
|
185
|
+
const statusMsg = stats.translated > 0
|
|
186
|
+
? chalk.green(`ā +${stats.translated} translated`)
|
|
187
|
+
: chalk.green(`ā ${stats.reused} reused`);
|
|
188
|
+
bar.update(100, { status: statusMsg });
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (error instanceof TranslationError) {
|
|
192
|
+
throw error;
|
|
129
193
|
}
|
|
130
|
-
|
|
194
|
+
bar.update(100, { status: chalk.red("ā Error") });
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
131
197
|
}));
|
|
198
|
+
// Stop the progress bars
|
|
199
|
+
multibar.stop();
|
|
200
|
+
// Print summary
|
|
201
|
+
console.log("");
|
|
202
|
+
console.log(chalk.green("⨠Sync complete!\n"));
|
|
203
|
+
// Show detailed stats
|
|
204
|
+
let totalMissing = 0;
|
|
205
|
+
let totalReused = 0;
|
|
206
|
+
let totalTranslated = 0;
|
|
207
|
+
for (const locale of localesToProcess) {
|
|
208
|
+
const stats = localeStats[locale];
|
|
209
|
+
totalMissing += stats.missing;
|
|
210
|
+
totalReused += stats.reused;
|
|
211
|
+
totalTranslated += stats.translated;
|
|
212
|
+
}
|
|
213
|
+
if (totalMissing > 0) {
|
|
214
|
+
console.log(chalk.dim(" Summary:"));
|
|
215
|
+
console.log(chalk.dim(` ⢠${chalk.white(totalTranslated)} keys translated`));
|
|
216
|
+
console.log(chalk.dim(` ⢠${chalk.white(totalReused)} keys reused from other namespaces`));
|
|
217
|
+
console.log("");
|
|
218
|
+
}
|
|
132
219
|
}
|
|
133
220
|
catch (error) {
|
|
221
|
+
multibar.stop();
|
|
134
222
|
if (error instanceof TranslationError) {
|
|
135
223
|
throw error;
|
|
136
224
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-locales.js","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"sync-locales.js","sourceRoot":"","sources":["../../src/commands/sync-locales.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,WAAW,MAAM,cAAc,CAAA;AAEtC,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAE9C,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAU,EAAE;IAClD,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAA;IACtD,OAAO,IAAI,EAAE,KAAK,IAAI,MAAM,CAAA;AAC9B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,MAAqB,EAAE,EAAE;IACzD,MAAM,EACJ,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,UAAU,EACV,OAAO,EACP,OAAO,EACP,MAAM,GACP,GAAG,MAAM,CAAA;IAEV,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC,CAAA;IAEnE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,CAAA;IACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,KAA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AC,QAAQ,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,oCAAoC,CAAC,CAAC,CAAA;YAC5F,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QACjB,CAAC;IAEH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,QAAQ,CAAC,IAAI,EAAE,CAAA;QACf,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;YACtC,MAAM,KAAK,CAAA;QACb,CAAC;QACD,MAAM,IAAI,gBAAgB,CACxB,iDAAiD,EACjD,SAAS,EACT,SAAS,EACT,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAC3C,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export declare const translateKey: ({ inputLanguage, context, object, openai, ou
|
|
|
12
12
|
model: string;
|
|
13
13
|
openai: OpenAI;
|
|
14
14
|
}) => Promise<Record<string, string>>;
|
|
15
|
-
export declare const loadLocalesFile: (loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>), locale: string, namespace: string
|
|
15
|
+
export declare const loadLocalesFile: (loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>), locale: string, namespace: string, options?: {
|
|
16
|
+
silent?: boolean;
|
|
17
|
+
}) => Promise<Record<string, string>>;
|
|
16
18
|
export declare const writeLocalesFile: (savePath: string | ((locale: string, namespace: string, data: Record<string, string>) => Promise<void>), locale: string, namespace: string, data: Record<string, string>) => Promise<void>;
|
|
17
19
|
export declare const getPureKey: (key: string, namespace?: string, isDefault?: boolean) => string;
|
|
18
20
|
/**
|
|
@@ -49,7 +51,9 @@ export declare const findExistingTranslation: (key: string, namespaces: string[]
|
|
|
49
51
|
/**
|
|
50
52
|
* Find existing translations for multiple keys in parallel
|
|
51
53
|
*/
|
|
52
|
-
export declare const findExistingTranslations: (keys: string[], namespaces: string[], locale: string, loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>)
|
|
54
|
+
export declare const findExistingTranslations: (keys: string[], namespaces: string[], locale: string, loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>), options?: {
|
|
55
|
+
silent?: boolean;
|
|
56
|
+
}) => Promise<Record<string, string | null>>;
|
|
53
57
|
export declare const getTextInput: (key: string, namespaces?: string[]) => Promise<string>;
|
|
54
58
|
export declare const checkAllKeysExist: ({ namespaces, defaultLocale, loadPath, locales, context, openai, savePath, disableTranslationDuringScan, model, }: Configuration) => Promise<void>;
|
|
55
59
|
export declare class TranslationError extends Error {
|
package/dist/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAGhC,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAElE,eAAO,MAAM,UAAU,GAAU,kBAE9B;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,iBAkB9B,CAAA;AAED,wBAAgB,yBAAyB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE1D;AA0BD,eAAO,MAAM,YAAY,GAAU,oEAOhC;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,oCAyDA,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,UACI,MAAM,GACN,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAC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
|
93
93
|
return result;
|
|
94
94
|
};
|
|
95
|
-
export const loadLocalesFile = async (loadPath, locale, namespace) => {
|
|
95
|
+
export const loadLocalesFile = async (loadPath, locale, namespace, options) => {
|
|
96
|
+
const silent = options?.silent ?? false;
|
|
96
97
|
if (typeof loadPath === "string") {
|
|
97
98
|
const resolvedPath = loadPath
|
|
98
99
|
.replace("{{lng}}", locale)
|
|
99
100
|
.replace("{{ns}}", namespace);
|
|
100
101
|
// Check if file exists, return empty object if it doesn't
|
|
101
102
|
if (!fs.existsSync(resolvedPath)) {
|
|
102
|
-
|
|
103
|
+
if (!silent) {
|
|
104
|
+
console.log(`š Creating new namespace file: ${resolvedPath}`);
|
|
105
|
+
}
|
|
103
106
|
return {};
|
|
104
107
|
}
|
|
105
108
|
const content = fs.readFileSync(resolvedPath, "utf-8");
|
|
@@ -388,12 +391,14 @@ export const findExistingTranslation = async (key, namespaces, locale, loadPath)
|
|
|
388
391
|
/**
|
|
389
392
|
* Find existing translations for multiple keys in parallel
|
|
390
393
|
*/
|
|
391
|
-
export const findExistingTranslations = async (keys, namespaces, locale, loadPath) => {
|
|
394
|
+
export const findExistingTranslations = async (keys, namespaces, locale, loadPath, options) => {
|
|
395
|
+
const silent = options?.silent ?? false;
|
|
396
|
+
const log = silent ? () => { } : console.log;
|
|
392
397
|
// Load all namespace files in parallel first
|
|
393
398
|
const namespaceKeys = {};
|
|
394
399
|
const loadPromises = namespaces.map(async (namespace) => {
|
|
395
400
|
try {
|
|
396
|
-
const existingKeys = await loadLocalesFile(loadPath, locale, namespace);
|
|
401
|
+
const existingKeys = await loadLocalesFile(loadPath, locale, namespace, { silent });
|
|
397
402
|
namespaceKeys[namespace] = existingKeys;
|
|
398
403
|
}
|
|
399
404
|
catch (error) {
|
|
@@ -402,20 +407,20 @@ export const findExistingTranslations = async (keys, namespaces, locale, loadPat
|
|
|
402
407
|
});
|
|
403
408
|
await Promise.all(loadPromises);
|
|
404
409
|
// Log how many keys were found in each namespace for the default locale
|
|
405
|
-
|
|
410
|
+
log(`\nš Searching for existing translations in ${locale}:`);
|
|
406
411
|
for (const namespace of namespaces) {
|
|
407
412
|
const nsKeys = Object.keys(namespaceKeys[namespace] || {});
|
|
408
|
-
|
|
413
|
+
log(` š ${namespace}.json: ${nsKeys.length} keys available`);
|
|
409
414
|
// Show sample keys from the namespace (first 3)
|
|
410
415
|
if (nsKeys.length > 0) {
|
|
411
416
|
const sampleKeys = nsKeys.slice(0, 3);
|
|
412
|
-
|
|
417
|
+
log(` Sample keys: ${sampleKeys.join(", ")}${nsKeys.length > 3 ? "..." : ""}`);
|
|
413
418
|
}
|
|
414
419
|
}
|
|
415
420
|
// Show sample of keys we're searching for
|
|
416
421
|
if (keys.length > 0) {
|
|
417
422
|
const sampleSearchKeys = keys.slice(0, 3);
|
|
418
|
-
|
|
423
|
+
log(`\n š Looking for keys like: ${sampleSearchKeys.join(", ")}${keys.length > 3 ? "..." : ""}`);
|
|
419
424
|
}
|
|
420
425
|
// Now find translations for all keys
|
|
421
426
|
const results = {};
|
|
@@ -440,14 +445,14 @@ export const findExistingTranslations = async (keys, namespaces, locale, loadPat
|
|
|
440
445
|
// Log how many keys were found in each namespace
|
|
441
446
|
const totalFound = Object.values(foundInNamespace).reduce((sum, count) => sum + count, 0);
|
|
442
447
|
const notFound = keys.length - totalFound;
|
|
443
|
-
|
|
448
|
+
log(`\nš Search results for ${keys.length} missing keys:`);
|
|
444
449
|
for (const [namespace, count] of Object.entries(foundInNamespace)) {
|
|
445
|
-
|
|
450
|
+
log(` ā
Found ${count} keys in ${namespace}.json`);
|
|
446
451
|
}
|
|
447
452
|
if (notFound > 0) {
|
|
448
|
-
|
|
453
|
+
log(` ā ${notFound} keys not found in any namespace`);
|
|
449
454
|
}
|
|
450
|
-
|
|
455
|
+
log("");
|
|
451
456
|
return results;
|
|
452
457
|
};
|
|
453
458
|
export const getTextInput = async (key, namespaces) => {
|