i18ntk 1.0.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +401 -0
  2. package/LICENSE +21 -0
  3. package/README.md +507 -0
  4. package/dev/README.md +37 -0
  5. package/dev/debug/README.md +30 -0
  6. package/dev/debug/complete-console-translations.js +295 -0
  7. package/dev/debug/console-key-checker.js +408 -0
  8. package/dev/debug/console-translations.js +335 -0
  9. package/dev/debug/debugger.js +408 -0
  10. package/dev/debug/export-missing-keys.js +432 -0
  11. package/dev/debug/final-normalize.js +236 -0
  12. package/dev/debug/find-extra-keys.js +68 -0
  13. package/dev/debug/normalize-locales.js +153 -0
  14. package/dev/debug/refactor-locales.js +240 -0
  15. package/dev/debug/reorder-locales.js +85 -0
  16. package/dev/debug/replace-hardcoded-console.js +378 -0
  17. package/docs/INSTALLATION.md +449 -0
  18. package/docs/README.md +222 -0
  19. package/docs/TODO_ROADMAP.md +279 -0
  20. package/docs/api/API_REFERENCE.md +377 -0
  21. package/docs/api/COMPONENTS.md +492 -0
  22. package/docs/api/CONFIGURATION.md +651 -0
  23. package/docs/api/NPM_PUBLISHING_GUIDE.md +434 -0
  24. package/docs/debug/DEBUG_README.md +30 -0
  25. package/docs/debug/DEBUG_TOOLS.md +494 -0
  26. package/docs/development/AGENTS.md +351 -0
  27. package/docs/development/DEVELOPMENT_RULES.md +165 -0
  28. package/docs/development/DEV_README.md +37 -0
  29. package/docs/release-notes/RELEASE_NOTES_v1.0.0.md +173 -0
  30. package/docs/release-notes/RELEASE_NOTES_v1.6.0.md +141 -0
  31. package/docs/release-notes/RELEASE_NOTES_v1.6.1.md +185 -0
  32. package/docs/release-notes/RELEASE_NOTES_v1.6.3.md +199 -0
  33. package/docs/reports/ANALYSIS_README.md +17 -0
  34. package/docs/reports/CONSOLE_MISMATCH_BUG_REPORT_v1.5.0.md +181 -0
  35. package/docs/reports/SIZING_README.md +18 -0
  36. package/docs/reports/SUMMARY_README.md +18 -0
  37. package/docs/reports/TRANSLATION_BUG_REPORT_v1.5.0.md +129 -0
  38. package/docs/reports/USAGE_README.md +18 -0
  39. package/docs/reports/VALIDATION_README.md +18 -0
  40. package/locales/de/auth.json +3 -0
  41. package/locales/de/common.json +16 -0
  42. package/locales/de/pagination.json +6 -0
  43. package/locales/en/auth.json +3 -0
  44. package/locales/en/common.json +16 -0
  45. package/locales/en/pagination.json +6 -0
  46. package/locales/es/auth.json +3 -0
  47. package/locales/es/common.json +16 -0
  48. package/locales/es/pagination.json +6 -0
  49. package/locales/fr/auth.json +3 -0
  50. package/locales/fr/common.json +16 -0
  51. package/locales/fr/pagination.json +6 -0
  52. package/locales/ru/auth.json +3 -0
  53. package/locales/ru/common.json +16 -0
  54. package/locales/ru/pagination.json +6 -0
  55. package/main/i18ntk-analyze.js +625 -0
  56. package/main/i18ntk-autorun.js +461 -0
  57. package/main/i18ntk-complete.js +494 -0
  58. package/main/i18ntk-init.js +686 -0
  59. package/main/i18ntk-manage.js +848 -0
  60. package/main/i18ntk-sizing.js +557 -0
  61. package/main/i18ntk-summary.js +671 -0
  62. package/main/i18ntk-usage.js +1282 -0
  63. package/main/i18ntk-validate.js +762 -0
  64. package/main/ui-i18n.js +332 -0
  65. package/package.json +152 -0
  66. package/scripts/fix-missing-translation-keys.js +214 -0
  67. package/scripts/verify-package.js +168 -0
  68. package/ui-locales/de.json +637 -0
  69. package/ui-locales/en.json +688 -0
  70. package/ui-locales/es.json +637 -0
  71. package/ui-locales/fr.json +637 -0
  72. package/ui-locales/ja.json +637 -0
  73. package/ui-locales/ru.json +637 -0
  74. package/ui-locales/zh.json +637 -0
  75. package/utils/admin-auth.js +317 -0
  76. package/utils/admin-cli.js +353 -0
  77. package/utils/admin-pin.js +409 -0
  78. package/utils/detect-language-mismatches.js +454 -0
  79. package/utils/i18n-helper.js +128 -0
  80. package/utils/maintain-language-purity.js +433 -0
  81. package/utils/native-translations.js +478 -0
  82. package/utils/security.js +384 -0
  83. package/utils/test-complete-system.js +356 -0
  84. package/utils/test-console-i18n.js +402 -0
  85. package/utils/translate-mismatches.js +571 -0
  86. package/utils/validate-language-purity.js +531 -0
