i18ntk 2.5.1 → 3.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 (40) hide show
  1. package/CHANGELOG.md +385 -0
  2. package/README.md +56 -47
  3. package/main/i18ntk-analyze.js +4 -4
  4. package/main/i18ntk-scanner.js +14 -12
  5. package/main/i18ntk-translate.js +502 -0
  6. package/main/i18ntk-validate.js +25 -18
  7. package/main/manage/commands/AnalyzeCommand.js +7 -4
  8. package/main/manage/commands/CommandRouter.js +7 -1
  9. package/main/manage/commands/FixerCommand.js +11 -1
  10. package/main/manage/commands/ScannerCommand.js +12 -10
  11. package/main/manage/commands/TranslateCommand.js +242 -0
  12. package/main/manage/commands/ValidateCommand.js +21 -17
  13. package/main/manage/index.js +17 -12
  14. package/package.json +13 -3
  15. package/runtime/enhanced.js +64 -10
  16. package/runtime/i18ntk.d.ts +10 -6
  17. package/runtime/index.js +45 -22
  18. package/ui-locales/de.json +3 -0
  19. package/ui-locales/en.json +3 -0
  20. package/ui-locales/es.json +3 -0
  21. package/ui-locales/fr.json +3 -0
  22. package/ui-locales/ja.json +3 -0
  23. package/ui-locales/ru.json +3 -1
  24. package/ui-locales/zh.json +3 -0
  25. package/utils/admin-auth.js +4 -1
  26. package/utils/config-helper.js +43 -37
  27. package/utils/config-manager.js +59 -49
  28. package/utils/config.js +13 -4
  29. package/utils/env-manager.js +3 -1
  30. package/utils/i18n-helper.js +41 -13
  31. package/utils/init-helper.js +23 -21
  32. package/utils/secure-errors.js +10 -6
  33. package/utils/security.js +30 -4
  34. package/utils/setup-enforcer.js +22 -33
  35. package/utils/translate/api.js +168 -0
  36. package/utils/translate/cli.js +91 -0
  37. package/utils/translate/placeholder.js +93 -0
  38. package/utils/translate/report.js +90 -0
  39. package/utils/translate/traverse.js +148 -0
  40. package/utils/watch-locales.js +12 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,385 @@
