i18ntk 2.0.4 → 2.2.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 +38 -60
- package/main/i18ntk-analyze.js +49 -44
- package/main/i18ntk-complete.js +75 -74
- package/main/i18ntk-fixer.js +3 -3
- package/main/i18ntk-init.js +5 -5
- package/main/i18ntk-scanner.js +2 -2
- package/main/i18ntk-sizing.js +35 -35
- package/main/i18ntk-summary.js +4 -4
- package/main/i18ntk-ui.js +54 -8
- package/main/i18ntk-usage.js +14 -14
- package/main/i18ntk-validate.js +6 -5
- package/main/manage/commands/AnalyzeCommand.js +40 -35
- package/main/manage/commands/FixerCommand.js +2 -2
- package/main/manage/commands/ScannerCommand.js +2 -2
- package/main/manage/commands/ValidateCommand.js +9 -9
- package/main/manage/index.js +147 -75
- package/main/manage/managers/LanguageMenu.js +7 -2
- package/main/manage/services/UsageService.js +7 -7
- package/package.json +269 -290
- package/settings/settings-cli.js +3 -3
- package/ui-locales/de.json +161 -166
- package/ui-locales/en.json +13 -18
- package/ui-locales/es.json +171 -184
- package/ui-locales/fr.json +155 -161
- package/ui-locales/ja.json +192 -243
- package/ui-locales/ru.json +145 -196
- package/ui-locales/zh.json +179 -185
- package/utils/cli-helper.js +26 -98
- package/utils/extractors/regex.js +39 -12
- package/utils/i18n-helper.js +88 -40
- package/{scripts → utils}/locale-optimizer.js +61 -60
- package/utils/security-check-improved.js +16 -13
- package/utils/security.js +6 -4
- package/main/i18ntk-go.js +0 -283
- package/main/i18ntk-java.js +0 -380
- package/main/i18ntk-js.js +0 -512
- package/main/i18ntk-manage.js +0 -1694
- package/main/i18ntk-php.js +0 -462
- package/main/i18ntk-py.js +0 -379
- package/main/i18ntk-settings.js +0 -23
- package/main/manage/index-fixed.js +0 -1447
- package/main/manage/services/ConfigurationService-fixed.js +0 -449
- package/scripts/build-lite.js +0 -279
- package/scripts/deprecate-versions.js +0 -317
- package/scripts/export-translations.js +0 -84
- package/scripts/fix-all-i18n.js +0 -215
- package/scripts/fix-and-purify-i18n.js +0 -213
- package/scripts/fix-locale-control-chars.js +0 -110
- package/scripts/lint-locales.js +0 -80
- package/scripts/prepublish.js +0 -348
- package/scripts/security-check.js +0 -117
- package/scripts/sync-translations.js +0 -151
- package/scripts/sync-ui-locales.js +0 -20
- package/scripts/validate-all-translations.js +0 -139
- package/scripts/verify-deprecations.js +0 -157
- package/scripts/verify-translations.js +0 -63
- package/utils/security-fixed.js +0 -607
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* validate-all-translations.js (Upgraded)
|
|
4
|
-
* ---------------------------------------
|
|
5
|
-
* Validates i18n translation files:
|
|
6
|
-
* 1. All locales have same keys as English
|
|
7
|
-
* 2. No missing or extra keys
|
|
8
|
-
* 3. No placeholder markers
|
|
9
|
-
* 4. No leftover country code prefixes in non-English locales
|
|
10
|
-
* 5. No untranslated English values in non-English locales
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* node scripts/validate-all-translations.js \
|
|
14
|
-
* --i18n-dir=./ui-locales \
|
|
15
|
-
* --languages=en,de,es,fr,ru,ja,zh
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const fs = require('fs');
|
|
19
|
-
const path = require('path');
|
|
20
|
-
const SecurityUtils = require('../utils/security');
|
|
21
|
-
|
|
22
|
-
const argv = Object.fromEntries(
|
|
23
|
-
process.argv.slice(2).map(a => {
|
|
24
|
-
const m = a.match(/^--([^=]+)(?:=(.*))?$/);
|
|
25
|
-
return m ? [m[1], m[2] === undefined ? true : m[2]] : [a, true];
|
|
26
|
-
})
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const I18N_DIR = path.resolve(argv['i18n-dir'] || './resources/i18n/ui-locales');
|
|
30
|
-
const LANGS = (argv.languages || 'en,de,es,fr,ru,ja,zh').split(',').map(s => s.trim());
|
|
31
|
-
const MARKER = argv.marker || '⚠️ TRANSLATION NEEDED ⚠️';
|
|
32
|
-
|
|
33
|
-
// ------------ helpers ------------
|
|
34
|
-
function readJSON(p) {
|
|
35
|
-
try { return JSON.parse(SecurityUtils.safeReadFileSync(p, path.dirname(p), 'utf8')); }
|
|
36
|
-
catch { return {}; }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function flatten(obj, prefix = '') {
|
|
40
|
-
const out = {};
|
|
41
|
-
if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
|
|
42
|
-
for (const [k, v] of Object.entries(obj)) {
|
|
43
|
-
const full = prefix ? `${prefix}.${k}` : k;
|
|
44
|
-
Object.assign(out, flatten(v, full));
|
|
45
|
-
}
|
|
46
|
-
return out;
|
|
47
|
-
}
|
|
48
|
-
out[prefix] = obj;
|
|
49
|
-
return out;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function listLocaleFile(lang) {
|
|
53
|
-
const file = path.join(I18N_DIR, `${lang}.json`);
|
|
54
|
-
if (SecurityUtils.safeExistsSync(file)) return file;
|
|
55
|
-
throw new Error(`Locale file not found: ${file}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// ------------ validation ------------
|
|
59
|
-
function validate() {
|
|
60
|
-
console.log(`🔍 Validating translations in: ${I18N_DIR}`);
|
|
61
|
-
console.log(`🌐 Languages: ${LANGS.join(', ')}`);
|
|
62
|
-
console.log('');
|
|
63
|
-
|
|
64
|
-
// Load EN baseline
|
|
65
|
-
const enFlat = flatten(readJSON(listLocaleFile('en')));
|
|
66
|
-
const report = {};
|
|
67
|
-
|
|
68
|
-
LANGS.forEach(lang => {
|
|
69
|
-
const langFile = listLocaleFile(lang);
|
|
70
|
-
const flat = flatten(readJSON(langFile));
|
|
71
|
-
|
|
72
|
-
const missing = [];
|
|
73
|
-
const extra = [];
|
|
74
|
-
const markers = [];
|
|
75
|
-
const countryCodeLeftovers = [];
|
|
76
|
-
const englishLeftovers = [];
|
|
77
|
-
|
|
78
|
-
// Compare keys
|
|
79
|
-
for (const k of Object.keys(enFlat)) {
|
|
80
|
-
if (!(k in flat)) {
|
|
81
|
-
missing.push(k);
|
|
82
|
-
} else {
|
|
83
|
-
const val = flat[k];
|
|
84
|
-
if (typeof val === 'string') {
|
|
85
|
-
// Placeholder marker check
|
|
86
|
-
if (val.includes(MARKER)) {
|
|
87
|
-
markers.push(k);
|
|
88
|
-
}
|
|
89
|
-
// Country code leftover check
|
|
90
|
-
if (lang !== 'en' && /^\[[A-Z]{2}\]/.test(val.trim())) {
|
|
91
|
-
countryCodeLeftovers.push(k);
|
|
92
|
-
}
|
|
93
|
-
// English leftover check
|
|
94
|
-
if (lang !== 'en' && val.trim() === enFlat[k]?.trim()) {
|
|
95
|
-
englishLeftovers.push(k);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Extra keys not in EN
|
|
102
|
-
for (const k of Object.keys(flat)) {
|
|
103
|
-
if (!(k in enFlat)) {
|
|
104
|
-
extra.push(k);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
report[lang] = {
|
|
109
|
-
missing,
|
|
110
|
-
extra,
|
|
111
|
-
markers,
|
|
112
|
-
countryCodeLeftovers,
|
|
113
|
-
englishLeftovers
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
console.log(`📄 ${lang.toUpperCase()}:`);
|
|
117
|
-
console.log(` Missing: ${missing.length}`);
|
|
118
|
-
console.log(` Extra: ${extra.length}`);
|
|
119
|
-
console.log(` Markers: ${markers.length}`);
|
|
120
|
-
if (lang !== 'en') {
|
|
121
|
-
console.log(` Country code leftovers: ${countryCodeLeftovers.length}`);
|
|
122
|
-
console.log(` English leftovers: ${englishLeftovers.length}`);
|
|
123
|
-
}
|
|
124
|
-
console.log('');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const reportFile = path.join(I18N_DIR, 'validation-purity-report.json');
|
|
128
|
-
SecurityUtils.safeWriteFileSync(reportFile, JSON.stringify(report, null, 2), path.dirname(reportFile), 'utf8');
|
|
129
|
-
console.log(`✅ Validation report saved: ${reportFile}`);
|
|
130
|
-
console.log(` Review this file for full details of problematic keys.`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Run
|
|
134
|
-
try {
|
|
135
|
-
validate();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
console.error('❌ Validation failed:', err.message);
|
|
138
|
-
process.exit(1);
|
|
139
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* i18ntk Deprecation Verification Script
|
|
5
|
-
*
|
|
6
|
-
* This script verifies that versions have been properly deprecated
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
|
|
12
|
-
// Read package.json to get deprecation list
|
|
13
|
-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
14
|
-
const packageJson = JSON.parse(SecurityUtils.safeReadFileSync(packageJsonPath, path.dirname(packageJsonPath), 'utf8'));
|
|
15
|
-
|
|
16
|
-
console.log('🔍 i18ntk Deprecation Verification');
|
|
17
|
-
console.log('=====================================');
|
|
18
|
-
console.log(`📦 Package: ${packageJson.name}`);
|
|
19
|
-
console.log(`🎯 Current Version: ${packageJson.version}`);
|
|
20
|
-
console.log('=====================================\n');
|
|
21
|
-
|
|
22
|
-
// Get deprecation info for all versions
|
|
23
|
-
async function getDeprecationInfo() {
|
|
24
|
-
try {
|
|
25
|
-
// Deprecation information is no longer fetched from npmjs.org
|
|
26
|
-
// This script now relies on local deprecation-config.json if available.
|
|
27
|
-
const deprecationConfigPath = path.join(__dirname, '..', 'deprecation-config.json');
|
|
28
|
-
let packageInfo = { versions: {} };
|
|
29
|
-
|
|
30
|
-
if (SecurityUtils.safeExistsSync(deprecationConfigPath)) {
|
|
31
|
-
packageInfo = JSON.parse(SecurityUtils.safeReadFileSync(deprecationConfigPath, path.dirname(deprecationConfigPath), 'utf8'));
|
|
32
|
-
} else {
|
|
33
|
-
console.warn('⚠️ deprecation-config.json not found. Cannot verify deprecations locally.');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (packageInfo.versions) {
|
|
38
|
-
const deprecatedVersions = [];
|
|
39
|
-
const activeVersions = [];
|
|
40
|
-
|
|
41
|
-
// Check each version for deprecation
|
|
42
|
-
for (const version of Object.keys(packageInfo.versions)) {
|
|
43
|
-
const versionInfo = packageInfo.versions[version];
|
|
44
|
-
if (versionInfo.deprecated) {
|
|
45
|
-
deprecatedVersions.push({
|
|
46
|
-
version,
|
|
47
|
-
reason: versionInfo.deprecated
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
activeVersions.push(version);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return { deprecatedVersions, activeVersions };
|
|
55
|
-
}
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('❌ Failed to get deprecation info:', error.message);
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Main verification process
|
|
63
|
-
async function verifyDeprecations() {
|
|
64
|
-
console.log('📊 Checking deprecation status...\n');
|
|
65
|
-
|
|
66
|
-
const deprecationInfo = await getDeprecationInfo();
|
|
67
|
-
|
|
68
|
-
if (!deprecationInfo) {
|
|
69
|
-
console.log('❌ Could not retrieve deprecation information');
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const { deprecatedVersions, activeVersions } = deprecationInfo;
|
|
74
|
-
const currentVersion = packageJson.version;
|
|
75
|
-
const deprecationList = packageJson.versionInfo.deprecations;
|
|
76
|
-
|
|
77
|
-
console.log(`📈 Total Published Versions: ${deprecatedVersions.length + activeVersions.length}`);
|
|
78
|
-
console.log(`✅ Deprecated Versions: ${deprecatedVersions.length}`);
|
|
79
|
-
console.log(`🔄 Active Versions: ${activeVersions.length}`);
|
|
80
|
-
console.log(`🎯 Current Version: ${currentVersion}`);
|
|
81
|
-
console.log(`📋 Expected Deprecations: ${deprecationList.length}`);
|
|
82
|
-
console.log('');
|
|
83
|
-
|
|
84
|
-
// Check if current version is active
|
|
85
|
-
const currentVersionActive = activeVersions.includes(currentVersion);
|
|
86
|
-
if (currentVersionActive) {
|
|
87
|
-
console.log(`✅ Current version ${currentVersion} is active (correct)`);
|
|
88
|
-
} else {
|
|
89
|
-
console.log(`❌ Current version ${currentVersion} is not active (problem)`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Check deprecated versions
|
|
93
|
-
console.log('\n📋 Deprecated Versions:');
|
|
94
|
-
if (deprecatedVersions.length > 0) {
|
|
95
|
-
deprecatedVersions.forEach(({ version, reason }) => {
|
|
96
|
-
console.log(` ❌ ${version}: ${reason}`);
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
console.log(' (None)');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Check active versions (should only be current version)
|
|
103
|
-
console.log('\n🔄 Active Versions:');
|
|
104
|
-
if (activeVersions.length > 0) {
|
|
105
|
-
activeVersions.forEach(version => {
|
|
106
|
-
if (version === currentVersion) {
|
|
107
|
-
console.log(` ✅ ${version} (current version - correct)`);
|
|
108
|
-
} else {
|
|
109
|
-
console.log(` ⚠️ ${version} (should be deprecated)`);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
console.log(' (None)');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Summary
|
|
117
|
-
console.log('\n=====================================');
|
|
118
|
-
console.log('🎯 Verification Summary');
|
|
119
|
-
console.log('=====================================');
|
|
120
|
-
|
|
121
|
-
const expectedDeprecated = deprecationList.length;
|
|
122
|
-
const actualDeprecated = deprecatedVersions.length;
|
|
123
|
-
const successRate = expectedDeprecated > 0 ? (actualDeprecated / expectedDeprecated * 100).toFixed(1) : 0;
|
|
124
|
-
|
|
125
|
-
console.log(`📊 Expected deprecated: ${expectedDeprecated}`);
|
|
126
|
-
console.log(`📊 Actually deprecated: ${actualDeprecated}`);
|
|
127
|
-
console.log(`📊 Success rate: ${successRate}%`);
|
|
128
|
-
|
|
129
|
-
if (activeVersions.length === 1 && activeVersions[0] === currentVersion) {
|
|
130
|
-
console.log('✅ Status: All previous versions deprecated, current version active');
|
|
131
|
-
} else {
|
|
132
|
-
console.log('⚠️ Status: Some versions may still need deprecation');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.log('=====================================');
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Handle command line arguments
|
|
139
|
-
const args = process.argv.slice(2);
|
|
140
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
141
|
-
console.log(`
|
|
142
|
-
i18ntk Deprecation Verification Script
|
|
143
|
-
|
|
144
|
-
Usage:
|
|
145
|
-
node scripts/verify-deprecations.js [options]
|
|
146
|
-
|
|
147
|
-
Description:
|
|
148
|
-
This script verifies that i18ntk versions have been properly deprecated.
|
|
149
|
-
|
|
150
|
-
Examples:
|
|
151
|
-
node scripts/verify-deprecations.js
|
|
152
|
-
`);
|
|
153
|
-
process.exit(0);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Run verification
|
|
157
|
-
verifyDeprecations();
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const SecurityUtils = require('../utils/security');
|
|
4
|
-
|
|
5
|
-
// Load all language files
|
|
6
|
-
const localesPath = path.join(__dirname, '../resources/i18n/ui-locales');
|
|
7
|
-
const files = fs.readdirSync(localesPath).filter(file => file.endsWith('.json') && file !== 'en.json');
|
|
8
|
-
|
|
9
|
-
// Load English as the base for comparison
|
|
10
|
-
const enContent = JSON.parse(SecurityUtils.safeReadFileSync(path.join(localesPath, 'en.json'), localesPath, 'utf8'));
|
|
11
|
-
|
|
12
|
-
// Function to get all keys from an object
|
|
13
|
-
function getAllKeys(obj, prefix = '') {
|
|
14
|
-
return Object.entries(obj).reduce((keys, [key, value]) => {
|
|
15
|
-
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
16
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
17
|
-
return [...keys, ...getAllKeys(value, fullKey)];
|
|
18
|
-
}
|
|
19
|
-
return [...keys, fullKey];
|
|
20
|
-
}, []);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Get all keys from English file
|
|
24
|
-
const enKeys = new Set(getAllKeys(enContent));
|
|
25
|
-
|
|
26
|
-
// Check each language file
|
|
27
|
-
console.log('\n🔍 Verifying translation keys across all language files...\n');
|
|
28
|
-
|
|
29
|
-
files.forEach(file => {
|
|
30
|
-
const langCode = path.basename(file, '.json');
|
|
31
|
-
const filePath = path.join(localesPath, file);
|
|
32
|
-
const content = JSON.parse(SecurityUtils.safeReadFileSync(filePath, localesPath, 'utf8'));
|
|
33
|
-
const langKeys = new Set(getAllKeys(content));
|
|
34
|
-
|
|
35
|
-
// Find missing keys
|
|
36
|
-
const missingKeys = [...enKeys].filter(key => !langKeys.has(key));
|
|
37
|
-
|
|
38
|
-
// Find extra keys (not in English)
|
|
39
|
-
const extraKeys = [...langKeys].filter(key => !enKeys.has(key));
|
|
40
|
-
|
|
41
|
-
console.log(`🌐 ${file}:`);
|
|
42
|
-
console.log(` Total keys: ${langKeys.size}/${enKeys.size} (${Math.round((langKeys.size / enKeys.size) * 100)}%)`);
|
|
43
|
-
|
|
44
|
-
if (missingKeys.length > 0) {
|
|
45
|
-
console.log(` ❌ Missing ${missingKeys.length} keys:`);
|
|
46
|
-
missingKeys.slice(0, 5).forEach(key => console.log(` - ${key}`));
|
|
47
|
-
if (missingKeys.length > 5) console.log(` ...and ${missingKeys.length - 5} more`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (extraKeys.length > 0) {
|
|
51
|
-
console.log(` ⚠️ Found ${extraKeys.length} extra keys (not in English):`);
|
|
52
|
-
extraKeys.slice(0, 3).forEach(key => console.log(` - ${key}`));
|
|
53
|
-
if (extraKeys.length > 3) console.log(` ...and ${extraKeys.length - 3} more`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (missingKeys.length === 0 && extraKeys.length === 0) {
|
|
57
|
-
console.log(' ✅ All keys match the English version!');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
console.log('');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
console.log('✅ Verification complete!');
|