i18ntk 4.1.0 → 4.2.1
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/CHANGELOG.md +64 -5
- package/README.md +73 -17
- package/SECURITY.md +10 -4
- package/main/i18ntk-analyze.js +10 -20
- package/main/i18ntk-backup.js +106 -44
- package/main/i18ntk-init.js +153 -157
- package/main/i18ntk-setup.js +36 -13
- package/main/i18ntk-sizing.js +44 -27
- package/main/i18ntk-translate.js +311 -41
- package/main/i18ntk-usage.js +272 -103
- package/main/i18ntk-validate.js +38 -31
- package/main/manage/commands/AnalyzeCommand.js +7 -17
- package/main/manage/commands/CommandRouter.js +6 -6
- package/main/manage/commands/SizingCommand.js +5 -2
- package/main/manage/commands/TranslateCommand.js +73 -56
- package/main/manage/commands/ValidateCommand.js +58 -26
- package/main/manage/index.js +11 -42
- package/main/manage/managers/InteractiveMenu.js +11 -40
- package/main/manage/services/InitService.js +114 -118
- package/main/manage/services/UsageService.js +247 -96
- package/package.json +19 -14
- package/runtime/enhanced.d.ts +5 -5
- package/runtime/enhanced.js +49 -25
- package/runtime/i18ntk.d.ts +30 -7
- package/runtime/index.d.ts +48 -19
- package/runtime/index.js +175 -90
- package/settings/settings-cli.js +115 -38
- package/settings/settings-manager.js +24 -6
- package/ui-locales/de.json +192 -11
- package/ui-locales/en.json +182 -8
- package/ui-locales/es.json +193 -12
- package/ui-locales/fr.json +189 -8
- package/ui-locales/ja.json +190 -8
- package/ui-locales/ru.json +191 -9
- package/ui-locales/zh.json +194 -9
- package/utils/cli-helper.js +8 -12
- package/utils/config-helper.js +1 -1
- package/utils/config-manager.js +8 -6
- package/utils/localized-confirm.js +55 -0
- package/utils/menu-layout.js +41 -0
- package/utils/report-writer.js +110 -0
- package/utils/security.js +15 -22
- package/utils/translate/api.js +31 -3
- package/utils/translate/placeholder.js +42 -1
- package/utils/translate/report.js +32 -4
- package/utils/translate/safe-network.js +24 -4
- package/utils/usage-insights.js +435 -0
- package/utils/usage-source.js +50 -0
- package/utils/watch-locales.js +1 -8
|
@@ -11,7 +11,9 @@ const path = require('path');
|
|
|
11
11
|
const SecurityUtils = require('../../../utils/security');
|
|
12
12
|
const configManager = require('../../../utils/config-manager');
|
|
13
13
|
const { getUnifiedConfig } = require('../../../utils/config-helper');
|
|
14
|
-
const { loadTranslations } = require('../../../utils/i18n-helper');
|
|
14
|
+
const { loadTranslations, t } = require('../../../utils/i18n-helper');
|
|
15
|
+
const { parseConfirmation } = require('../../../utils/localized-confirm');
|
|
16
|
+
const { DEFAULT_CONCURRENCY, getProviderConcurrencyLimit } = require('../../../utils/translate/api');
|
|
15
17
|
const SetupEnforcer = require('../../../utils/setup-enforcer');
|
|
16
18
|
const {
|
|
17
19
|
createProtectionFile,
|
|
@@ -38,6 +40,11 @@ class TranslateCommand {
|
|
|
38
40
|
this.safeClose = safeClose;
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
tr(key, replacements = {}, fallback = '') {
|
|
44
|
+
const value = t(key, replacements);
|
|
45
|
+
return value && value !== key ? value : fallback;
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
async execute(options = {}) {
|
|
42
49
|
try {
|
|
43
50
|
await SetupEnforcer.checkSetupCompleteAsync();
|
|
@@ -46,15 +53,15 @@ class TranslateCommand {
|
|
|
46
53
|
return { success: false, error: 'Setup required' };
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
loadTranslations('en', path.resolve(__dirname, '..', '..', '..', 'ui-locales'));
|
|
50
|
-
|
|
51
56
|
const config = this.config || {};
|
|
52
57
|
let unified;
|
|
53
58
|
try {
|
|
54
|
-
unified = await getUnifiedConfig('translate', options);
|
|
59
|
+
unified = { ...(await getUnifiedConfig('translate', options)), ...config };
|
|
55
60
|
} catch (_) {
|
|
56
61
|
unified = config;
|
|
57
62
|
}
|
|
63
|
+
const uiLanguage = unified.uiLanguage || unified.language || 'en';
|
|
64
|
+
loadTranslations(uiLanguage, path.resolve(__dirname, '..', '..', '..', 'ui-locales'));
|
|
58
65
|
this.autoTranslateSettings = this.getAutoTranslateSettings(unified);
|
|
59
66
|
|
|
60
67
|
const defaultSourceDir = unified.sourceDir || unified.i18nDir || path.resolve(process.cwd(), 'locales', 'en');
|
|
@@ -62,13 +69,13 @@ class TranslateCommand {
|
|
|
62
69
|
this.configuredTargetLangs = this.getConfiguredTargetLanguages(unified, defaultSourceDir);
|
|
63
70
|
|
|
64
71
|
console.log('\n============================================================');
|
|
65
|
-
console.log('
|
|
72
|
+
console.log(` ${t('translate.title') || '\u{1F310} Auto Translate'}`);
|
|
66
73
|
console.log('============================================================');
|
|
67
74
|
|
|
68
75
|
if (this.isNonInteractiveMode) {
|
|
69
76
|
this.sourceDir = defaultSourceDir;
|
|
70
77
|
if (!SecurityUtils.safeExistsSync(this.sourceDir, path.dirname(this.sourceDir))) {
|
|
71
|
-
console.error(`Source locale directory not found: ${this.sourceDir}`);
|
|
78
|
+
console.error(this.tr('translate.errors.sourceDirectoryNotFound', { dir: this.sourceDir }, `Source locale directory not found: ${this.sourceDir}`));
|
|
72
79
|
return { success: false, error: 'Source directory not found' };
|
|
73
80
|
}
|
|
74
81
|
const resolvedSource = this.resolveSourceDirectoryForLanguage(this.sourceDir, this.sourceLang);
|
|
@@ -105,25 +112,25 @@ class TranslateCommand {
|
|
|
105
112
|
|
|
106
113
|
async promptSourceDir(ask, defaultDir) {
|
|
107
114
|
while (true) {
|
|
108
|
-
console.log('\n Source locale directory');
|
|
109
|
-
console.log(`
|
|
110
|
-
console.log(`
|
|
111
|
-
console.log(' Accepted: an absolute path, or a path relative to the current project.');
|
|
112
|
-
console.log(' Examples:');
|
|
115
|
+
console.log('\n ' + this.tr('translate.sourceDirectory.title', {}, 'Source locale directory'));
|
|
116
|
+
console.log(' ' + this.tr('translate.common.default', { value: defaultDir }, `Default: ${defaultDir}`));
|
|
117
|
+
console.log(' ' + this.tr('translate.sourceDirectory.currentProject', { dir: process.cwd() }, `Current project: ${process.cwd()}`));
|
|
118
|
+
console.log(' ' + this.tr('translate.sourceDirectory.accepted', {}, 'Accepted: an absolute path, or a path relative to the current project.'));
|
|
119
|
+
console.log(' ' + this.tr('translate.common.examples', {}, 'Examples:'));
|
|
113
120
|
console.log(' ./locales/en');
|
|
114
|
-
console.log(' ./locales (then choose source language: en)');
|
|
121
|
+
console.log(' ' + this.tr('translate.sourceDirectory.localeRootExample', {}, './locales (then choose source language: en)'));
|
|
115
122
|
console.log(` ${defaultDir}`);
|
|
116
|
-
console.log(' The folder can contain JSON files directly, or language folders such as ./locales/en.');
|
|
117
|
-
console.log(' Press Enter to use the default.');
|
|
123
|
+
console.log(' ' + this.tr('translate.sourceDirectory.folderHint', {}, 'The folder can contain JSON files directly, or language folders such as ./locales/en.'));
|
|
124
|
+
console.log(' ' + this.tr('translate.common.pressEnterDefault', {}, 'Press Enter to use the default.'));
|
|
118
125
|
const input = await ask(' > ');
|
|
119
126
|
|
|
120
127
|
if (!input.trim()) {
|
|
121
128
|
if (!SecurityUtils.safeExistsSync(defaultDir, path.dirname(defaultDir))) {
|
|
122
|
-
console.log(`
|
|
123
|
-
console.log(' Please enter an existing directory with JSON locale files.');
|
|
129
|
+
console.log(' ' + this.tr('translate.sourceDirectory.defaultNotFound', { dir: defaultDir }, `Default directory not found: ${defaultDir}`));
|
|
130
|
+
console.log(' ' + this.tr('translate.sourceDirectory.enterExisting', {}, 'Please enter an existing directory with JSON locale files.'));
|
|
124
131
|
continue;
|
|
125
132
|
}
|
|
126
|
-
console.log(`
|
|
133
|
+
console.log(' ' + this.tr('translate.common.usingDefault', { value: defaultDir }, `Using default: ${defaultDir}`));
|
|
127
134
|
return defaultDir;
|
|
128
135
|
}
|
|
129
136
|
|
|
@@ -132,31 +139,31 @@ class TranslateCommand {
|
|
|
132
139
|
? path.resolve(cleanInput)
|
|
133
140
|
: path.resolve(process.cwd(), cleanInput);
|
|
134
141
|
if (!SecurityUtils.safeExistsSync(resolved, path.dirname(resolved))) {
|
|
135
|
-
console.log(`
|
|
136
|
-
console.log(' Enter an existing folder, for example ./locales/en.');
|
|
142
|
+
console.log(' ' + this.tr('translate.sourceDirectory.directoryNotFound', { dir: resolved }, `Directory not found: ${resolved}`));
|
|
143
|
+
console.log(' ' + this.tr('translate.sourceDirectory.enterFolderExample', {}, 'Enter an existing folder, for example ./locales/en.'));
|
|
137
144
|
continue;
|
|
138
145
|
}
|
|
139
146
|
const stats = SecurityUtils.safeStatSync(resolved, path.dirname(resolved));
|
|
140
147
|
if (!stats || !stats.isDirectory()) {
|
|
141
|
-
console.log(`
|
|
148
|
+
console.log(' ' + this.tr('translate.sourceDirectory.notDirectory', { dir: resolved }, `Not a directory: ${resolved}`));
|
|
142
149
|
continue;
|
|
143
150
|
}
|
|
144
|
-
console.log(`
|
|
151
|
+
console.log(' ' + this.tr('translate.sourceDirectory.using', { dir: resolved }, `Using source directory: ${resolved}`));
|
|
145
152
|
return resolved;
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
|
|
149
156
|
async promptSourceLang(ask) {
|
|
150
157
|
while (true) {
|
|
151
|
-
console.log('\n Source language code');
|
|
152
|
-
console.log(`
|
|
153
|
-
console.log(' This should match the language of the source JSON values.');
|
|
154
|
-
console.log(' Example: en');
|
|
155
|
-
console.log(' Press Enter to use the default.');
|
|
158
|
+
console.log('\n ' + this.tr('translate.sourceLanguage.title', {}, 'Source language code'));
|
|
159
|
+
console.log(' ' + this.tr('translate.common.default', { value: this.sourceLang }, `Default: ${this.sourceLang}`));
|
|
160
|
+
console.log(' ' + this.tr('translate.sourceLanguage.hint', {}, 'This should match the language of the source JSON values.'));
|
|
161
|
+
console.log(' ' + this.tr('translate.common.exampleValue', { value: 'en' }, 'Example: en'));
|
|
162
|
+
console.log(' ' + this.tr('translate.common.pressEnterDefault', {}, 'Press Enter to use the default.'));
|
|
156
163
|
const input = await ask(' > ');
|
|
157
164
|
|
|
158
165
|
if (!input.trim()) {
|
|
159
|
-
console.log(`
|
|
166
|
+
console.log(' ' + this.tr('translate.sourceLanguage.using', { lang: this.sourceLang }, `Using source language: ${this.sourceLang}`));
|
|
160
167
|
return this.sourceLang;
|
|
161
168
|
}
|
|
162
169
|
|
|
@@ -164,46 +171,46 @@ class TranslateCommand {
|
|
|
164
171
|
if (lang.length >= 2) {
|
|
165
172
|
return lang;
|
|
166
173
|
}
|
|
167
|
-
console.log(' Invalid language code. Use 2+ characters (e.g. en, de, fr).');
|
|
174
|
+
console.log(' ' + this.tr('translate.sourceLanguage.invalid', {}, 'Invalid language code. Use 2+ characters (e.g. en, de, fr).'));
|
|
168
175
|
}
|
|
169
176
|
}
|
|
170
177
|
|
|
171
178
|
async interactiveFlow(jsonFiles, ask) {
|
|
172
179
|
await this.maybeConfigureProtection(ask);
|
|
173
180
|
|
|
174
|
-
console.log('\n Target language(s)');
|
|
181
|
+
console.log('\n ' + this.tr('translate.targetLanguages.title', {}, 'Target language(s)'));
|
|
175
182
|
if (this.configuredTargetLangs.length > 0) {
|
|
176
|
-
console.log(`
|
|
183
|
+
console.log(' ' + this.tr('translate.targetLanguages.allConfigured', { languages: this.configuredTargetLangs.join(', ') }, `a) All configured target languages: ${this.configuredTargetLangs.join(', ')}`));
|
|
177
184
|
} else {
|
|
178
|
-
console.log(' a) All configured target languages: none configured');
|
|
185
|
+
console.log(' ' + this.tr('translate.targetLanguages.noneConfigured', {}, 'a) All configured target languages: none configured'));
|
|
179
186
|
}
|
|
180
|
-
console.log(' Or enter one or more comma/space-separated language codes.');
|
|
181
|
-
console.log(' Examples: de, es, fr or de es fr or zh');
|
|
182
|
-
console.log(`
|
|
187
|
+
console.log(' ' + this.tr('translate.targetLanguages.enterCodes', {}, 'Or enter one or more comma/space-separated language codes.'));
|
|
188
|
+
console.log(' ' + this.tr('translate.common.examplesInline', { examples: 'de, es, fr or de es fr or zh' }, 'Examples: de, es, fr or de es fr or zh'));
|
|
189
|
+
console.log(' ' + this.tr('translate.targetLanguages.sourceExcluded', { lang: this.sourceLang }, `Source language "${this.sourceLang}" will be excluded automatically.`));
|
|
183
190
|
const langInput = await ask(' > ');
|
|
184
191
|
|
|
185
192
|
const targetLangs = this.parseTargetLanguages(langInput);
|
|
186
193
|
|
|
187
194
|
if (targetLangs.length === 0) {
|
|
188
|
-
console.log(' No valid target languages selected. Aborting.');
|
|
195
|
+
console.log(' ' + this.tr('translate.targetLanguages.noneSelected', {}, 'No valid target languages selected. Aborting.'));
|
|
189
196
|
if (this.configuredTargetLangs.length === 0) {
|
|
190
|
-
console.log(' Configure defaultLanguages in .i18ntk-config, or enter target codes manually.');
|
|
197
|
+
console.log(' ' + this.tr('translate.targetLanguages.configureHint', {}, 'Configure defaultLanguages in .i18ntk-config, or enter target codes manually.'));
|
|
191
198
|
}
|
|
192
199
|
return { success: false, error: 'Invalid language code' };
|
|
193
200
|
}
|
|
194
201
|
|
|
195
|
-
console.log(
|
|
202
|
+
console.log('\n ' + this.tr('translate.targetLanguages.selected', { languages: targetLangs.join(', ') }, `Target languages: ${targetLangs.join(', ')}`));
|
|
196
203
|
|
|
197
|
-
console.log(
|
|
204
|
+
console.log('\n ' + this.tr('translate.files.title', {}, 'Which file(s) to translate?'));
|
|
198
205
|
const filePreview = jsonFiles.length <= 6
|
|
199
206
|
? jsonFiles.join(', ')
|
|
200
207
|
: `${jsonFiles.slice(0, 6).join(', ')}, ...`;
|
|
201
|
-
console.log(`
|
|
208
|
+
console.log(' ' + this.tr('translate.files.all', { count: jsonFiles.length, files: filePreview }, `a) All JSON files (${jsonFiles.length}: ${filePreview})`));
|
|
202
209
|
jsonFiles.forEach((f, i) => {
|
|
203
210
|
console.log(` ${i + 1}) ${f}`);
|
|
204
211
|
});
|
|
205
212
|
|
|
206
|
-
const fileChoice = await ask('\n Choice [a/all or file number]: ');
|
|
213
|
+
const fileChoice = await ask('\n ' + this.tr('translate.files.choicePrompt', {}, 'Choice [a/all or file number]: '));
|
|
207
214
|
let sourceFiles;
|
|
208
215
|
|
|
209
216
|
if (['a', 'all', '*'].includes(fileChoice.trim().toLowerCase())) {
|
|
@@ -211,7 +218,7 @@ class TranslateCommand {
|
|
|
211
218
|
} else {
|
|
212
219
|
const idx = parseInt(fileChoice, 10) - 1;
|
|
213
220
|
if (isNaN(idx) || idx < 0 || idx >= jsonFiles.length) {
|
|
214
|
-
console.log(' Invalid choice. Aborting.');
|
|
221
|
+
console.log(' ' + this.tr('translate.files.invalidChoice', {}, 'Invalid choice. Aborting.'));
|
|
215
222
|
return { success: false, error: 'Invalid file choice' };
|
|
216
223
|
}
|
|
217
224
|
sourceFiles = [path.join(this.sourceDir, jsonFiles[idx])];
|
|
@@ -220,39 +227,47 @@ class TranslateCommand {
|
|
|
220
227
|
if (this.autoTranslateSettings.dryRunFirst !== false) {
|
|
221
228
|
// Dry-run for first language only (all languages use same source so same keys)
|
|
222
229
|
const firstLang = targetLangs[0];
|
|
223
|
-
console.log(
|
|
230
|
+
console.log('\n ' + this.tr('translate.dryRun.previewFor', { lang: firstLang }, `Dry-run preview for "${firstLang}"...`) + '\n');
|
|
224
231
|
await this.runTranslate(sourceFiles, firstLang, { dryRun: true });
|
|
225
232
|
}
|
|
226
233
|
|
|
227
|
-
console.log('\n Proceed with actual translation?');
|
|
228
|
-
const answer = await ask(' [y]es / [n]o: ');
|
|
229
|
-
if (
|
|
230
|
-
console.log(' Translation cancelled.');
|
|
234
|
+
console.log('\n ' + this.tr('translate.confirm.proceed', {}, 'Proceed with actual translation?'));
|
|
235
|
+
const answer = await ask(' ' + this.tr('translate.confirm.yesNoPrompt', {}, '[y]es / [n]o: '));
|
|
236
|
+
if (!parseConfirmation(answer, { language: this.config.uiLanguage || this.config.language || 'en', defaultValue: false })) {
|
|
237
|
+
console.log(' ' + this.tr('translate.confirm.cancelled', {}, 'Translation cancelled.'));
|
|
231
238
|
return { success: true, cancelled: true };
|
|
232
239
|
}
|
|
233
240
|
|
|
234
241
|
let results = [];
|
|
235
242
|
for (const lang of targetLangs) {
|
|
236
|
-
console.log(
|
|
243
|
+
console.log('\n ' + this.tr('translate.run.translatingTo', { lang }, `Translating to "${lang}"...`) + '\n');
|
|
237
244
|
try {
|
|
238
245
|
await this.runTranslate(sourceFiles, lang, { dryRun: false });
|
|
239
246
|
results.push({ lang, ok: true });
|
|
240
247
|
} catch (e) {
|
|
241
|
-
console.error(`
|
|
248
|
+
console.error(' ' + this.tr('translate.run.failedFor', { lang, error: e.message }, `Failed for "${lang}": ${e.message}`));
|
|
242
249
|
results.push({ lang, ok: false, error: e.message });
|
|
243
250
|
}
|
|
244
251
|
}
|
|
245
252
|
|
|
246
|
-
console.log('\n Summary:');
|
|
253
|
+
console.log('\n ' + this.tr('translate.summary.title', {}, 'Summary:'));
|
|
247
254
|
for (const r of results) {
|
|
248
255
|
console.log(` ${r.ok ? '\u{2705}' : '\u{274C}'} ${r.lang}${r.error ? ' (' + r.error + ')' : ''}`);
|
|
249
256
|
}
|
|
250
|
-
|
|
257
|
+
const failed = results.filter(r => !r.ok);
|
|
258
|
+
if (failed.length > 0) {
|
|
259
|
+
const message = failed.length === 1
|
|
260
|
+
? `Translation finished with warnings for ${failed[0].lang}. Rerun Auto Translate to capture leftovers.`
|
|
261
|
+
: `Translation finished with warnings for ${failed.length} languages. Rerun Auto Translate to capture leftovers.`;
|
|
262
|
+
console.log('\n ' + this.tr('translate.summary.incomplete', { count: failed.length }, message));
|
|
263
|
+
return { success: false, results, error: message };
|
|
264
|
+
}
|
|
265
|
+
console.log('\n ' + this.tr('translate.summary.complete', {}, 'Translation complete!'));
|
|
251
266
|
return { success: true, results };
|
|
252
267
|
}
|
|
253
268
|
|
|
254
269
|
async nonInteractiveFlow(jsonFiles) {
|
|
255
|
-
console.log('\n Non-interactive mode. Use direct CLI instead:');
|
|
270
|
+
console.log('\n ' + this.tr('translate.nonInteractive.useDirect', {}, 'Non-interactive mode. Use direct CLI instead:'));
|
|
256
271
|
console.log(' i18ntk-translate <source> <lang> [options]');
|
|
257
272
|
return { success: false, error: 'Non-interactive mode not supported from menu' };
|
|
258
273
|
}
|
|
@@ -278,8 +293,8 @@ class TranslateCommand {
|
|
|
278
293
|
const languageJsonFiles = this.getJsonFiles(languageDir);
|
|
279
294
|
if (languageJsonFiles.length > 0) {
|
|
280
295
|
if (shouldLog) {
|
|
281
|
-
console.log(`
|
|
282
|
-
console.log(`
|
|
296
|
+
console.log(' ' + this.tr('translate.sourceDirectory.noJsonDirect', { dir: selectedDir }, `No JSON files found directly in: ${selectedDir}`));
|
|
297
|
+
console.log(' ' + this.tr('translate.sourceDirectory.usingLanguageFolder', { dir: languageDir }, `Using source language folder: ${languageDir}`));
|
|
283
298
|
}
|
|
284
299
|
return { ok: true, sourceDir: languageDir, jsonFiles: languageJsonFiles };
|
|
285
300
|
}
|
|
@@ -288,8 +303,8 @@ class TranslateCommand {
|
|
|
288
303
|
|
|
289
304
|
const checkedLanguageDir = cleanLang ? path.join(selectedDir, cleanLang) : null;
|
|
290
305
|
const message = checkedLanguageDir
|
|
291
|
-
? `No JSON files found in: ${selectedDir}\nAlso checked source language folder: ${checkedLanguageDir}`
|
|
292
|
-
: `No JSON files found in: ${selectedDir}
|
|
306
|
+
? this.tr('translate.sourceDirectory.noJsonWithLanguageFolder', { dir: selectedDir, languageDir: checkedLanguageDir }, `No JSON files found in: ${selectedDir}\nAlso checked source language folder: ${checkedLanguageDir}`)
|
|
307
|
+
: this.tr('translate.sourceDirectory.noJson', { dir: selectedDir }, `No JSON files found in: ${selectedDir}`);
|
|
293
308
|
return { ok: false, sourceDir: selectedDir, jsonFiles: [], message };
|
|
294
309
|
}
|
|
295
310
|
|
|
@@ -343,13 +358,14 @@ class TranslateCommand {
|
|
|
343
358
|
placeholderMode: ['preserve', 'skip', 'send'].includes(settings.placeholderMode)
|
|
344
359
|
? settings.placeholderMode
|
|
345
360
|
: 'preserve',
|
|
346
|
-
concurrency: this.toInt(settings.concurrency,
|
|
361
|
+
concurrency: this.toInt(settings.concurrency, DEFAULT_CONCURRENCY, 1, getProviderConcurrencyLimit(settings.provider || 'google')),
|
|
347
362
|
batchSize: this.toInt(settings.batchSize, 100, 1, 10000),
|
|
348
363
|
progressInterval: this.toInt(settings.progressInterval, 25, 1, 10000),
|
|
349
364
|
retryCount: this.toInt(settings.retryCount, 3, 0, 10),
|
|
350
365
|
retryDelay: this.toInt(settings.retryDelay, 1000, 0, 30000),
|
|
351
366
|
timeout: this.toInt(settings.timeout, 15000, 1000, 120000),
|
|
352
367
|
dryRunFirst: settings.dryRunFirst !== false,
|
|
368
|
+
onlyMissingOrEnglish: settings.onlyMissingOrEnglish !== false,
|
|
353
369
|
reportStdout: settings.reportStdout !== false,
|
|
354
370
|
bom: settings.bom === true,
|
|
355
371
|
protectionEnabled: settings.protectionEnabled !== false,
|
|
@@ -480,6 +496,7 @@ class TranslateCommand {
|
|
|
480
496
|
args.noConfirm = true;
|
|
481
497
|
args.sourceLang = this.sourceLang || 'en';
|
|
482
498
|
args.dryRun = opts.dryRun === true;
|
|
499
|
+
args.onlyMissingOrEnglish = settings.onlyMissingOrEnglish;
|
|
483
500
|
args.reportStdout = settings.reportStdout;
|
|
484
501
|
args.bom = settings.bom;
|
|
485
502
|
args.concurrency = settings.concurrency;
|
|
@@ -37,8 +37,11 @@ class ValidateCommand {
|
|
|
37
37
|
this.warnings = [];
|
|
38
38
|
this.rl = null;
|
|
39
39
|
this.sourceDir = null;
|
|
40
|
-
this.i18nDir = null;
|
|
41
|
-
this.sourceLanguageDir = null;
|
|
40
|
+
this.i18nDir = null;
|
|
41
|
+
this.sourceLanguageDir = null;
|
|
42
|
+
this.initialized = false;
|
|
43
|
+
this.pathsDisplayed = false;
|
|
44
|
+
this.validationBannerDisplayed = false;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/**
|
|
@@ -53,8 +56,12 @@ class ValidateCommand {
|
|
|
53
56
|
/**
|
|
54
57
|
* Initialize the validator with configuration
|
|
55
58
|
*/
|
|
56
|
-
async initialize() {
|
|
57
|
-
try {
|
|
59
|
+
async initialize() {
|
|
60
|
+
try {
|
|
61
|
+
if (this.initialized) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
58
65
|
// Initialize i18n with UI language first
|
|
59
66
|
const args = this.parseArgs();
|
|
60
67
|
if (args.help) {
|
|
@@ -101,7 +108,9 @@ class ValidateCommand {
|
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
110
|
|
|
104
|
-
displayPaths({ sourceDir: this.sourceDir, i18nDir: this.i18nDir, outputDir: this.config.outputDir });
|
|
111
|
+
displayPaths({ sourceDir: this.sourceDir, i18nDir: this.i18nDir, outputDir: this.config.outputDir });
|
|
112
|
+
this.pathsDisplayed = true;
|
|
113
|
+
this.initialized = true;
|
|
105
114
|
|
|
106
115
|
SecurityUtils.logSecurityEvent(
|
|
107
116
|
'I18n validator initialized successfully',
|
|
@@ -660,6 +669,30 @@ class ValidateCommand {
|
|
|
660
669
|
);
|
|
661
670
|
});
|
|
662
671
|
|
|
672
|
+
if (this.errors.length > 0) {
|
|
673
|
+
lines.push('');
|
|
674
|
+
lines.push('Errors');
|
|
675
|
+
lines.push('------');
|
|
676
|
+
this.errors.forEach((error, index) => {
|
|
677
|
+
lines.push(`${index + 1}. ${error.message}`);
|
|
678
|
+
if (error.details && Object.keys(error.details).length > 0) {
|
|
679
|
+
lines.push(` Details: ${JSON.stringify(error.details, null, 2).replace(/\n/g, '\n ')}`);
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
if (this.warnings.length > 0) {
|
|
685
|
+
lines.push('');
|
|
686
|
+
lines.push('Warnings');
|
|
687
|
+
lines.push('--------');
|
|
688
|
+
this.warnings.forEach((warning, index) => {
|
|
689
|
+
lines.push(`${index + 1}. ${warning.message}`);
|
|
690
|
+
if (warning.details && Object.keys(warning.details).length > 0) {
|
|
691
|
+
lines.push(` Details: ${JSON.stringify(warning.details, null, 2).replace(/\n/g, '\n ')}`);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
|
|
663
696
|
SecurityUtils.safeWriteFileSync(reportPath, lines.join('\n') + '\n', process.cwd(), 'utf8');
|
|
664
697
|
return reportPath;
|
|
665
698
|
} catch (error) {
|
|
@@ -673,9 +706,12 @@ class ValidateCommand {
|
|
|
673
706
|
const args = this.parseArgs();
|
|
674
707
|
const jsonOutput = new JsonOutput('validate');
|
|
675
708
|
|
|
676
|
-
if (!args.json) {
|
|
677
|
-
console.log(
|
|
678
|
-
console.log(t('validate.
|
|
709
|
+
if (!args.json) {
|
|
710
|
+
console.log('');
|
|
711
|
+
console.log(t('validate.title'));
|
|
712
|
+
if (!this.validationBannerDisplayed) {
|
|
713
|
+
console.log(t('validate.message'));
|
|
714
|
+
}
|
|
679
715
|
|
|
680
716
|
// Delete old validation report if it exists
|
|
681
717
|
const reportPath = path.join(process.cwd(), 'validation-report.txt');
|
|
@@ -705,11 +741,14 @@ class ValidateCommand {
|
|
|
705
741
|
this.config.strictMode = true;
|
|
706
742
|
}
|
|
707
743
|
|
|
708
|
-
if (!args.json) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
744
|
+
if (!args.json) {
|
|
745
|
+
if (!this.pathsDisplayed) {
|
|
746
|
+
console.log(t('validate.sourceDirectory', { dir: this.sourceDir }));
|
|
747
|
+
}
|
|
748
|
+
console.log(t('validate.sourceLanguage', { sourceLanguage: this.config.sourceLanguage }));
|
|
749
|
+
console.log(t('validate.strictMode', { mode: this.config.strictMode ? 'ON' : 'OFF' }));
|
|
750
|
+
console.log('');
|
|
751
|
+
}
|
|
713
752
|
|
|
714
753
|
// Validate source language directory exists
|
|
715
754
|
SecurityUtils.validatePath(this.sourceLanguageDir);
|
|
@@ -933,17 +972,9 @@ class ValidateCommand {
|
|
|
933
972
|
this.config = {};
|
|
934
973
|
}
|
|
935
974
|
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
this.config = { ...baseConfig, ...this.config };
|
|
940
|
-
|
|
941
|
-
const uiLanguage = (this.config && this.config.uiLanguage) || 'en';
|
|
942
|
-
loadTranslations(uiLanguage, path.resolve(__dirname, '../../../resources', 'i18n', 'ui-locales'));this.sourceDir = this.config.sourceDir;
|
|
943
|
-
this.sourceLanguageDir = path.join(this.sourceDir, this.config.sourceLanguage);
|
|
944
|
-
} else {
|
|
945
|
-
await this.initialize();
|
|
946
|
-
}
|
|
975
|
+
if (!this.initialized) {
|
|
976
|
+
await this.initialize();
|
|
977
|
+
}
|
|
947
978
|
|
|
948
979
|
// Skip admin authentication when called from menu
|
|
949
980
|
if (!fromMenu) {
|
|
@@ -972,8 +1003,9 @@ class ValidateCommand {
|
|
|
972
1003
|
}
|
|
973
1004
|
const execute = async () => {
|
|
974
1005
|
|
|
975
|
-
console.log(t('validate.startingValidationProcess'));
|
|
976
|
-
|
|
1006
|
+
console.log('\n' + t('validate.startingValidationProcess'));
|
|
1007
|
+
this.validationBannerDisplayed = true;
|
|
1008
|
+
SecurityUtils.logSecurityEvent(
|
|
977
1009
|
t('validate.runStarted'),
|
|
978
1010
|
'info',
|
|
979
1011
|
{ message: 'Starting validation run' }
|
package/main/manage/index.js
CHANGED
|
@@ -27,6 +27,7 @@ const cliHelper = require('../../utils/cli-helper');
|
|
|
27
27
|
const { printUpgradeWarningIfOutdated } = require('../../utils/npm-version-warning');
|
|
28
28
|
const { blue } = require('../../utils/colors-new');
|
|
29
29
|
const { loadConfig, saveConfig, ensureConfigDefaults } = require('../../utils/config');
|
|
30
|
+
const { buildMainMenuLines } = require('../../utils/menu-layout');
|
|
30
31
|
const SettingsCLI = require('../../settings/settings-cli');
|
|
31
32
|
const pkg = require('../../package.json');
|
|
32
33
|
const SetupEnforcer = require('../../utils/setup-enforcer');
|
|
@@ -858,52 +859,20 @@ class I18nManager {
|
|
|
858
859
|
return cfg;
|
|
859
860
|
}
|
|
860
861
|
|
|
861
|
-
async showInteractiveMenu() {
|
|
862
|
-
// Check if we're in non-interactive mode (like echo 0 | node script)
|
|
863
|
-
if (this.isNonInteractiveMode()) {
|
|
864
|
-
console.log(
|
|
865
|
-
|
|
866
|
-
console.log(
|
|
867
|
-
console.log(
|
|
868
|
-
console.log(`3. ${t('menu.options.validate')}`);
|
|
869
|
-
console.log(`4. ${t('menu.options.usage')}`);
|
|
870
|
-
console.log(`5. ${t('menu.options.complete')}`);
|
|
871
|
-
console.log(`6. ${t('menu.options.sizing')}`);
|
|
872
|
-
console.log(`7. ${t('menu.options.fix')}`);
|
|
873
|
-
console.log(`8. ${t('menu.options.status')}`);
|
|
874
|
-
console.log(`9. ${t('menu.options.delete')}`);
|
|
875
|
-
console.log(`10. ${t('menu.options.settings')}`);
|
|
876
|
-
console.log(`11. ${t('menu.options.help')}`);
|
|
877
|
-
console.log(`12. ${t('menu.options.language')}`);
|
|
878
|
-
console.log(`13. ${t('menu.options.scanner')}`);
|
|
879
|
-
console.log(`14. ${t('menu.options.translate')}`);
|
|
880
|
-
console.log(`0. ${t('menu.options.exit')}`);
|
|
881
|
-
|
|
882
|
-
console.log('\n' + t('menu.nonInteractiveModeWarning'));
|
|
883
|
-
console.log(t('menu.useDirectExecution'));
|
|
862
|
+
async showInteractiveMenu() {
|
|
863
|
+
// Check if we're in non-interactive mode (like echo 0 | node script)
|
|
864
|
+
if (this.isNonInteractiveMode()) {
|
|
865
|
+
console.log(buildMainMenuLines(t).join('\n'));
|
|
866
|
+
|
|
867
|
+
console.log('\n' + t('menu.nonInteractiveModeWarning'));
|
|
868
|
+
console.log(t('menu.useDirectExecution'));
|
|
884
869
|
console.log(t('menu.useHelpForCommands'));
|
|
885
870
|
this.safeClose();
|
|
886
871
|
process.exit(0);
|
|
887
872
|
return;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
console.log(
|
|
891
|
-
console.log(t('menu.separator'));
|
|
892
|
-
console.log(`1. ${t('menu.options.init')}`);
|
|
893
|
-
console.log(`2. ${t('menu.options.analyze')}`);
|
|
894
|
-
console.log(`3. ${t('menu.options.validate')}`);
|
|
895
|
-
console.log(`4. ${t('menu.options.usage')}`);
|
|
896
|
-
console.log(`5. ${t('menu.options.complete')}`);
|
|
897
|
-
console.log(`6. ${t('menu.options.sizing')}`);
|
|
898
|
-
console.log(`7. ${t('menu.options.fix')}`);
|
|
899
|
-
console.log(`8. ${t('menu.options.status')}`);
|
|
900
|
-
console.log(`9. ${t('menu.options.delete')}`);
|
|
901
|
-
console.log(`10. ${t('menu.options.settings')}`);
|
|
902
|
-
console.log(`11. ${t('menu.options.help')}`);
|
|
903
|
-
console.log(`12. ${t('menu.options.language')}`);
|
|
904
|
-
console.log(`13. ${t('menu.options.scanner')}`);
|
|
905
|
-
console.log(`14. ${t('menu.options.translate')}`);
|
|
906
|
-
console.log(`0. ${t('menu.options.exit')}`);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
console.log(buildMainMenuLines(t).join('\n'));
|
|
907
876
|
|
|
908
877
|
const choice = await this.prompt('\n' + t('menu.selectOptionPrompt'));
|
|
909
878
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const { t } = require('../../../utils/i18n-helper');
|
|
11
11
|
const cliHelper = require('../../../utils/cli-helper');
|
|
12
|
+
const { buildMainMenuLines } = require('../../../utils/menu-layout');
|
|
12
13
|
const summaryTool = require('../../i18ntk-summary');
|
|
13
14
|
|
|
14
15
|
module.exports = class InteractiveMenu {
|
|
@@ -22,49 +23,19 @@ module.exports = class InteractiveMenu {
|
|
|
22
23
|
* Display the main interactive menu with 13 options
|
|
23
24
|
*/
|
|
24
25
|
async showInteractiveMenu() {
|
|
25
|
-
// Check if we're in non-interactive mode (like echo 0 | node script)
|
|
26
|
-
if (this.manager.isNonInteractiveMode()) {
|
|
27
|
-
console.log(
|
|
28
|
-
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(
|
|
31
|
-
console.log(`3. ${t('menu.options.validate')}`);
|
|
32
|
-
console.log(`4. ${t('menu.options.usage')}`);
|
|
33
|
-
console.log(`5. ${t('menu.options.complete')}`);
|
|
34
|
-
console.log(`6. ${t('menu.options.sizing')}`);
|
|
35
|
-
console.log(`7. ${t('menu.options.fix')}`);
|
|
36
|
-
console.log(`8. ${t('menu.options.status')}`);
|
|
37
|
-
console.log(`9. ${t('menu.options.delete')}`);
|
|
38
|
-
console.log(`10. ${t('menu.options.settings')}`);
|
|
39
|
-
console.log(`11. ${t('menu.options.help')}`);
|
|
40
|
-
console.log(`12. ${t('menu.options.language')}`);
|
|
41
|
-
console.log(`13. ${t('menu.options.scanner')}`);
|
|
42
|
-
console.log(`0. ${t('menu.options.exit')}`);
|
|
43
|
-
|
|
44
|
-
console.log('\n' + t('menu.nonInteractiveModeWarning'));
|
|
45
|
-
console.log(t('menu.useDirectExecution'));
|
|
26
|
+
// Check if we're in non-interactive mode (like echo 0 | node script)
|
|
27
|
+
if (this.manager.isNonInteractiveMode()) {
|
|
28
|
+
console.log(buildMainMenuLines(t, { includeTranslate: false }).join('\n'));
|
|
29
|
+
|
|
30
|
+
console.log('\n' + t('menu.nonInteractiveModeWarning'));
|
|
31
|
+
console.log(t('menu.useDirectExecution'));
|
|
46
32
|
console.log(t('menu.useHelpForCommands'));
|
|
47
33
|
this.manager.safeClose();
|
|
48
34
|
process.exit(0);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log(
|
|
53
|
-
console.log(t('menu.separator'));
|
|
54
|
-
console.log(`1. ${t('menu.options.init')}`);
|
|
55
|
-
console.log(`2. ${t('menu.options.analyze')}`);
|
|
56
|
-
console.log(`3. ${t('menu.options.validate')}`);
|
|
57
|
-
console.log(`4. ${t('menu.options.usage')}`);
|
|
58
|
-
console.log(`5. ${t('menu.options.complete')}`);
|
|
59
|
-
console.log(`6. ${t('menu.options.sizing')}`);
|
|
60
|
-
console.log(`7. ${t('menu.options.fix')}`);
|
|
61
|
-
console.log(`8. ${t('menu.options.status')}`);
|
|
62
|
-
console.log(`9. ${t('menu.options.delete')}`);
|
|
63
|
-
console.log(`10. ${t('menu.options.settings')}`);
|
|
64
|
-
console.log(`11. ${t('menu.options.help')}`);
|
|
65
|
-
console.log(`12. ${t('menu.options.language')}`);
|
|
66
|
-
console.log(`13. ${t('menu.options.scanner')}`);
|
|
67
|
-
console.log(`0. ${t('menu.options.exit')}`);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log(buildMainMenuLines(t, { includeTranslate: false }).join('\n'));
|
|
68
39
|
|
|
69
40
|
const choice = await this.manager.prompt('\n' + t('menu.selectOptionPrompt'));
|
|
70
41
|
|