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.
- package/CHANGELOG.md +385 -0
- package/README.md +56 -47
- package/main/i18ntk-analyze.js +4 -4
- package/main/i18ntk-scanner.js +14 -12
- package/main/i18ntk-translate.js +502 -0
- package/main/i18ntk-validate.js +25 -18
- package/main/manage/commands/AnalyzeCommand.js +7 -4
- package/main/manage/commands/CommandRouter.js +7 -1
- package/main/manage/commands/FixerCommand.js +11 -1
- package/main/manage/commands/ScannerCommand.js +12 -10
- package/main/manage/commands/TranslateCommand.js +242 -0
- package/main/manage/commands/ValidateCommand.js +21 -17
- package/main/manage/index.js +17 -12
- package/package.json +13 -3
- package/runtime/enhanced.js +64 -10
- package/runtime/i18ntk.d.ts +10 -6
- package/runtime/index.js +45 -22
- package/ui-locales/de.json +3 -0
- package/ui-locales/en.json +3 -0
- package/ui-locales/es.json +3 -0
- package/ui-locales/fr.json +3 -0
- package/ui-locales/ja.json +3 -0
- package/ui-locales/ru.json +3 -1
- package/ui-locales/zh.json +3 -0
- package/utils/admin-auth.js +4 -1
- package/utils/config-helper.js +43 -37
- package/utils/config-manager.js +59 -49
- package/utils/config.js +13 -4
- package/utils/env-manager.js +3 -1
- package/utils/i18n-helper.js +41 -13
- package/utils/init-helper.js +23 -21
- package/utils/secure-errors.js +10 -6
- package/utils/security.js +30 -4
- package/utils/setup-enforcer.js +22 -33
- package/utils/translate/api.js +168 -0
- package/utils/translate/cli.js +91 -0
- package/utils/translate/placeholder.js +93 -0
- package/utils/translate/report.js +90 -0
- package/utils/translate/traverse.js +148 -0
- package/utils/watch-locales.js +12 -5
package/runtime/index.js
CHANGED
|
@@ -30,7 +30,18 @@ function stripBOMAndComments(s) {
|
|
|
30
30
|
|
|
31
31
|
function readJsonSafe(file) {
|
|
32
32
|
const raw = SecurityUtils.safeReadFileSync(file, path.dirname(file), 'utf8');
|
|
33
|
-
|
|
33
|
+
if (raw === null || raw === undefined) {
|
|
34
|
+
throw new Error(`Unable to read JSON file: ${file}`);
|
|
35
|
+
}
|
|
36
|
+
const cleaned = stripBOMAndComments(raw);
|
|
37
|
+
if (!cleaned) {
|
|
38
|
+
throw new Error(`Empty JSON file: ${file}`);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(cleaned);
|
|
42
|
+
} catch (parseError) {
|
|
43
|
+
throw new Error(`Invalid JSON in file ${file}: ${parseError.message}`);
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
function deepMerge(target, source) {
|
|
@@ -93,13 +104,17 @@ function listJsonFilesRecursively(dir) {
|
|
|
93
104
|
while (stack.length) {
|
|
94
105
|
const d = stack.pop();
|
|
95
106
|
if (!SecurityUtils.safeExistsSync(d)) continue;
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
try {
|
|
108
|
+
for (const entry of fs.readdirSync(d, { withFileTypes: true })) {
|
|
109
|
+
const full = path.join(d, entry.name);
|
|
110
|
+
if (entry.isDirectory()) {
|
|
111
|
+
stack.push(full);
|
|
112
|
+
} else if (entry.isFile() && entry.name.toLowerCase().endsWith('.json')) {
|
|
113
|
+
results.push(full);
|
|
114
|
+
}
|
|
102
115
|
}
|
|
116
|
+
} catch (_) {
|
|
117
|
+
// Skip directories we cannot read
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
return results;
|
|
@@ -111,7 +126,8 @@ function readLanguageFromBase(baseDir, lang) {
|
|
|
111
126
|
const langDir = path.join(baseDir, lang);
|
|
112
127
|
|
|
113
128
|
// Prefer folder if exists, otherwise single file
|
|
114
|
-
|
|
129
|
+
const langDirStat = SecurityUtils.safeStatSync(langDir, path.dirname(langDir));
|
|
130
|
+
if (langDirStat && langDirStat.isDirectory()) {
|
|
115
131
|
const files = listJsonFilesRecursively(langDir);
|
|
116
132
|
for (const file of files) {
|
|
117
133
|
try {
|
|
@@ -121,11 +137,14 @@ function readLanguageFromBase(baseDir, lang) {
|
|
|
121
137
|
// Skip unreadable/invalid files
|
|
122
138
|
}
|
|
123
139
|
}
|
|
124
|
-
} else
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
140
|
+
} else {
|
|
141
|
+
const langFileStat = SecurityUtils.safeStatSync(langFile, path.dirname(langFile));
|
|
142
|
+
if (langFileStat && langFileStat.isFile()) {
|
|
143
|
+
try {
|
|
144
|
+
const data = readJsonSafe(langFile);
|
|
145
|
+
if (data && typeof data === 'object') deepMerge(merged, data);
|
|
146
|
+
} catch (_) { /* ignore */ }
|
|
147
|
+
}
|
|
129
148
|
}
|
|
130
149
|
|
|
131
150
|
return merged;
|
|
@@ -211,16 +230,20 @@ function getAvailableLanguages() {
|
|
|
211
230
|
const langs = new Set();
|
|
212
231
|
if (!state.baseDir) state.baseDir = resolveBaseDir();
|
|
213
232
|
if (!SecurityUtils.safeExistsSync(state.baseDir)) return ['en'];
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
try {
|
|
234
|
+
for (const entry of fs.readdirSync(state.baseDir, { withFileTypes: true })) {
|
|
235
|
+
if (entry.isFile() && entry.name.toLowerCase().endsWith('.json')) {
|
|
236
|
+
langs.add(entry.name.replace(/\.json$/i, ''));
|
|
237
|
+
} else if (entry.isDirectory()) {
|
|
238
|
+
const lang = entry.name;
|
|
239
|
+
const idx = path.join(state.baseDir, lang, `${lang}.json`);
|
|
240
|
+
if (SecurityUtils.safeExistsSync(idx)) langs.add(lang);
|
|
241
|
+
else langs.add(lang); // be permissive
|
|
242
|
+
}
|
|
223
243
|
}
|
|
244
|
+
} catch (_) {
|
|
245
|
+
// Unreadable directory
|
|
246
|
+
return ['en'];
|
|
224
247
|
}
|
|
225
248
|
return Array.from(langs.size ? langs : new Set(['en']));
|
|
226
249
|
}
|
package/ui-locales/de.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - Projektstatus anzeigen",
|
|
923
923
|
"debugCommand": "debug - Übersetzungsfehler debuggen",
|
|
924
924
|
"scannerCommand": "scanner - Projekt für i18n-Schlüssel scannen",
|
|
925
|
+
"translateCommand": "translate - Auto-Übersetzung (Beta)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "Drücken Sie die Eingabetaste, um fortzufahren...",
|
|
927
928
|
"title": "🌐 I18NTK VERWALTUNGSMENÜ",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 Größenanalyse",
|
|
1147
1148
|
"fix": "🛠️ Platzhalterübersetzungen reparieren",
|
|
1148
1149
|
"scanner": "🔍 i18n-Probleme scannen",
|
|
1150
|
+
"translate": "🌐 Auto-Übersetzung (Beta)",
|
|
1149
1151
|
"workflow": "🔄 Gesamten Workflow ausführen",
|
|
1150
1152
|
"status": "📋 Projektstatus anzeigen",
|
|
1151
1153
|
"delete": "🗑️ Alle Berichte löschen",
|
|
@@ -2111,6 +2113,7 @@
|
|
|
2111
2113
|
"completeCommand": "complete - Übersetzungen vervollständigen (100% Abdeckung)",
|
|
2112
2114
|
"summaryCommand": "summary - Projektstatus anzeigen",
|
|
2113
2115
|
"scannerCommand": "scanner - i18n-Probleme scannen",
|
|
2116
|
+
"translateCommand": "translate - Auto-Übersetzung (Beta)",
|
|
2114
2117
|
"debugCommand": "debug - Übersetzungsprobleme debuggen"
|
|
2115
2118
|
},
|
|
2116
2119
|
"test_complete_system": {
|
package/ui-locales/en.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - Show project status",
|
|
923
923
|
"debugCommand": "debug - Debug translation issues",
|
|
924
924
|
"scannerCommand": "scanner - Scan for keys",
|
|
925
|
+
"translateCommand": "translate - Auto-translate locale files (Beta)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "Press Enter to continue...",
|
|
927
928
|
"title": "🌐 I18NTK MANAGEMENT MENU",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 Analyze sizing",
|
|
1147
1148
|
"fix": "🛠️ Fix placeholder translations",
|
|
1148
1149
|
"scanner": "🔍 Scan for i18n issues",
|
|
1150
|
+
"translate": "🌐 Auto Translate (Beta)",
|
|
1149
1151
|
"workflow": "🔄 Run full workflow",
|
|
1150
1152
|
"status": "📋 Show project status",
|
|
1151
1153
|
"delete": "🗑️ Delete all reports",
|
|
@@ -2109,6 +2111,7 @@
|
|
|
2109
2111
|
"completeCommand": "complete - Complete translations (100% coverage)",
|
|
2110
2112
|
"summaryCommand": "summary - Show project status",
|
|
2111
2113
|
"scannerCommand": "scanner - Scan for i18n issues",
|
|
2114
|
+
"translateCommand": "translate - Auto-translate locale files (Beta)",
|
|
2112
2115
|
"debugCommand": "debug - Debug translation issues"
|
|
2113
2116
|
},
|
|
2114
2117
|
"test_complete_system": {
|
package/ui-locales/es.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - Mostrar estado del proyecto",
|
|
923
923
|
"debugCommand": "debug - Depurar problemas de traducción",
|
|
924
924
|
"scannerCommand": "scanner - Escanear proyecto para claves i18n",
|
|
925
|
+
"translateCommand": "translate - Traducción automática (Beta)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "Presiona Enter para continuar...",
|
|
927
928
|
"title": "🌐 MENÚ DE GESTIÓN I18NTK",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 Analizar dimensionamiento",
|
|
1147
1148
|
"fix": "🛠️ Corregir traducciones provisionales",
|
|
1148
1149
|
"scanner": "🔍 Buscar problemas de i18n",
|
|
1150
|
+
"translate": "🌐 Traducción Automática (Beta)",
|
|
1149
1151
|
"workflow": "🔄 Ejecutar flujo completo",
|
|
1150
1152
|
"status": "📋 Mostrar estado del proyecto",
|
|
1151
1153
|
"delete": "🗑️ Eliminar todos los informes",
|
|
@@ -2111,6 +2113,7 @@
|
|
|
2111
2113
|
"completeCommand": "complete - Completar traducciones (100% cobertura)",
|
|
2112
2114
|
"summaryCommand": "summary - Mostrar estado del proyecto",
|
|
2113
2115
|
"scannerCommand": "scanner - Escanear problemas i18n",
|
|
2116
|
+
"translateCommand": "translate - Traducción automática (Beta)",
|
|
2114
2117
|
"debugCommand": "debug - Depurar problemas de traducción"
|
|
2115
2118
|
},
|
|
2116
2119
|
"test_complete_system": {
|
package/ui-locales/fr.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - Afficher le statut du projet",
|
|
923
923
|
"debugCommand": "debug - Déboguer les problèmes de traduction",
|
|
924
924
|
"scannerCommand": "scanner - Rechercher des clés",
|
|
925
|
+
"translateCommand": "translate - Traduction automatique (Bêta)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "Appuyez sur Entrée pour continuer...",
|
|
927
928
|
"title": "🌐 MENU DE GESTION I18NTK",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 Analyser le dimensionnement",
|
|
1147
1148
|
"fix": "🛠️ Corriger les traductions de remplacement",
|
|
1148
1149
|
"scanner": "🔍 Analyser les problèmes i18n",
|
|
1150
|
+
"translate": "🌐 Traduction Automatique (Bêta)",
|
|
1149
1151
|
"workflow": "🔄 Exécuter le flux complet",
|
|
1150
1152
|
"status": "📋 Afficher le statut du projet",
|
|
1151
1153
|
"delete": "🗑️ Supprimer tous les rapports",
|
|
@@ -2111,6 +2113,7 @@
|
|
|
2111
2113
|
"completeCommand": "complete - Compléter les traductions (couverture 100%)",
|
|
2112
2114
|
"summaryCommand": "summary - Afficher l'état du projet",
|
|
2113
2115
|
"scannerCommand": "scanner - Scanner le projet pour les clés i18n",
|
|
2116
|
+
"translateCommand": "translate - Traduction automatique (Bêta)",
|
|
2114
2117
|
"debugCommand": "debug - Déboguer les problèmes de traduction"
|
|
2115
2118
|
},
|
|
2116
2119
|
"test_complete_system": {
|
package/ui-locales/ja.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - プロジェクトのステータスを表示",
|
|
923
923
|
"debugCommand": "debug - 翻訳の問題をデバッグ",
|
|
924
924
|
"scannerCommand": "scanner - プロジェクトをスキャン",
|
|
925
|
+
"translateCommand": "translate - 自動翻訳 (ベータ版)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "Enterキーを押して続行してください…",
|
|
927
928
|
"title": "🌐 I18NTK 管理メニュー",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 サイズを分析",
|
|
1147
1148
|
"fix": "🛠️ プレースホルダー翻訳を修正",
|
|
1148
1149
|
"scanner": "🔍 i18n問題をスキャン",
|
|
1150
|
+
"translate": "🌐 自動翻訳 (ベータ版)",
|
|
1149
1151
|
"workflow": "🔄 フルワークフローを実行",
|
|
1150
1152
|
"status": "📋 プロジェクトステータスを表示",
|
|
1151
1153
|
"delete": "🗑️ すべてのレポートを削除",
|
|
@@ -2111,6 +2113,7 @@
|
|
|
2111
2113
|
"completeCommand": "complete - 翻訳を完了 (100% カバレッジ)",
|
|
2112
2114
|
"summaryCommand": "summary - プロジェクトステータスを表示",
|
|
2113
2115
|
"scannerCommand": "scanner - 🔍 i18nの問題をスキャン",
|
|
2116
|
+
"translateCommand": "translate - 自動翻訳 (ベータ版)",
|
|
2114
2117
|
"debugCommand": "debug - 翻訳の問題をデバッグ"
|
|
2115
2118
|
},
|
|
2116
2119
|
"test_complete_system": {
|
package/ui-locales/ru.json
CHANGED
|
@@ -1146,6 +1146,7 @@
|
|
|
1146
1146
|
"sizing": "📏 Анализ размеров",
|
|
1147
1147
|
"fix": "🛠️ Исправить переводы-заглушки",
|
|
1148
1148
|
"scanner": "🔍 Сканировать проблемы i18n",
|
|
1149
|
+
"translate": "🌐 Автоперевод (Бета)",
|
|
1149
1150
|
"workflow": "🔄 Запустить полный рабочий процесс",
|
|
1150
1151
|
"status": "📋 Показать статус проекта",
|
|
1151
1152
|
"delete": "🗑️ Удалить все отчёты",
|
|
@@ -2110,7 +2111,8 @@
|
|
|
2110
2111
|
"sizingCommand": "Оценка команды",
|
|
2111
2112
|
"completeCommand": "Завершение команды",
|
|
2112
2113
|
"summaryCommand": "Сводка команды",
|
|
2113
|
-
|
|
2114
|
+
"scannerCommand": "scanner - 🔍 Сканирование проблем i18n",
|
|
2115
|
+
"translateCommand": "translate - Автоперевод (Бета)",
|
|
2114
2116
|
"debugCommand": "Отладка команды"
|
|
2115
2117
|
},
|
|
2116
2118
|
"test_complete_system": {
|
package/ui-locales/zh.json
CHANGED
|
@@ -922,6 +922,7 @@
|
|
|
922
922
|
"summaryCommand": "summary - 显示项目状态",
|
|
923
923
|
"debugCommand": "debug - 调试翻译问题",
|
|
924
924
|
"scannerCommand": "scanner - 扫描项目中的 i18n 键",
|
|
925
|
+
"translateCommand": "translate - 自动翻译 (测试版)",
|
|
925
926
|
"menu": {
|
|
926
927
|
"pressEnterToContinue": "按 Enter 继续...",
|
|
927
928
|
"title": "🌐 国际化管理菜单",
|
|
@@ -1146,6 +1147,7 @@
|
|
|
1146
1147
|
"sizing": "📏 分析大小差异",
|
|
1147
1148
|
"fix": "🛠️ 修复占位翻译",
|
|
1148
1149
|
"scanner": "🔍 扫描i18n问题",
|
|
1150
|
+
"translate": "🌐 自动翻译 (测试版)",
|
|
1149
1151
|
"workflow": "🔄 运行完整工作流",
|
|
1150
1152
|
"status": "📋 显示项目状态",
|
|
1151
1153
|
"delete": "🗑️ 删除全部报告",
|
|
@@ -2111,6 +2113,7 @@
|
|
|
2111
2113
|
"completeCommand": "complete - 完成翻译(100% 覆盖)",
|
|
2112
2114
|
"summaryCommand": "summary - 显示项目状态",
|
|
2113
2115
|
"scannerCommand": "scanner - 🔍 扫描i18n问题",
|
|
2116
|
+
"translateCommand": "translate - 自动翻译 (测试版)",
|
|
2114
2117
|
"debugCommand": "debug - 调试翻译问题"
|
|
2115
2118
|
},
|
|
2116
2119
|
"test_complete_system": {
|
package/utils/admin-auth.js
CHANGED
|
@@ -374,7 +374,10 @@ class AdminAuth {
|
|
|
374
374
|
process.exit(0);
|
|
375
375
|
});
|
|
376
376
|
process.on('uncaughtException', (error) => {
|
|
377
|
-
SecurityUtils.logSecurityEvent('uncaught_exception', 'error',
|
|
377
|
+
SecurityUtils.logSecurityEvent('uncaught_exception', 'error', {
|
|
378
|
+
message: error && error.message ? error.message : 'Unknown uncaught exception',
|
|
379
|
+
stack: error && error.stack ? String(error.stack).split('\n').slice(0, 3).join('\n') : undefined
|
|
380
|
+
});
|
|
378
381
|
cleanup();
|
|
379
382
|
process.exit(1);
|
|
380
383
|
});
|
package/utils/config-helper.js
CHANGED
|
@@ -51,7 +51,9 @@ async function getUnifiedConfig(scriptName, cliArgs = {}) {
|
|
|
51
51
|
}
|
|
52
52
|
settingsDir = safeConfigDir;
|
|
53
53
|
const configFile = path.join(settingsDir, 'i18ntk-config.json');
|
|
54
|
-
|
|
54
|
+
const rawConfig = SecurityUtils.safeReadFileSync(configFile, settingsDir, 'utf8');
|
|
55
|
+
cfg = rawConfig ? SecurityUtils.safeParseJSON(rawConfig) : {};
|
|
56
|
+
if (!cfg || typeof cfg !== 'object') cfg = {};
|
|
55
57
|
projectRoot = settingsDir;
|
|
56
58
|
cfg.projectRoot = projectRoot;
|
|
57
59
|
cfg.sourceDir = path.resolve(projectRoot, toStr(cfg.sourceDir) || './locales');
|
|
@@ -60,11 +62,15 @@ async function getUnifiedConfig(scriptName, cliArgs = {}) {
|
|
|
60
62
|
} else {
|
|
61
63
|
cfg = configManager.getConfig();
|
|
62
64
|
// Use current working directory instead of hardcoded path
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
+
const isSuspiciousPath = cfg.projectRoot && (
|
|
66
|
+
cfg.projectRoot.includes('i18n-management-toolkit-main') ||
|
|
67
|
+
cfg.projectRoot.includes('i18ntk-') ||
|
|
68
|
+
!SecurityUtils.safeExistsSync(cfg.projectRoot, path.dirname(cfg.projectRoot || '.'))
|
|
69
|
+
);
|
|
70
|
+
projectRoot = isSuspiciousPath ? process.cwd() : path.resolve(cfg.projectRoot || '.');
|
|
65
71
|
|
|
66
72
|
// Update config with dynamic project root
|
|
67
|
-
if (
|
|
73
|
+
if (isSuspiciousPath) {
|
|
68
74
|
cfg.projectRoot = '.';
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -110,7 +116,7 @@ async function getUnifiedConfig(scriptName, cliArgs = {}) {
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
// Auto-fix i18nDir if missing but sourceDir exists
|
|
113
|
-
if (!SecurityUtils.safeExistsSync(cfg.i18nDir) && SecurityUtils.safeExistsSync(cfg.sourceDir)) {
|
|
119
|
+
if (!SecurityUtils.safeExistsSync(cfg.i18nDir, projectRoot) && SecurityUtils.safeExistsSync(cfg.sourceDir, projectRoot)) {
|
|
114
120
|
await configManager.updateConfig({ i18nDir: configManager.toRelative(cfg.sourceDir) });
|
|
115
121
|
cfg.i18nDir = cfg.sourceDir;
|
|
116
122
|
}
|
|
@@ -414,8 +420,8 @@ function ensureDirectory(dirPath) {
|
|
|
414
420
|
// Silently handle undefined or invalid paths to prevent security errors
|
|
415
421
|
return;
|
|
416
422
|
}
|
|
417
|
-
if (!SecurityUtils.safeExistsSync(dirPath)) {
|
|
418
|
-
|
|
423
|
+
if (!SecurityUtils.safeExistsSync(dirPath, process.cwd())) {
|
|
424
|
+
SecurityUtils.safeMkdirSync(dirPath, process.cwd(), { recursive: true });
|
|
419
425
|
}
|
|
420
426
|
}
|
|
421
427
|
|
|
@@ -499,49 +505,49 @@ async function initializeSourceFiles(sourceDir, sourceLang) {
|
|
|
499
505
|
ensureDirectory(sourceDir);
|
|
500
506
|
|
|
501
507
|
// Write the default source language file
|
|
502
|
-
SecurityUtils.safeWriteFileSync(sourceFile, JSON.stringify(defaultContent, null, 2));
|
|
508
|
+
SecurityUtils.safeWriteFileSync(sourceFile, JSON.stringify(defaultContent, null, 2), sourceDir, 'utf8');
|
|
503
509
|
|
|
504
510
|
// Create directories for supported languages
|
|
505
511
|
const supportedLanguages = ['es', 'fr', 'de', 'ja', 'ru', 'zh', 'pt'];
|
|
506
512
|
|
|
507
513
|
supportedLanguages.forEach(lang => {
|
|
508
514
|
const langFile = path.join(sourceDir, `${lang}.json`);
|
|
509
|
-
if (!SecurityUtils.safeExistsSync(langFile)) {
|
|
515
|
+
if (!SecurityUtils.safeExistsSync(langFile, sourceDir)) {
|
|
510
516
|
// Create empty object structure for each language
|
|
511
517
|
const emptyStructure = {
|
|
512
518
|
app: {},
|
|
513
519
|
common: {},
|
|
514
520
|
navigation: {}
|
|
515
521
|
};
|
|
516
|
-
SecurityUtils.safeWriteFileSync(langFile, JSON.stringify(emptyStructure, null, 2));
|
|
522
|
+
SecurityUtils.safeWriteFileSync(langFile, JSON.stringify(emptyStructure, null, 2), sourceDir, 'utf8');
|
|
517
523
|
}
|
|
518
524
|
});
|
|
519
525
|
|
|
520
|
-
// Create v2 project config if it doesn't exist
|
|
521
|
-
const configFile = '.i18ntk-config';
|
|
522
|
-
if (!SecurityUtils.safeExistsSync(configFile)) {
|
|
523
|
-
const version = (() => {
|
|
524
|
-
try {
|
|
525
|
-
return require('../package.json').version;
|
|
526
|
-
} catch {
|
|
527
|
-
return '2.0.0';
|
|
528
|
-
}
|
|
529
|
-
})();
|
|
530
|
-
const defaultConfig = {
|
|
531
|
-
version,
|
|
532
|
-
sourceDir: sourceDir,
|
|
533
|
-
outputDir: "./i18ntk-reports",
|
|
534
|
-
defaultLanguage: sourceLang,
|
|
535
|
-
supportedLanguages: [sourceLang, 'es', 'fr', 'de', 'ja', 'ru', 'zh', 'pt'],
|
|
536
|
-
setup: {
|
|
537
|
-
completed: true,
|
|
538
|
-
completedAt: new Date().toISOString(),
|
|
539
|
-
version,
|
|
540
|
-
setupId: `setup_${Date.now()}`
|
|
541
|
-
},
|
|
542
|
-
security: {
|
|
543
|
-
adminPinEnabled: true,
|
|
544
|
-
sessionTimeout: 1800000,
|
|
526
|
+
// Create v2 project config if it doesn't exist
|
|
527
|
+
const configFile = '.i18ntk-config';
|
|
528
|
+
if (!SecurityUtils.safeExistsSync(configFile, process.cwd())) {
|
|
529
|
+
const version = (() => {
|
|
530
|
+
try {
|
|
531
|
+
return require('../package.json').version;
|
|
532
|
+
} catch {
|
|
533
|
+
return '2.0.0';
|
|
534
|
+
}
|
|
535
|
+
})();
|
|
536
|
+
const defaultConfig = {
|
|
537
|
+
version,
|
|
538
|
+
sourceDir: sourceDir,
|
|
539
|
+
outputDir: "./i18ntk-reports",
|
|
540
|
+
defaultLanguage: sourceLang,
|
|
541
|
+
supportedLanguages: [sourceLang, 'es', 'fr', 'de', 'ja', 'ru', 'zh', 'pt'],
|
|
542
|
+
setup: {
|
|
543
|
+
completed: true,
|
|
544
|
+
completedAt: new Date().toISOString(),
|
|
545
|
+
version,
|
|
546
|
+
setupId: `setup_${Date.now()}`
|
|
547
|
+
},
|
|
548
|
+
security: {
|
|
549
|
+
adminPinEnabled: true,
|
|
550
|
+
sessionTimeout: 1800000,
|
|
545
551
|
maxFailedAttempts: 3
|
|
546
552
|
},
|
|
547
553
|
performance: {
|
|
@@ -550,8 +556,8 @@ async function initializeSourceFiles(sourceDir, sourceLang) {
|
|
|
550
556
|
batchSize: 1000
|
|
551
557
|
}
|
|
552
558
|
};
|
|
553
|
-
SecurityUtils.safeWriteFileSync(configFile, JSON.stringify(defaultConfig, null, 2));
|
|
554
|
-
}
|
|
559
|
+
SecurityUtils.safeWriteFileSync(configFile, JSON.stringify(defaultConfig, null, 2), process.cwd(), 'utf8');
|
|
560
|
+
}
|
|
555
561
|
}
|
|
556
562
|
|
|
557
563
|
|