@@ -0,0 +1,433 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Language Purity Maintenance Tool
5
+ *
6
+ * This script provides a comprehensive workflow for maintaining language purity
7
+ * across all locale files. It integrates detection, translation, and validation.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const { execSync } = require('child_process');
13
+
14
+ class LanguagePurityMaintainer {
15
+ constructor() {
16
+ this.toolsDir = __dirname;
17
+ this.reportsDir = path.join(__dirname, 'i18ntk-reports');
18
+ this.timestamp = new Date().toISOString().replace(/[:.]/g, '-');
19
+ }
20
+
21
+ /**
22
+ * Run the complete language purity maintenance workflow
23
+ */
24
+ async runCompleteWorkflow() {
25
+ console.log('🚀 Language Purity Maintenance Workflow');
26
+ console.log('==========================================\n');
27
+
28
+ const results = {
29
+ timestamp: new Date().toISOString(),
30
+ steps: [],
31
+ summary: {
32
+ initialViolations: 0,
33
+ finalViolations: 0,
34
+ improvementPercentage: 0,
35
+ totalFixesApplied: 0
36
+ }
37
+ };
38
+
39
+ try {
40
+ // Step 1: Initial Assessment
41
+ console.log('📊 STEP 1: Initial Language Purity Assessment');
42
+ console.log('==============================================\n');
43
+ const initialAssessment = await this.runInitialAssessment();
44
+ results.steps.push(initialAssessment);
45
+ results.summary.initialViolations = initialAssessment.totalViolations;
46
+
47
+ // Step 2: Detect and Fix Language Mismatches
48
+ console.log('\n🔧 STEP 2: Detect and Auto-Fix Language Mismatches');
49
+ console.log('===================================================\n');
50
+ const mismatchFixes = await this.fixLanguageMismatches();
51
+ results.steps.push(mismatchFixes);
52
+ results.summary.totalFixesApplied += mismatchFixes.fixesApplied;
53
+
54
+ // Step 3: Apply Automatic Translations
55
+ console.log('\n🌐 STEP 3: Apply Automatic Translations');
56
+ console.log('========================================\n');
57
+ const translationFixes = await this.applyAutomaticTranslations();
58
+ results.steps.push(translationFixes);
59
+ results.summary.totalFixesApplied += translationFixes.fixesApplied;
60
+
61
+ // Step 4: Final Assessment
62
+ console.log('\n✅ STEP 4: Final Language Purity Assessment');
63
+ console.log('============================================\n');
64
+ const finalAssessment = await this.runFinalAssessment();
65
+ results.steps.push(finalAssessment);
66
+ results.summary.finalViolations = finalAssessment.totalViolations;
67
+
68
+ // Calculate improvement
69
+ if (results.summary.initialViolations > 0) {
70
+ const improvement = results.summary.initialViolations - results.summary.finalViolations;
71
+ results.summary.improvementPercentage = Math.round((improvement / results.summary.initialViolations) * 100);
72
+ }
73
+
74
+ // Generate final report
75
+ this.generateWorkflowReport(results);
76
+
77
+ } catch (error) {
78
+ console.error('❌ Workflow Error:', error.message);
79
+ throw error;
80
+ }
81
+
82
+ return results;
83
+ }
84
+
85
+ /**
86
+ * Run initial language purity assessment
87
+ */
88
+ async runInitialAssessment() {
89
+ console.log('Running initial language purity validation...');
90
+
91
+ try {
92
+ const output = execSync('node validate-language-purity.js', {
93
+ cwd: this.toolsDir,
94
+ encoding: 'utf8',
95
+ stdio: 'pipe'
96
+ });
97
+
98
+ // Parse the output to extract violation counts
99
+ const violationMatch = output.match(/Total violations: (\d+)/);
100
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
101
+
102
+ console.log(`✅ Initial assessment complete: ${totalViolations} violations found\n`);
103
+
104
+ return {
105
+ step: 'initial_assessment',
106
+ success: true,
107
+ totalViolations,
108
+ output: output.substring(0, 1000) // Truncate for report
109
+ };
110
+ } catch (error) {
111
+ console.log(`⚠️ Initial assessment completed with warnings\n`);
112
+
113
+ // Even if exit code is non-zero, we can still extract useful info
114
+ const output = error.stdout || error.message;
115
+ const violationMatch = output.match(/Total violations: (\d+)/);
116
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
117
+
118
+ return {
119
+ step: 'initial_assessment',
120
+ success: false,
121
+ totalViolations,
122
+ output: output.substring(0, 1000)
123
+ };
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Fix language mismatches (remove prefixes, etc.)
129
+ */
130
+ async fixLanguageMismatches() {
131
+ console.log('Detecting and fixing language mismatches...');
132
+
133
+ try {
134
+ // First, run detection to see what needs fixing
135
+ const detectionOutput = execSync('node detect-language-mismatches.js', {
136
+ cwd: this.toolsDir,
137
+ encoding: 'utf8'
138
+ });
139
+
140
+ console.log('Detection complete. Applying auto-fixes...');
141
+
142
+ // Apply auto-fixes
143
+ const fixOutput = execSync('node detect-language-mismatches.js --auto-fix --apply', {
144
+ cwd: this.toolsDir,
145
+ encoding: 'utf8'
146
+ });
147
+
148
+ // Extract number of fixes applied
149
+ const fixMatch = fixOutput.match(/(\d+) total fixes applied/);
150
+ const fixesApplied = fixMatch ? parseInt(fixMatch[1]) : 0;
151
+
152
+ console.log(`✅ Language mismatch fixes complete: ${fixesApplied} fixes applied\n`);
153
+
154
+ return {
155
+ step: 'language_mismatch_fixes',
156
+ success: true,
157
+ fixesApplied,
158
+ output: fixOutput.substring(0, 1000)
159
+ };
160
+ } catch (error) {
161
+ console.log(`⚠️ Language mismatch fixes completed with warnings\n`);
162
+
163
+ const output = error.stdout || error.message;
164
+ const fixMatch = output.match(/(\d+) total fixes applied/);
165
+ const fixesApplied = fixMatch ? parseInt(fixMatch[1]) : 0;
166
+
167
+ return {
168
+ step: 'language_mismatch_fixes',
169
+ success: false,
170
+ fixesApplied,
171
+ output: output.substring(0, 1000)
172
+ };
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Apply automatic translations
178
+ */
179
+ async applyAutomaticTranslations() {
180
+ console.log('Applying automatic translations...');
181
+
182
+ try {
183
+ // First, check what can be translated
184
+ const previewOutput = execSync('node translate-mismatches.js --translate', {
185
+ cwd: this.toolsDir,
186
+ encoding: 'utf8'
187
+ });
188
+
189
+ console.log('Translation preview complete. Applying translations...');
190
+
191
+ // Apply translations
192
+ const applyOutput = execSync('node translate-mismatches.js --apply', {
193
+ cwd: this.toolsDir,
194
+ encoding: 'utf8'
195
+ });
196
+
197
+ // Extract number of translations applied
198
+ const translationMatch = applyOutput.match(/(\d+) translations/);
199
+ const fixesApplied = translationMatch ? parseInt(translationMatch[1]) : 0;
200
+
201
+ console.log(`✅ Automatic translations complete: ${fixesApplied} translations applied\n`);
202
+
203
+ return {
204
+ step: 'automatic_translations',
205
+ success: true,
206
+ fixesApplied,
207
+ output: applyOutput.substring(0, 1000)
208
+ };
209
+ } catch (error) {
210
+ console.log(`⚠️ Automatic translations completed with warnings\n`);
211
+
212
+ const output = error.stdout || error.message;
213
+ const translationMatch = output.match(/(\d+) translations/);
214
+ const fixesApplied = translationMatch ? parseInt(translationMatch[1]) : 0;
215
+
216
+ return {
217
+ step: 'automatic_translations',
218
+ success: false,
219
+ fixesApplied,
220
+ output: output.substring(0, 1000)
221
+ };
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Run final language purity assessment
227
+ */
228
+ async runFinalAssessment() {
229
+ console.log('Running final language purity validation...');
230
+
231
+ try {
232
+ const output = execSync('node validate-language-purity.js', {
233
+ cwd: this.toolsDir,
234
+ encoding: 'utf8',
235
+ stdio: 'pipe'
236
+ });
237
+
238
+ const violationMatch = output.match(/Total violations: (\d+)/);
239
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
240
+
241
+ console.log(`✅ Final assessment complete: ${totalViolations} violations remaining\n`);
242
+
243
+ return {
244
+ step: 'final_assessment',
245
+ success: true,
246
+ totalViolations,
247
+ output: output.substring(0, 1000)
248
+ };
249
+ } catch (error) {
250
+ console.log(`⚠️ Final assessment completed with warnings\n`);
251
+
252
+ const output = error.stdout || error.message;
253
+ const violationMatch = output.match(/Total violations: (\d+)/);
254
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
255
+
256
+ return {
257
+ step: 'final_assessment',
258
+ success: false,
259
+ totalViolations,
260
+ output: output.substring(0, 1000)
261
+ };
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Generate comprehensive workflow report
267
+ */
268
+ generateWorkflowReport(results) {
269
+ console.log('📋 WORKFLOW SUMMARY');
270
+ console.log('===================\n');
271
+
272
+ console.log(`🕐 Workflow completed at: ${results.timestamp}`);
273
+ console.log(`📊 Initial violations: ${results.summary.initialViolations}`);
274
+ console.log(`📉 Final violations: ${results.summary.finalViolations}`);
275
+ console.log(`🔧 Total fixes applied: ${results.summary.totalFixesApplied}`);
276
+ console.log(`📈 Improvement: ${results.summary.improvementPercentage}%\n`);
277
+
278
+ // Step-by-step results
279
+ console.log('📝 STEP RESULTS:\n');
280
+ results.steps.forEach((step, index) => {
281
+ const status = step.success ? '✅' : '⚠️';
282
+ console.log(`${index + 1}. ${status} ${step.step.replace(/_/g, ' ').toUpperCase()}`);
283
+
284
+ if (step.totalViolations !== undefined) {
285
+ console.log(` Violations: ${step.totalViolations}`);
286
+ }
287
+ if (step.fixesApplied !== undefined) {
288
+ console.log(` Fixes applied: ${step.fixesApplied}`);
289
+ }
290
+ console.log('');
291
+ });
292
+
293
+ // Recommendations
294
+ console.log('💡 NEXT STEPS:\n');
295
+
296
+ if (results.summary.finalViolations === 0) {
297
+ console.log('🎉 Congratulations! All locale files now have perfect language purity!');
298
+ console.log('✅ Consider integrating the validator into your CI/CD pipeline');
299
+ console.log('✅ Set up automated checks for new translations\n');
300
+ } else if (results.summary.improvementPercentage >= 80) {
301
+ console.log('🎯 Great progress! Most issues have been resolved.');
302
+ console.log('🔍 Review remaining violations manually');
303
+ console.log('🌐 Consider adding more translation mappings for edge cases');
304
+ console.log('✅ Integrate validator into CI/CD pipeline\n');
305
+ } else if (results.summary.improvementPercentage >= 50) {
306
+ console.log('📈 Good progress made, but more work needed.');
307
+ console.log('🔧 Expand automatic translation mappings');
308
+ console.log('👥 Consider manual review of complex translations');
309
+ console.log('🔄 Run workflow again after adding more mappings\n');
310
+ } else {
311
+ console.log('⚠️ Limited progress. Manual intervention may be needed.');
312
+ console.log('🔍 Review translation mappings and add missing ones');
313
+ console.log('👥 Consider professional translation services');
314
+ console.log('🔧 Check for systematic issues in locale files\n');
315
+ }
316
+
317
+ // Save detailed report
318
+ this.saveWorkflowReport(results);
319
+ }
320
+
321
+ /**
322
+ * Save workflow report to file
323
+ */
324
+ saveWorkflowReport(results) {
325
+ const reportPath = path.join(this.reportsDir, 'workflow', `language-purity-workflow-${this.timestamp}.json`);
326
+
327
+ // Ensure directory exists
328
+ const reportDir = path.dirname(reportPath);
329
+ if (!fs.existsSync(reportDir)) {
330
+ fs.mkdirSync(reportDir, { recursive: true });
331
+ }
332
+
333
+ try {
334
+ fs.writeFileSync(reportPath, JSON.stringify(results, null, 2));
335
+ console.log(`📄 Detailed workflow report saved to: ${reportPath}\n`);
336
+ } catch (error) {
337
+ console.error(`❌ Error saving workflow report: ${error.message}\n`);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Quick validation check
343
+ */
344
+ async quickValidation() {
345
+ console.log('🔍 Quick Language Purity Check');
346
+ console.log('===============================\n');
347
+
348
+ try {
349
+ const output = execSync('node validate-language-purity.js', {
350
+ cwd: this.toolsDir,
351
+ encoding: 'utf8',
352
+ stdio: 'pipe'
353
+ });
354
+
355
+ const violationMatch = output.match(/Total violations: (\d+)/);
356
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
357
+
358
+ if (totalViolations === 0) {
359
+ console.log('✅ All locale files have perfect language purity!\n');
360
+ } else {
361
+ console.log(`⚠️ ${totalViolations} language purity violations found.`);
362
+ console.log('💡 Run the full workflow to fix these issues:\n');
363
+ console.log(' node maintain-language-purity.js --workflow\n');
364
+ }
365
+
366
+ return totalViolations;
367
+ } catch (error) {
368
+ const output = error.stdout || error.message;
369
+ const violationMatch = output.match(/Total violations: (\d+)/);
370
+ const totalViolations = violationMatch ? parseInt(violationMatch[1]) : 0;
371
+
372
+ console.log(`⚠️ ${totalViolations} language purity violations found.`);
373
+ console.log('💡 Run the full workflow to fix these issues:\n');
374
+ console.log(' node maintain-language-purity.js --workflow\n');
375
+
376
+ return totalViolations;
377
+ }
378
+ }
379
+ }
380
+
381
+ // CLI Interface
382
+ if (require.main === module) {
383
+ const args = process.argv.slice(2);
384
+ const maintainer = new LanguagePurityMaintainer();
385
+
386
+ if (args.includes('--help') || args.includes('-h')) {
387
+ console.log(`
388
+ Language Purity Maintenance Tool
389
+
390
+ Usage:
391
+ node maintain-language-purity.js [options]
392
+
393
+ Options:
394
+ --workflow Run the complete language purity maintenance workflow
395
+ --quick Run a quick validation check only
396
+ --help, -h Show this help message
397
+
398
+ Examples:
399
+ node maintain-language-purity.js --workflow # Full maintenance workflow
400
+ node maintain-language-purity.js --quick # Quick validation check
401
+ node maintain-language-purity.js # Default: quick check
402
+
403
+ Workflow Steps:
404
+ 1. Initial language purity assessment
405
+ 2. Detect and auto-fix language mismatches
406
+ 3. Apply automatic translations
407
+ 4. Final language purity assessment
408
+ 5. Generate comprehensive report
409
+ `);
410
+ process.exit(0);
411
+ }
412
+
413
+ if (args.includes('--workflow')) {
414
+ maintainer.runCompleteWorkflow().then(results => {
415
+ const exitCode = results.summary.finalViolations > 0 ? 1 : 0;
416
+ process.exit(exitCode);
417
+ }).catch(error => {
418
+ console.error('❌ Workflow Error:', error.message);
419
+ process.exit(1);
420
+ });
421
+ } else {
422
+ // Default: quick validation
423
+ maintainer.quickValidation().then(violations => {
424
+ const exitCode = violations > 0 ? 1 : 0;
425
+ process.exit(exitCode);
426
+ }).catch(error => {
427
+ console.error('❌ Validation Error:', error.message);
428
+ process.exit(1);
429
+ });
430
+ }
431
+ }
432
+
433
+ module.exports = LanguagePurityMaintainer;