1
+ # CHANGELOG
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [3.0.0] - 2026-05-05
9
+
10
+ ### Added
11
+ - **`i18ntk-translate`**: Zero-dependency CLI tool that converts English source JSON locale files into any target language via Google's free Translate API.
12
+ - **Placeholder protection**: Intelligent detection, masking, and unmasking of dynamic placeholder tokens (`{name}`, `{{count}}`, `%d`, `%s`, `:param`, `{{variable}}`, `%{name}`, `${var}`, etc.) to prevent corruption during translation.
13
+ - **Custom regex support**: `--custom-regex` flag to define additional placeholder patterns for detection and protection.
14
+ - **Interactive control flow**: Two-level user controls — global choice (skip all / send all / ask per key) and per-key interactive mode where each affected key can be individually flagged.
15
+ - **Fully automated CLI mode**: `--no-confirm --skip-placeholders` or `--no-confirm --send-placeholders` flags for unattended CI/CD use.
16
+ - **Post-translation report**: Comprehensive report (stdout, file, or both) listing every skipped key with its original value and a reminder for manual translation.
17
+ - **Multi-file batch processing**: `--source-dir` and `--files` flags support translating all JSON files in a directory at once.
18
+ - **Dry-run mode**: `--dry-run` flag previews which keys would be skipped without making API calls.
19
+ - **UTF-8 BOM output**: `--bom` flag for output files with UTF-8 byte order mark.
20
+ - **Custom translation function**: `--translate-fn` flag to inject an alternative translation API while maintaining the placeholder safety workflow.
21
+ - **Rate-limit handling**: Exponential backoff/retry logic for Google Translate API rate limits and network errors.
22
+ - **Deep JSON traversal**: Full support for nested objects and arrays, preserving data types, null values, and non-string leaf values.
23
+
24
+ ### Changed
25
+ - Version bumped to 3.0.0 (major release with new translation tool feature).
26
+
27
+ ## [2.6.0] - 2026-05-03
28
+
29
+ ### Security
30
+ - **CRITICAL**: Fixed 8+ silent-write failures where `safeWriteFileSync` was called without basePath parameter across `utils/config.js`, `utils/config-helper.js`, `utils/secure-errors.js`, and `main/i18ntk-scanner.js`.
31
+ - Replaced all raw `fs` calls (`readdirSync`, `statSync`, `mkdirSync`, `unlinkSync`, `rmSync`) with `SecurityUtils` wrappers in `main/i18ntk-validate.js`, `main/i18ntk-scanner.js`, `main/manage/commands/FixerCommand.js`, and `utils/secure-errors.js`.
32
+ - Fixed path traversal checks in `security.js` and `config-manager.js` — replaced fragile `path.sep`-based comparison with robust `startsWith('..')` prefix check.
33
+ - Hardened `utils/i18n-helper.js` fallback `SecurityUtils` implementation with path containment checks.
34
+ - Fixed `SecurityUtils.safeParseJSON` reference leak — deep-clones objects instead of returning caller's reference.
35
+
36
+ ### Fixed
37
+ - Fixed `main/i18ntk-analyze.js` `this.adminAuth` reference error (local variable was not assigned to instance property).
38
+ - Fixed `main/i18ntk-validate.js` `ExitCodes.CONFIG_ERROR` referenced before declaration.
39
+ - Fixed `main/i18ntk-scanner.js` `fs.readdirSync(projectRoot, { recursive: true })` removed (unsupported in older Node.js).
40
+ - Fixed `main/i18ntk-scanner.js` raw `fs.readdirSync`/`fs.statSync`/`fs.mkdirSync` in `scanDirectory` and `generateReport`.
41
+ - Fixed `main/i18ntk-validate.js` raw `fs.readdirSync`/`fs.mkdirSync`/`fs.unlinkSync` in `getAvailableLanguages`, `getLanguageFiles`, and validation report cleanup.
42
+ - Fixed `utils/secure-errors.js` `safeWriteFileSync` missing basePath and raw `fs.mkdirSync`.
43
+ - Fixed `main/manage/commands/FixerCommand.js` `cleanupOldBackups` using raw `fs.rmSync` without path validation.
44
+ - Fixed `runtime/enhanced.js` process event handler leak (multiple instances) and missing `setInterval.unref()`.
45
+ - Fixed `utils/setup-enforcer.js` async Promise executor anti-pattern.
46
+ - Fixed `utils/config-manager.js` stale `process.cwd()` capture at module load time.
47
+ - Fixed `utils/config-manager.js` `ensureProjectSettingsDir` being a no-op.
48
+ - Fixed `utils/config-helper.js` 7 `safeWriteFileSync` calls missing basePath in `initializeSourceFiles`.
49
+ - Fixed `utils/env-manager.js` `getBoolean` comparison against non-boolean values.
50
+ - Fixed `utils/admin-auth.js` `uncaughtException` handler wrong parameter format.
51
+
52
+ ### Added
53
+ - `SecurityUtils.safeUnlinkSync(filePath, basePath)` — safely delete a file.
54
+ - `SecurityUtils.safeRmdirSync(dirPath, basePath)` — safely remove a directory.
55
+
56
+ ### Changed
57
+ - `configManager.resolvePaths`, `configManager.toRelative`, and config lock path now dynamically resolve via `getUserProjectRoot()`/`getProjectConfigPath()`.
58
+ - `configManager.CONFIG_PATH` is now a getter that dynamically returns the project config path.
59
+ - `configManager.migrateLegacyIfNeeded` exported for testability.
60
+
61
+ ### TypeScript
62
+ - Fixed `runtime/i18ntk.d.ts` `BasicI18nRuntime.translate` and `t` return types from `Promise<string>` to `string`.
63
+
64
+ ### Scripts
65
+ - Fixed `scripts/build-public-package.js` and `scripts/reset-release-state.js` `npm_execpath` fallback for missing env var.
66
+ - Fixed `scripts/lint-locales.js` BOM handling and try-catch for `fs.readdirSync`.
67
+
68
+ ## [2.5.1] - 2026-04-29
69
+
70
+ ### Security
71
+ - Fixed `AdminAuth.verifyPin()` to fail closed when admin config is missing, disabled, or malformed instead of returning success.
72
+ - Fixed auth-required checks to fail closed when settings require admin PIN protection but the admin config is unusable.
73
+ - Normalized admin session expiry handling by storing both `expires` and `expiresAt` and cleaning up both formats consistently.
74
+
75
+ ### Added
76
+ - Added regression tests for admin PIN fail-closed behavior and session expiry cleanup.
77
+
78
+ ### Changed
79
+ - Documented the public npm package staging flow introduced after `2.5.0`.
80
+
81
+ ## [2.5.0] - 2026-04-29
82
+
83
+ ### Security
84
+ - Centralized environment-variable access behind the `utils/env-manager.js` allowlist.
85
+ - Hardened `SecurityUtils.safeJoin()` and path validation against sibling-prefix containment bypasses.
86
+ - Switched admin PIN hash verification to timing-safe comparison.
87
+ - Fixed expired admin session cleanup and unref'd the cleanup timer so it does not keep CLI processes alive.
88
+ - Expanded the release security scanner to inspect nested production source files.
89
+
90
+ ### Fixed
91
+ - Fixed the manager fixer command so applied fixes are written to the same parsed object that is saved.
92
+ - Fixed fixer writes for absolute source directories outside the current working directory.
93
+ - Fixed debug-menu file reads to use `SecurityUtils` wrappers.
94
+ - Fixed `secure-errors` to import its `SecurityUtils` dependency explicitly.
95
+
96
+ ### Changed
97
+ - Updated package and documentation metadata to `2.5.0`.
98
+
99
+ ## [2.4.0] - 2026-04-16
100
+
101
+ ### Changed
102
+ - Disabled npm registry update-check behavior in CLI startup paths.
103
+ - Disabled manager-route backup execution (`i18ntk --command=backup`); standalone `i18ntk-backup` remains available.
104
+ - Disabled setup prerequisite command probing via `PATH` inspection.
105
+ - Updated README/docs/migration guides/environment variable documentation to reflect the above behavior.
106
+
107
+ ## [2.3.8] - 2026-04-13
108
+
109
+ ### Added
110
+ - Added centralized structured logger with standardized prefixes and configurable levels (`error`, `warn`, `info`, `debug`).
111
+ - Added opt-in JSON log output for CI/build pipelines via `JSON_LOG=true`.
112
+ - Added missing-translation-key cache TTL (5 minutes) to prevent repeated key-miss spam.
113
+ - Added build/worker logging utilities for percentage progress and pooled worker activity summaries.
114
+ - Added test coverage for logger timing/progress/worker aggregation behavior.
115
+
116
+ ### Fixed
117
+ - Fixed repeated default-configuration fallback output by emitting a single fallback notice per process.
118
+ - Fixed recursive security/i18n logging interactions that could trigger repeated warning cascades.
119
+ - Fixed false-positive security warnings for internal package/project absolute paths through internal root whitelisting.
120
+
121
+ ### Changed
122
+ - Logging is now silent by default for non-critical output in production-like builds unless `DEBUG_MODE=true`.
123
+ - Security warning reasons now use specific detection details instead of generic "dangerous patterns".
124
+ - Updated package/docs/version metadata to `2.3.8`.
125
+
126
+ ## [2.3.7] - 2026-04-12
127
+
128
+ ### Fixed
129
+ - Removed false-positive path traversal warnings for safe absolute project paths during framework builds.
130
+ - Reduced repeated default-configuration console noise in multi-worker build environments.
131
+
132
+ ### Changed
133
+ - Security event console logging is now fully opt-in via `I18NTK_ENABLE_SECURITY_LOGS=true` (or debug envs).
134
+ - Config-manager diagnostic console logging is now fully opt-in via `I18NTK_ENABLE_LOGS=true` (or debug envs).
135
+ - Updated docs to reflect new default-silent logging behavior and troubleshooting toggles.
136
+
137
+ ## [2.3.6] - 2026-04-12
138
+
139
+ ### Security
140
+ - **Fixed path traversal vulnerability** in temporary file creation
141
+ - **Added `safeJoin` function** for secure path construction
142
+ - **Improved path validation** throughout the codebase
143
+
144
+ ### Fixed
145
+ - Hardened settings reset and backup cleanup paths to reduce risk of broad/deep unintended file deletion.
146
+ - Hardened backup command path handling to keep source/output/restore operations inside project boundaries by default.
147
+ - Fixed backup-class async file operations to consistently use `fs.promises` APIs.
148
+
149
+ ### Changed
150
+ - **Silent security logging by default**: Info-level messages suppressed, warnings/errors shown
151
+ - **Debug mode**: Enable verbose logging with `I18N_DEBUG=true`
152
+ - **Centralized security logging**: All security events use `SecurityUtils.logSecurityEvent()`
153
+ - Made npm registry update checks explicit opt-in via `I18NTK_ENABLE_UPDATE_CHECK`.
154
+ - Updated package/docs/version metadata to `2.3.6`.
155
+
156
+ ## [2.3.4] - 2026-04-12
157
+
158
+ ### Fixed
159
+ - Fixed runtime autosave behavior so configuration write failures no longer hard-throw through request/render paths.
160
+ - Fixed config save race resilience by combining queued writes, cross-process lock files, and unique temp filenames per write.
161
+
162
+ ### Added
163
+ - Added `I18NTK_DISABLE_AUTOSAVE` support to skip disk persistence and keep in-memory config in server/runtime environments.
164
+ - Added config-manager concurrency regression test covering parallel `saveConfig` calls.
165
+
166
+ ### Changed
167
+ - Updated package/docs/version metadata to `2.3.4`.
168
+ - Updated support policy guidance to recommend upgrading from versions below `2.3.4`.
169
+
170
+ ## [2.3.3] - 2026-04-12
171
+
172
+ ### Fixed
173
+ - Fixed production config persistence race across multiple Node processes by adding cross-process file locking for `.i18ntk-config` writes.
174
+ - Fixed intermittent `ENOENT` during atomic config rename operations under concurrent production traffic.
175
+
176
+ ### Changed
177
+ - Updated package/docs/version metadata to `2.3.3`.
178
+ - Updated support policy guidance to recommend upgrading from versions below `2.3.3`.
179
+
180
+ ## [2.3.2] - 2026-04-12
181
+
182
+ ### Added
183
+ - Added startup npm-registry version checks that warn when the installed CLI is behind the latest published `i18ntk` release.
184
+ - Added support for checking all published semver versions up to the current latest tag to improve outdated-version detection reliability.
185
+
186
+ ### Fixed
187
+ - Fixed fatal analyze-command startup failure in manager command flow caused by missing `validateSourceDir` import.
188
+
189
+ ### Changed
190
+ - Updated package/docs/version metadata to `2.3.2`.
191
+ - Updated support policy guidance to recommend upgrading from versions below `2.3.2`.
192
+
193
+ ## [2.3.1] - 2026-04-12
194
+
195
+ ### Fixed
196
+ - Fixed package export-path fallback in `utils/i18n-helper` that could trigger build warnings in production bundlers (`i18ntk/resources/i18n/ui-locales/en.json` not exported).
197
+
198
+ ### Changed
199
+ - Updated package/docs/version metadata to `2.3.1`.
200
+ - Updated support policy guidance to recommend upgrading from versions below `2.3.1`.
201
+
202
+ ## [2.3.0] - 2026-04-12
203
+
204
+ ### Added
205
+ - Added validation summary report output after validation runs.
206
+ - Added init-time backup configuration prompt (default disabled, optional enable).
207
+
208
+ ### Fixed
209
+ - Fixed backup recursion/pollution risk by moving automated fixer backups to a dedicated backup root.
210
+ - Fixed backup retention behavior to keep 1 by default with enforced bounds up to 3.
211
+ - Fixed language discovery in validate/fixer flows to ignore backup/report directories.
212
+
213
+ ### Changed
214
+ - Updated package/docs/version metadata to `2.3.0`.
215
+ - Updated support policy guidance to recommend upgrading from versions below `2.3.0`.
216
+
217
+ ## [2.2.0] - 2026-04-12
218
+
219
+ ### Added
220
+ - Added an explicit upgrade/support notice in docs recommending upgrade from pre-`2.2.0` versions.
221
+ - Added migration guide for `v2.2.0`.
222
+
223
+ ### Fixed
224
+ - Fixed critical sizing workflow regressions.
225
+ - Fixed critical usage-analysis workflow regressions.
226
+ - Fixed runtime locale optimizer dependency path after publish-surface cleanup.
227
+
228
+ ### Changed
229
+ - Reduced publish surface by excluding internal development scripts from npm package artifacts.
230
+ - Excluded legacy fixed artifacts from package output (`main/manage/index-fixed.js`, `utils/security-fixed.js`).
231
+ - Updated package/docs/version metadata to `2.2.0`.
232
+
233
+ ## [2.1.1] - 2026-04-11
234
+
235
+ ### Added
236
+ - Version bump to 2.1.1 for release.
237
+ - Added `SecurityUtils.debugLog` function for consistent debugging.
238
+
239
+ ### Fixed
240
+ - Fixed `SecurityUtils.logSecurityEvent` calls missing `level` parameter in `i18ntk-usage` and `UsageService`.
241
+ - Fixed `level.toLowerCase is not a function` error in usage analysis.
242
+ - Fixed `SecurityUtils.debugLog is not a function` error in sizing analysis.
243
+
244
+ ### Changed
245
+ - Updated package and release metadata to `2.1.1`.
246
+ - Removed legacy `resources/i18n/ui-locales` path references (use `ui-locales/` instead).
247
+ - Updated all UI locale loading to use `ui-locales/` directory.
248
+
249
+ ## [2.1.0] - 2026-04-11
250
+
251
+ ### Added
252
+ - Added a v2.1.0 migration guide and updated release runbook references.
253
+ - Added stricter language-directory filtering in analysis paths to ignore backup/report folders.
254
+
255
+ ### Fixed
256
+ - Fixed interactive menu command flow so it reliably returns to the main menu after command completion.
257
+ - Fixed analysis progress output to report the correct processed-language count.
258
+ - Fixed duplicate report-save output lines during analysis.
259
+ - Fixed framework detection behavior to treat setup-complete projects as internally configured i18ntk projects.
260
+ - Fixed false-positive security warnings for valid configuration fields like `dateFormat`, `timeFormat`, and `reportLanguage`.
261
+ - Fixed locale-loading path fallback behavior to avoid noisy startup errors in global installs.
262
+
263
+ ### Changed
264
+ - Synchronized and normalized UI locale keys across `resources/i18n/ui-locales` and `ui-locales`.
265
+ - Updated package/release metadata to `2.1.0`.
266
+
267
+ ## [2.0.0] - 2026-01-01
268
+
269
+ ### Added
270
+ - Added missing runtime translation keys across `init`, `fixer`, `sizing`, `summary`, `usage`, and settings import/export flows.
271
+ - Added `SecurityUtils.safeParseJSON`, `SecurityUtils.safeReadFile`, and `SecurityUtils.safeWriteFile` compatibility APIs used by v2 command paths.
272
+ - Added source-locale bootstrap behavior during `init` when the source language directory exists but has no translation files.
273
+
274
+ ### Fixed
275
+ - Fixed initialization state detection to use project `.i18ntk-config` setup metadata as the v2 source of truth.
276
+ - Fixed false setup-invalid states caused by BOM-encoded config files during setup checks.
277
+ - Fixed config persistence risk by using atomic writes in `config-manager` save flow.
278
+ - Fixed self-dependency metadata so the package remains zero-dependency in v2.
279
+
280
+ ### Changed
281
+ - Updated package release metadata for the v2 line (`versionInfo`, deprecations, nextVersion).
282
+
283
+ ## [1.10.2] - 2025-08-23
284
+
285
+ ### 🚨 Critical Fix
286
+ - **Fixed projectRoot default path**: Resetting settings now correctly restores `projectRoot` to `/` instead of `./`, ensuring fresh installs work out-of-the-box
287
+
288
+ ### 🆕 New Features
289
+ - **Centralized Environment Variable Management**: Added comprehensive environment variable support with validation and security controls
290
+ - **Enhanced Debug Logging**: Improved debug logging with environment variable support for better troubleshooting
291
+ - **Secure Plugin Loading**: Added path sanitization for module loading to prevent security issues
292
+
293
+ ### 🔒 Security Enhancements
294
+ - **Enhanced Path Validation**: Strengthened path validation and file operations security
295
+ - **Secure Module Loading**: Added path sanitization for all plugin/module loading operations
296
+ - **Environment Variable Security**: Implemented centralized environment variable management with security filtering
297
+
298
+ ### 🛠️ Improvements
299
+ - **Refactored Configuration Handling**: Updated config system with integrated environment variable support
300
+ - **Enhanced Logging System**: Improved debug logging capabilities with environment variable integration
301
+ - **Better Error Handling**: Enhanced error messages and debugging information
302
+
303
+ ### 📚 Documentation
304
+ - **Environment Variables Guide**: Added comprehensive documentation for all supported environment variables
305
+ - **Migration Notes**: Added clear migration guidance for projectRoot path changes
306
+
307
+ ### 🔧 Technical Changes
308
+ - **Package Version**: Updated to v1.10.2 across all files
309
+ - **Security Patches**: Applied security improvements to path handling and file operations
310
+
311
+ ## [1.10.1] - 2025-08-22
312
+
313
+ ### Added
314
+ - **New Terminal-Icons Utility**: Added `terminal-icons` utility for better emoji support in terminal output
315
+ - **Enhanced UI Text Processing**: Improved text processing with terminal-safe fallbacks for special characters
316
+
317
+ ### Fixed
318
+ - Fixed infinite setup loop issue (Hotfix)
319
+ - Resolved version string update inconsistencies
320
+
321
+ ### Changed
322
+ - Update version strings across all files from 1.9.1 to 1.10.1
323
+ - Remove outdated package-lock.json and backup config
324
+
325
+ ## [1.10.0] - 2025-08-22
326
+
327
+ ### Added
328
+ - **Enhanced Runtime API**: Improved framework-agnostic translation runtime with better TypeScript support
329
+ - **Framework Detection**: Enhanced support for Next.js, Nuxt.js, and SvelteKit projects
330
+ - **Reset Script**: Added `reset-for-publish.js` for clean package publishing
331
+ - **Documentation**: Comprehensive updates for new features and improvements
332
+ - **Configuration Persistence**: Fixed configuration changes not being saved to disk
333
+ - **Caching System**: Added configuration caching to prevent redundant initialization
334
+
335
+ ### Fixed
336
+ - **DNR Functionality**: Fixed persistence of "Do Not Remind" settings across version updates
337
+ - **Settings Management**: Improved error handling and logging for settings operations
338
+ - **TypeScript Definitions**: Enhanced type safety and autocomplete for better developer experience
339
+ - **Performance**: Optimized translation lookups with reduced memory footprint
340
+ - **Shell Security**: Verified zero shell access vulnerabilities in setup-enforcer.js
341
+ - **Configuration Loading**: Fixed multiple "Initializing with default configuration" messages
342
+ - **Path Resolution**: Fixed source directory path handling for CLI arguments
343
+
344
+ ### Security
345
+ - **Settings Persistence**: Secure handling of user preferences and framework settings
346
+ - **Error Handling**: Improved error reporting for configuration issues
347
+ - **Dependencies**: Maintained zero runtime dependencies for maximum security
348
+ - **Shell Access**: Confirmed no child_process usage in setup-enforcer.js
349
+ - **Input Validation**: Enhanced path validation for source and output directories
350
+
351
+
352
+
353
+ ## [1.9.1] - 2025-08-14
354
+
355
+ ### Added
356
+ - **Python Support**: Full support for Python frameworks including Django, Flask, FastAPI, and generic Python projects
357
+ - **Enhanced Framework Detection**: Improved accuracy for all supported frameworks with new Python detection algorithms
358
+ - **Common Locale File**: Added `locales/common.json` for shared translation keys across frameworks
359
+ - **Zero Shell Security**: Complete removal of `child_process` dependencies for maximum security
360
+ - **Exit/Cancel Option**: Added option to exit/cancel (press 0) during directory selection in fixer command
361
+
362
+ ### Changed
363
+ - **Security Overhaul**: Replaced all `child_process` imports with native Node.js APIs
364
+ - **Performance**: Maintained 97% performance improvement while adding security enhancements
365
+ - **Framework Detection**: Updated detection patterns for JavaScript, Python, Go, Java, and PHP
366
+ - **File Structure**: Optimized package structure with removed outdated files
367
+ - **Documentation**: Comprehensive updates to reflect new features and security improvements
368
+
369
+ ### Removed
370
+ - **Outdated Test Files**: Cleaned up test directories and removed deprecated test scripts
371
+ - **Debug Tools**: Removed unused benchmark and package test files
372
+ - **Shell Dependencies**: Eliminated all shell command dependencies
373
+ - **Legacy Files**: Removed outdated configuration and development files
374
+
375
+ ### Security
376
+ - **Zero Vulnerabilities**: Successfully passed security audit with 0 vulnerabilities
377
+ - **Memory Safety**: Enhanced memory-safe operations throughout the codebase
378
+ - **Input Validation**: Improved validation for all user inputs and file operations
379
+ - **Dependency Cleanup**: Removed all shell-related dependencies
380
+
381
+ ### Performance
382
+ - **Zero Overhead**: Security enhancements added zero performance overhead
383
+ - **Python Detection**: Minimal overhead from new Python framework detection
384
+ - **Memory Usage**: Maintained <2MB memory usage for all operations
385
+ - **Validation**: Enhanced validation with no performance impact
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # i18ntk v2.5.1
1
+ # i18ntk v3.0.0
2
2
 
