i18ntk 2.0.3 → 2.1.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.
- package/README.md +36 -32
- package/main/i18ntk-analyze.js +59 -54
- package/main/i18ntk-ui.js +96 -49
- package/main/manage/commands/AnalyzeCommand.js +59 -54
- package/main/manage/index.js +140 -71
- package/package.json +290 -290
- package/scripts/fix-all-i18n.js +41 -20
- package/scripts/fix-and-purify-i18n.js +43 -23
- package/scripts/prepublish-dev.js +221 -0
- package/scripts/prepublish.js +155 -141
- package/scripts/validate-all-translations.js +190 -134
- package/ui-locales/de.json +149 -155
- package/ui-locales/en.json +1 -7
- package/ui-locales/es.json +159 -173
- package/ui-locales/fr.json +143 -150
- package/ui-locales/ja.json +181 -233
- package/ui-locales/ru.json +133 -185
- package/ui-locales/zh.json +168 -175
- package/utils/cli-helper.js +26 -98
- package/utils/extractors/regex.js +39 -12
- package/utils/i18n-helper.js +181 -128
- package/utils/security-check-improved.js +16 -13
- package/utils/security-fixed.js +6 -4
- package/utils/security.js +6 -4
- package/main/manage/services/ConfigurationService-fixed.js +0 -449
package/main/manage/index.js
CHANGED
|
@@ -151,13 +151,40 @@ class I18nManager {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
// Check if i18n framework is installed - configuration-based check without prompts
|
|
155
|
-
async checkI18nDependencies() {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
// Check if i18n framework is installed - configuration-based check without prompts
|
|
155
|
+
async checkI18nDependencies() {
|
|
156
|
+
const markInternalFrameworkDetected = () => {
|
|
157
|
+
const cfg = configManager.loadSettings ? configManager.loadSettings() : (configManager.getConfig ? configManager.getConfig() : {});
|
|
158
|
+
cfg.framework = cfg.framework || {};
|
|
159
|
+
cfg.framework.detected = true;
|
|
160
|
+
cfg.framework.preference = cfg.framework.preference || 'i18ntk';
|
|
161
|
+
const existing = Array.isArray(cfg.framework.installed) ? cfg.framework.installed : [];
|
|
162
|
+
if (!existing.includes('i18ntk')) {
|
|
163
|
+
cfg.framework.installed = [...existing, 'i18ntk'];
|
|
164
|
+
}
|
|
165
|
+
if (configManager.saveSettings) {
|
|
166
|
+
configManager.saveSettings(cfg);
|
|
167
|
+
} else if (configManager.saveConfig) {
|
|
168
|
+
configManager.saveConfig(cfg);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
const { checkInitialized } = require('../../utils/init-helper');
|
|
174
|
+
const initStatus = await checkInitialized();
|
|
175
|
+
if (initStatus?.initialized || initStatus?.config?.setup?.completed) {
|
|
176
|
+
markInternalFrameworkDetected();
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
} catch (_) {
|
|
180
|
+
// Continue with package.json detection.
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const packageJsonPath = path.resolve('./package.json');
|
|
184
|
+
|
|
185
|
+
if (!SecurityUtils.safeExistsSync(packageJsonPath)) {
|
|
186
|
+
console.log(this.ui ? this.ui.t('errors.noPackageJson') : 'No package.json found');
|
|
187
|
+
return false; // Treat as no framework detected
|
|
161
188
|
}
|
|
162
189
|
|
|
163
190
|
try {
|
|
@@ -174,11 +201,12 @@ class I18nManager {
|
|
|
174
201
|
'vue-i18n',
|
|
175
202
|
'angular-i18n',
|
|
176
203
|
'i18next',
|
|
177
|
-
'next-i18next',
|
|
178
|
-
'svelte-i18n',
|
|
179
|
-
'@nuxtjs/i18n',
|
|
180
|
-
'i18ntk-runtime'
|
|
181
|
-
|
|
204
|
+
'next-i18next',
|
|
205
|
+
'svelte-i18n',
|
|
206
|
+
'@nuxtjs/i18n',
|
|
207
|
+
'i18ntk-runtime',
|
|
208
|
+
'i18ntk'
|
|
209
|
+
];
|
|
182
210
|
|
|
183
211
|
const installedFrameworks = i18nFrameworks.filter(framework => dependencies[framework]);
|
|
184
212
|
|
|
@@ -484,21 +512,39 @@ class I18nManager {
|
|
|
484
512
|
const settings = configManager.loadSettings ? configManager.loadSettings() : (configManager.getConfig ? configManager.getConfig() : {});
|
|
485
513
|
|
|
486
514
|
// Ensure framework configuration exists with all required fields
|
|
487
|
-
if (!settings.framework) {
|
|
488
|
-
settings.framework = {
|
|
489
|
-
detected: false,
|
|
490
|
-
preference: null,
|
|
491
|
-
prompt: 'always',
|
|
515
|
+
if (!settings.framework) {
|
|
516
|
+
settings.framework = {
|
|
517
|
+
detected: false,
|
|
518
|
+
preference: null,
|
|
519
|
+
prompt: 'always',
|
|
492
520
|
lastPromptedVersion: null,
|
|
493
521
|
installed: [],
|
|
494
|
-
version: '1.0' // Schema version for future compatibility
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (
|
|
500
|
-
settings.framework.
|
|
501
|
-
settings.framework.
|
|
522
|
+
version: '1.0' // Schema version for future compatibility
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const setupCompleted = Boolean(config?.setup?.completed || settings?.setup?.completed);
|
|
527
|
+
if (setupCompleted) {
|
|
528
|
+
settings.framework.detected = true;
|
|
529
|
+
settings.framework.preference = settings.framework.preference || 'i18ntk';
|
|
530
|
+
settings.framework.installed = Array.isArray(settings.framework.installed)
|
|
531
|
+
? Array.from(new Set([...settings.framework.installed, 'i18ntk']))
|
|
532
|
+
: ['i18ntk'];
|
|
533
|
+
settings.framework.lastDetected = new Date().toISOString();
|
|
534
|
+
|
|
535
|
+
if (configManager.saveSettings) {
|
|
536
|
+
await configManager.saveSettings(settings);
|
|
537
|
+
} else if (configManager.saveConfig) {
|
|
538
|
+
await configManager.saveConfig(settings);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return { ...config, ...settings };
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Check if we need to prompt for framework detection
|
|
545
|
+
if (!settings.framework.detected &&
|
|
546
|
+
settings.framework.prompt !== 'suppress' &&
|
|
547
|
+
settings.framework.lastPromptedVersion !== pkg.version) {
|
|
502
548
|
|
|
503
549
|
console.log('\nWe noticed you haven\'t set up an i18n framework yet.');
|
|
504
550
|
console.log('Would you like to detect your i18n framework automatically?');
|
|
@@ -557,11 +603,11 @@ class I18nManager {
|
|
|
557
603
|
return { ...config, ...settings };
|
|
558
604
|
}
|
|
559
605
|
|
|
560
|
-
async detectEnvironmentAndFramework() {
|
|
561
|
-
// Defensive check to ensure SecurityUtils is available
|
|
562
|
-
if (!SecurityUtils) {
|
|
563
|
-
throw new Error('SecurityUtils is not available. This may indicate a module loading issue.');
|
|
564
|
-
}
|
|
606
|
+
async detectEnvironmentAndFramework() {
|
|
607
|
+
// Defensive check to ensure SecurityUtils is available
|
|
608
|
+
if (!SecurityUtils) {
|
|
609
|
+
throw new Error('SecurityUtils is not available. This may indicate a module loading issue.');
|
|
610
|
+
}
|
|
565
611
|
const fs = require('fs');
|
|
566
612
|
const path = require('path');
|
|
567
613
|
|
|
@@ -572,13 +618,23 @@ class I18nManager {
|
|
|
572
618
|
const pomPath = path.join(process.cwd(), 'pom.xml');
|
|
573
619
|
const composerPath = path.join(process.cwd(), 'composer.json');
|
|
574
620
|
|
|
575
|
-
let detectedLanguage = 'generic';
|
|
576
|
-
let detectedFramework = 'generic';
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
621
|
+
let detectedLanguage = 'generic';
|
|
622
|
+
let detectedFramework = 'generic';
|
|
623
|
+
|
|
624
|
+
try {
|
|
625
|
+
const { checkInitialized } = require('../../utils/init-helper');
|
|
626
|
+
const initStatus = await checkInitialized();
|
|
627
|
+
if (initStatus?.initialized || initStatus?.config?.setup?.completed) {
|
|
628
|
+
return { detectedLanguage: 'javascript', detectedFramework: 'i18ntk' };
|
|
629
|
+
}
|
|
630
|
+
} catch (_) {
|
|
631
|
+
// Continue with filesystem/package detection.
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (SecurityUtils.safeExistsSync(packageJsonPath)) {
|
|
635
|
+
detectedLanguage = 'javascript';
|
|
636
|
+
try {
|
|
637
|
+
const packageJson = JSON.parse(SecurityUtils.safeReadFileSync(packageJsonPath, path.dirname(packageJsonPath), 'utf8'));
|
|
582
638
|
const deps = {
|
|
583
639
|
...(packageJson.dependencies || {}),
|
|
584
640
|
...(packageJson.devDependencies || {}),
|
|
@@ -586,13 +642,18 @@ class I18nManager {
|
|
|
586
642
|
};
|
|
587
643
|
|
|
588
644
|
// Check for i18ntk-runtime first (check both package names)
|
|
589
|
-
const hasI18nTkRuntime = deps['i18ntk-runtime'] || deps['i18ntk/runtime'];
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
if (
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
645
|
+
const hasI18nTkRuntime = deps['i18ntk-runtime'] || deps['i18ntk/runtime'];
|
|
646
|
+
const hasI18nTkToolkit = Boolean(deps['i18ntk']);
|
|
647
|
+
|
|
648
|
+
if (hasI18nTkToolkit) {
|
|
649
|
+
detectedFramework = 'i18ntk';
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// Check for common i18n patterns in source code if not found in package.json
|
|
653
|
+
if (!hasI18nTkRuntime && detectedFramework !== 'i18ntk') {
|
|
654
|
+
const i18nPatterns = [
|
|
655
|
+
/i18n\.t\(['\"`]/,
|
|
656
|
+
/useI18n\(/,
|
|
596
657
|
/from ['\"]i18ntk[\/\\]runtime['\"]/,
|
|
597
658
|
/require\(['\"]i18ntk[\/\\]runtime['\"]\)/
|
|
598
659
|
];
|
|
@@ -614,9 +675,9 @@ class I18nManager {
|
|
|
614
675
|
continue;
|
|
615
676
|
}
|
|
616
677
|
}
|
|
617
|
-
} else {
|
|
618
|
-
detectedFramework = 'i18ntk-runtime';
|
|
619
|
-
}
|
|
678
|
+
} else if (hasI18nTkRuntime) {
|
|
679
|
+
detectedFramework = 'i18ntk-runtime';
|
|
680
|
+
}
|
|
620
681
|
|
|
621
682
|
// Only check other frameworks if i18ntk-runtime wasn't detected
|
|
622
683
|
if (detectedFramework !== 'i18ntk-runtime') {
|
|
@@ -850,27 +911,34 @@ class I18nManager {
|
|
|
850
911
|
const choice = await this.prompt('\n' + t('menu.selectOptionPrompt'));
|
|
851
912
|
|
|
852
913
|
switch (choice.trim()) {
|
|
853
|
-
case '1':
|
|
854
|
-
await this.executeCommand('init', {fromMenu: true});
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
await this.
|
|
864
|
-
|
|
865
|
-
case '
|
|
866
|
-
await this.executeCommand('
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
914
|
+
case '1':
|
|
915
|
+
await this.executeCommand('init', {fromMenu: true});
|
|
916
|
+
await this.showInteractiveMenu();
|
|
917
|
+
return;
|
|
918
|
+
case '2':
|
|
919
|
+
await this.executeCommand('analyze', {fromMenu: true});
|
|
920
|
+
await this.showInteractiveMenu();
|
|
921
|
+
return;
|
|
922
|
+
case '3':
|
|
923
|
+
await this.executeCommand('validate', {fromMenu: true});
|
|
924
|
+
await this.showInteractiveMenu();
|
|
925
|
+
return;
|
|
926
|
+
case '4':
|
|
927
|
+
await this.executeCommand('usage', {fromMenu: true});
|
|
928
|
+
await this.showInteractiveMenu();
|
|
929
|
+
return;
|
|
930
|
+
case '5':
|
|
931
|
+
await this.executeCommand('complete', {fromMenu: true});
|
|
932
|
+
await this.showInteractiveMenu();
|
|
933
|
+
return;
|
|
934
|
+
case '6':
|
|
935
|
+
await this.executeCommand('sizing', {fromMenu: true});
|
|
936
|
+
await this.showInteractiveMenu();
|
|
937
|
+
return;
|
|
938
|
+
case '7':
|
|
939
|
+
await this.executeCommand('fix', {fromMenu: true});
|
|
940
|
+
await this.showInteractiveMenu();
|
|
941
|
+
return;
|
|
874
942
|
case '8':
|
|
875
943
|
// Check for PIN protection
|
|
876
944
|
const authRequired = await this.adminAuth.isAuthRequiredForScript('summaryReports');
|
|
@@ -943,9 +1011,10 @@ class I18nManager {
|
|
|
943
1011
|
case '12':
|
|
944
1012
|
await this.showLanguageMenu();
|
|
945
1013
|
break;
|
|
946
|
-
case '13':
|
|
947
|
-
await this.executeCommand('scanner', {fromMenu: true});
|
|
948
|
-
|
|
1014
|
+
case '13':
|
|
1015
|
+
await this.executeCommand('scanner', {fromMenu: true});
|
|
1016
|
+
await this.showInteractiveMenu();
|
|
1017
|
+
return;
|
|
949
1018
|
case '0':
|
|
950
1019
|
console.log(t('menu.goodbye'));
|
|
951
1020
|
this.safeClose();
|