3
- Zero-dependency internationalization toolkit for setup, scanning, analysis, validation, usage tracking, and translation completion.
3
+ Zero-dependency internationalization toolkit for setup, scanning, analysis, validation, usage tracking, translation completion, automatic locale translation, and runtime translation loading.
4
4
 
5
5
  ![i18ntk Logo](https://raw.githubusercontent.com/vladnoskv/i18ntk/main/docs/screenshots/i18ntk-logo-public.PNG)
6
6
 
@@ -9,52 +9,25 @@ Zero-dependency internationalization toolkit for setup, scanning, analysis, vali
9
9
  [![node](https://img.shields.io/badge/node-%3E%3D16-339933)](https://nodejs.org)
10
10
  [![dependencies](https://img.shields.io/badge/dependencies-0-success)](https://www.npmjs.com/package/i18ntk)
11
11
  [![license](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)
12
- [![socket](https://socket.dev/api/badge/npm/package/i18ntk/2.5.1)](https://socket.dev/npm/package/i18ntk/overview/2.5.1)
12
+ [![socket](https://socket.dev/api/badge/npm/package/i18ntk/3.0.0)](https://socket.dev/npm/package/i18ntk/overview/3.0.0)
13
13
 
14
14
  ## Upgrade Notice
15
15
 
16
- Versions earlier than `2.5.1` may contain known stability and security issues.
17
- They are considered unsupported for production use. Upgrade to `2.5.1` or newer.
18
-
19
- ## v2.5.1 Security Update
20
-
21
- `v2.5.1` is a security and packaging-process update for the `2.5.x` release line.
22
-
23
- ### Change Summary
24
-
25
- - Hardened `utils/admin-auth.js` so `verifyPin()` fails closed when admin config is missing, disabled, or malformed.
26
- - Hardened auth-required checks so enabled PIN protection does not silently bypass authentication when admin config is unusable.
27
- - Normalized admin session expiry handling by storing both `expires` and `expiresAt` and cleaning up either format consistently.
28
- - Marked the root `package.json` as development-only and added a separate public manifest flow.
29
- - Added package scripts to stage, pack, and publish the public npm package from `package.public.json`.
30
- - Added a root publish guard via `prepack` and `prepublishOnly` to block accidental publishing of the development manifest.
31
- - Updated ignore rules to exclude release staging artifacts and public package metadata from the repo/package payload.
32
- - Replaced the expanded `SECURITY.md` policy with a shorter reporting-oriented policy and added community docs links.
33
- - Updated docs and release reset automation to use `npm run package:public` instead of `npm pack --dry-run`.
34
-
35
- ### Files Changed
36
-
37
- - `utils/admin-auth.js`: fixed fail-open PIN verification and session expiry consistency.
38
- - `tests/security.test.js`: added admin-auth fail-closed and session cleanup coverage.
39
- - `package.json`: set development-only metadata, adjusted included files, and added public packaging/publish scripts.
40
- - `package.public.json`: introduced the stripped public npm manifest.
41
- - `scripts/build-public-package.js`: added the public package staging, pack, and publish workflow.
42
- - `scripts/prevent-root-publish.js`: added a guard against publishing the root development manifest.
43
- - `scripts/reset-release-state.js`: switched release validation to the public package build flow.
44
- - `README.md`, `docs/README.md`, `docs/development/AGENTS.md`, `docs/migration-guide-v2.5.1.md`, `docs/migration-guide-v2.5.0.md`: documented the security fix, packaging, and community file layout.
45
- - `SECURITY.md`, `CODE_OF_CONDUCT.md`, `CONTRIBUTING.md`, `FUNDING.md`: updated or added community and security-facing docs.
46
- - `.gitignore`, `.npmignore`: excluded release staging output and public-package metadata.
47
-
48
- ### Audit Trail
49
-
50
- - Risk addressed: AI-based analysis flagged `verifyPin()` as fail-open when admin config was missing or disabled.
51
- - Behavior change: direct `verifyPin()` calls now return `false` unless a usable enabled PIN config exists.
52
- - Behavior change: when settings require PIN auth but admin config is broken, protected auth checks now require authentication and verification fails closed.
53
- - Risk: the root manifest is intentionally non-publishable, so publishing flows must use the public-package scripts.
54
- - Behavior change: `npm pack` and `npm publish` at the repo root are blocked by guard scripts.
55
- - Behavior change: the public npm payload is staged from `package.public.json` rather than the development manifest.
56
- - Validation note: release-state reset now exercises `npm run package:public` as part of its checks.
57
- - Validation note: this documentation update describes the working tree changes used for the packaging split.
16
+ Versions earlier than `3.0.0` may contain known stability and security issues.
17
+ They are considered unsupported for production use. Upgrade to `3.0.0` or newer.
18
+
19
+ ## v3.0.0 - Auto Translate Release
20
+
21
+ v3.0.0 adds automatic JSON locale translation through the management menu and the standalone `i18ntk-translate` command. Highlights:
22
+
23
+ - **Auto Translate (Beta)**: Translate one or more source JSON files into one or more target languages from menu option 14.
24
+ - **Standalone CLI**: Use `i18ntk-translate <source-file> <target-lang>` for direct automation and batch translation.
25
+ - **Dry-run preview**: Review translated/skipped counts before writing target files.
26
+ - **Placeholder protection**: Detect and preserve placeholders such as `{name}`, `{{count}}`, `%s`, `%d`, `:id`, `%{name}`, and `${value}`.
27
+ - **Post-translation report**: Print or write translated and skipped key counts.
28
+ - **Zero dependencies**: Translation support uses built-in Node.js modules and the free Google Translate endpoint.
29
+
30
+ For the full detailed changelog, see [CHANGELOG.md](./CHANGELOG.md). For migration notes, see [docs/migration-guide-v3.0.0.md](./docs/migration-guide-v3.0.0.md).
58
31
 
59
32
  ## What i18ntk Does
60
33
 
@@ -63,6 +36,7 @@ They are considered unsupported for production use. Upgrade to `2.5.1` or newer.
63
36
  - Translation completeness analysis and usage tracking
64
37
  - Validation, sizing, and summary reporting
65
38
  - Missing-key completion and fixer workflows
39
+ - Automatic translation of JSON locale files
66
40
  - Runtime translation helpers for application code
67
41
  - Support for JS/TS, React, Vue, Angular, and generic projects
68
42
 
@@ -73,6 +47,7 @@ They are considered unsupported for production use. Upgrade to `2.5.1` or newer.
73
47
  3. Confirm the source language and locale directories.
74
48
  4. Run `i18ntk --command=analyze` or `i18ntk --command=validate` to inspect translation coverage.
75
49
  5. Use `i18ntk --command=complete` to fill missing keys when needed.
50
+ 6. Use `i18ntk --command=translate` or menu option 14 to auto-translate source JSON files.
76
51
 
77
52
  The full onboarding flow is documented in [docs/getting-started.md](docs/getting-started.md).
78
53
 
@@ -125,6 +100,7 @@ i18ntk --command=usage
125
100
  i18ntk --command=scanner
126
101
  i18ntk --command=sizing
127
102
  i18ntk --command=complete
103
+ i18ntk --command=translate
128
104
  i18ntk --command=summary
129
105
  ```
130
106
 
@@ -142,6 +118,7 @@ i18ntk-summary
142
118
  i18ntk-doctor
143
119
  i18ntk-fixer
144
120
  i18ntk-backup
121
+ i18ntk-translate
145
122
  ```
146
123
 
147
124
  Note: `i18ntk --command=backup` in the manager flow is disabled in current builds.
@@ -158,12 +135,42 @@ Use the standalone `i18ntk-backup` executable when backup operations are require
158
135
  - `--dry-run`
159
136
  - `--help`
160
137
 
138
+ Auto Translate also supports:
139
+
140
+ - `--source-lang <code>`
141
+ - `--files <pattern>`
142
+ - `--skip-placeholders`
143
+ - `--send-placeholders`
144
+ - `--report-file <path>`
145
+ - `--report-stdout`
146
+
161
147
  Example:
162
148
 
163
149
  ```bash
164
150
  i18ntk --command=analyze --source-dir=./src --i18n-dir=./locales --output-dir=./i18ntk-reports
165
151
  ```
166
152
 
153
+ ## Auto Translate
154
+
155
+ Interactive menu flow:
156
+
157
+ ```bash
158
+ i18ntk
159
+ # choose "Auto Translate (Beta)"
160
+ ```
161
+
162
+ Direct CLI examples:
163
+
164
+ ```bash
165
+ i18ntk-translate locales/en/common.json de
166
+ i18ntk-translate locales/en/common.json fr --dry-run --report-stdout
167
+ i18ntk-translate locales/en es --files "*.json" --no-confirm --skip-placeholders
168
+ ```
169
+
170
+ The manager flow accepts comma- or space-separated target language codes, previews the first target language with a dry run, asks for confirmation, then writes translated files under matching target-language directories such as `locales/de/common.json`.
171
+
172
+ See [docs/auto-translate.md](docs/auto-translate.md) for full usage details.
173
+
167
174
  ## Runtime API
168
175
 
169
176
  Use `i18ntk/runtime` when your application needs to read locale JSON files at runtime.
@@ -194,7 +201,7 @@ Example `.i18ntk-config`:
194
201
 
195
202
  ```json
196
203
  {
197
- "version": "2.5.1",
204
+ "version": "3.0.0",
198
205
  "sourceDir": "./locales",
199
206
  "i18nDir": "./locales",
200
207
  "outputDir": "./i18ntk-reports",
@@ -215,10 +222,12 @@ See [docs/api/CONFIGURATION.md](docs/api/CONFIGURATION.md) for the full configur
215
222
  - [API Reference](https://github.com/vladnoskv/i18ntk/blob/main/docs/api/API_REFERENCE.md)
216
223
  - [Configuration Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/api/CONFIGURATION.md)
217
224
  - [Runtime API Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/runtime.md)
225
+ - [Auto Translate Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/auto-translate.md)
218
226
  - [Scanner Guide](https://github.com/vladnoskv/i18ntk/blob/main/docs/scanner-guide.md)
219
227
  - [Environment Variables](https://github.com/vladnoskv/i18ntk/blob/main/docs/environment-variables.md)
228
+ - [Migration Guide v3.0.0](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v3.0.0.md)
229
+ - [Migration Guide v2.6.0](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v2.6.0.md)
220
230
  - [Migration Guide v2.5.1](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v2.5.1.md)
221
- - [Migration Guide v2.5.0](https://github.com/vladnoskv/i18ntk/blob/main/docs/migration-guide-v2.5.0.md)
222
231
 
223
232
  ## Community
224
233
 
@@ -252,7 +252,7 @@ class I18nAnalyzer {
252
252
  const relativePath = path.relative(this.sourceDir, fullPath);
253
253
  const shouldExclude = (this.config.excludeFiles || []).some(pattern => {
254
254
  if (typeof pattern === 'string') {
255
- return relativePath === pattern || relativePath.endsWith(path.sep + pattern);
255
+ return relativePath === pattern || relativePath.endsWith('/' + pattern) || relativePath.endsWith('\\' + pattern);
256
256
  }
257
257
  if (pattern instanceof RegExp) {
258
258
  return pattern.test(relativePath);
@@ -908,9 +908,9 @@ try {
908
908
  const isRequired = await adminAuth.isAuthRequired();
909
909
  if (isRequired) {
910
910
  console.log('\n' + t('adminCli.authRequiredForOperation', { operation: 'analyze translations' }));
911
- const cliHelper = require('../utils/cli-helper');
912
- const pin = await cliHelper.promptPin(t('adminCli.enterPin'));
913
- const isValid = await this.adminAuth.verifyPin(pin);
911
+ const cli = require('../utils/cli-helper');
912
+ const pin = await cli.promptPin(t('adminCli.enterPin'));
913
+ const isValid = await adminAuth.verifyPin(pin);
914
914
 
915
915
  if (!isValid) {
916
916
  console.log(t('adminCli.invalidPin'));
@@ -181,9 +181,9 @@ class I18nTextScanner {
181
181
  if (pyproject.includes('Flask')) return 'flask';
182
182
  }
183
183
 
184
- // Check for Python files
185
- const hasPythonFiles = fs.readdirSync(projectRoot, { recursive: true })
186
- .some(file => file.endsWith && file.endsWith('.py'));
184
+ // Check for Python files using safeReaddirSync
185
+ const pythonItems = SecurityUtils.safeReaddirSync(projectRoot, projectRoot, { withFileTypes: true }) || [];
186
+ const hasPythonFiles = pythonItems.some(item => item.isFile && item.name && item.name.endsWith('.py'));
187
187
  if (hasPythonFiles) return 'python';
188
188
  } catch (error) {
189
189
  // Continue to JS frameworks
@@ -420,20 +420,22 @@ class I18nTextScanner {
420
420
  const extensions = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.html', '.svelte', '.py', '.pyx', '.pyi'];
421
421
 
422
422
  const scanRecursive = (currentDir) => {
423
- const items = fs.readdirSync(currentDir);
423
+ const items = SecurityUtils.safeReaddirSync(currentDir, path.dirname(currentDir), { withFileTypes: true });
424
+ if (!items) return;
424
425
 
425
426
  for (const item of items) {
426
- const fullPath = path.join(currentDir, item);
427
- const stat = fs.statSync(fullPath);
427
+ const fullPath = path.join(currentDir, item.name);
428
+ const stat = SecurityUtils.safeStatSync(fullPath, currentDir);
429
+ if (!stat) continue;
428
430
 
429
431
  if (stat.isDirectory()) {
430
- if (!item.startsWith('.') && !this.shouldExcludeFile(fullPath, exclusions)) {
432
+ if (!item.name.startsWith('.') && !this.shouldExcludeFile(fullPath, exclusions)) {
431
433
  scanRecursive(fullPath);
432
434
  }
433
435
  } else if (stat.isFile()) {
434
- const ext = path.extname(item);
436
+ const ext = path.extname(item.name);
435
437
  if (extensions.includes(ext) && !this.shouldExcludeFile(fullPath, exclusions)) {
436
- if (!includeTests && (item.includes('.test.') || item.includes('.spec.'))) {
438
+ if (!includeTests && (item.name.includes('.test.') || item.name.includes('.spec.'))) {
437
439
  continue;
438
440
  }
439
441
 
@@ -455,7 +457,7 @@ class I18nTextScanner {
455
457
 
456
458
  async generateReport(results, outputDir) {
457
459
  if (!SecurityUtils.safeExistsSync(outputDir, path.dirname(outputDir))) {
458
- fs.mkdirSync(outputDir, { recursive: true });
460
+ SecurityUtils.safeMkdirSync(outputDir, process.cwd(), { recursive: true });
459
461
  }
460
462
 
461
463
  const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
@@ -472,11 +474,11 @@ class I18nTextScanner {
472
474
  };
473
475
 
474
476
  // JSON report
475
- SecurityUtils.safeWriteFileSync(reportFile, JSON.stringify(summary, null, 2), outputDir);
477
+ SecurityUtils.safeWriteFileSync(reportFile, JSON.stringify(summary, null, 2), outputDir, 'utf8');
476
478
 
477
479
  // Markdown summary
478
480
  const mdContent = this.generateMarkdownReport(summary);
479
- SecurityUtils.safeWriteFileSync(summaryFile, mdContent, outputDir);
481
+ SecurityUtils.safeWriteFileSync(summaryFile, mdContent, outputDir, 'utf8');
480
482
 
481
483
  return { reportFile, summaryFile, summary };
482
484
  }