@magmonium/cli 0.7.8
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 +392 -0
- package/bin/README.md +244 -0
- package/bin/cli.js +55 -0
- package/bin/commands/assets-wc.js +249 -0
- package/bin/commands/assets.js +943 -0
- package/bin/commands/build.js +242 -0
- package/bin/commands/clean.js +621 -0
- package/bin/commands/compile-i18n.js +91 -0
- package/bin/commands/config-ci.js +266 -0
- package/bin/commands/configure-wc.js +167 -0
- package/bin/commands/connect.js +188 -0
- package/bin/commands/create-app.js +946 -0
- package/bin/commands/deploy.js +100 -0
- package/bin/commands/fix-i18n.js +40 -0
- package/bin/commands/generate.js +765 -0
- package/bin/commands/init/config-files.js +1114 -0
- package/bin/commands/init/mag-assets.js +541 -0
- package/bin/commands/init/mag-cli-config.js +120 -0
- package/bin/commands/init/monorepo-structure.js +735 -0
- package/bin/commands/init/package-json.js +308 -0
- package/bin/commands/init/project-structure.js +189 -0
- package/bin/commands/init/pwa-files.js +204 -0
- package/bin/commands/init/source-files.js +2596 -0
- package/bin/commands/init.js +591 -0
- package/bin/commands/lib.js +508 -0
- package/bin/commands/patch-wc-env.js +136 -0
- package/bin/commands/refractor.js +51 -0
- package/bin/commands/sanitize-i18n.js +41 -0
- package/bin/commands/translate.js +32 -0
- package/bin/commands/zip.js +540 -0
- package/package.json +53 -0
- package/src/compilers/button-group-compiler.d.ts +18 -0
- package/src/compilers/button-group-compiler.d.ts.map +1 -0
- package/src/compilers/button-group-compiler.js +151 -0
- package/src/compilers/button-group-compiler.js.map +1 -0
- package/src/compilers/copy-compiler.d.ts +14 -0
- package/src/compilers/copy-compiler.d.ts.map +1 -0
- package/src/compilers/copy-compiler.js +170 -0
- package/src/compilers/copy-compiler.js.map +1 -0
- package/src/compilers/field-compiler.d.ts +15 -0
- package/src/compilers/field-compiler.d.ts.map +1 -0
- package/src/compilers/field-compiler.js +153 -0
- package/src/compilers/field-compiler.js.map +1 -0
- package/src/compilers/form-compiler.d.ts +15 -0
- package/src/compilers/form-compiler.d.ts.map +1 -0
- package/src/compilers/form-compiler.js +220 -0
- package/src/compilers/form-compiler.js.map +1 -0
- package/src/compilers/logo-compiler.d.ts +14 -0
- package/src/compilers/logo-compiler.d.ts.map +1 -0
- package/src/compilers/logo-compiler.js +114 -0
- package/src/compilers/logo-compiler.js.map +1 -0
- package/src/compilers/options-compiler.d.ts +46 -0
- package/src/compilers/options-compiler.d.ts.map +1 -0
- package/src/compilers/options-compiler.js +329 -0
- package/src/compilers/options-compiler.js.map +1 -0
- package/src/compilers/pwa-build.d.ts +7 -0
- package/src/compilers/pwa-build.d.ts.map +1 -0
- package/src/compilers/pwa-build.js +62 -0
- package/src/compilers/pwa-build.js.map +1 -0
- package/src/compilers/svg-compiler.d.ts +12 -0
- package/src/compilers/svg-compiler.d.ts.map +1 -0
- package/src/compilers/svg-compiler.js +123 -0
- package/src/compilers/svg-compiler.js.map +1 -0
- package/src/compilers/tabs-compiler.d.ts +25 -0
- package/src/compilers/tabs-compiler.d.ts.map +1 -0
- package/src/compilers/tabs-compiler.js +422 -0
- package/src/compilers/tabs-compiler.js.map +1 -0
- package/src/compilers/theme-compiler.d.ts +14 -0
- package/src/compilers/theme-compiler.d.ts.map +1 -0
- package/src/compilers/theme-compiler.js +144 -0
- package/src/compilers/theme-compiler.js.map +1 -0
- package/src/compilers/translation-compiler.d.ts +17 -0
- package/src/compilers/translation-compiler.d.ts.map +1 -0
- package/src/compilers/translation-compiler.js +232 -0
- package/src/compilers/translation-compiler.js.map +1 -0
- package/src/compilers/web-component/index.d.ts +3 -0
- package/src/compilers/web-component/index.d.ts.map +1 -0
- package/src/compilers/web-component/index.js +6 -0
- package/src/compilers/web-component/index.js.map +1 -0
- package/src/compilers/web-component/lib/builder.d.ts +45 -0
- package/src/compilers/web-component/lib/builder.d.ts.map +1 -0
- package/src/compilers/web-component/lib/builder.js +341 -0
- package/src/compilers/web-component/lib/builder.js.map +1 -0
- package/src/compilers/web-component/lib/class-name.d.ts +4 -0
- package/src/compilers/web-component/lib/class-name.d.ts.map +1 -0
- package/src/compilers/web-component/lib/class-name.js +24 -0
- package/src/compilers/web-component/lib/class-name.js.map +1 -0
- package/src/compilers/web-component/lib/config-data.d.ts +9 -0
- package/src/compilers/web-component/lib/config-data.d.ts.map +1 -0
- package/src/compilers/web-component/lib/config-data.js +14 -0
- package/src/compilers/web-component/lib/config-data.js.map +1 -0
- package/src/compilers/web-component/lib/ng-build.d.ts +8 -0
- package/src/compilers/web-component/lib/ng-build.d.ts.map +1 -0
- package/src/compilers/web-component/lib/ng-build.js +685 -0
- package/src/compilers/web-component/lib/ng-build.js.map +1 -0
- package/src/compilers/web-component/lib/resource-inliner.d.ts +9 -0
- package/src/compilers/web-component/lib/resource-inliner.d.ts.map +1 -0
- package/src/compilers/web-component/lib/resource-inliner.js +355 -0
- package/src/compilers/web-component/lib/resource-inliner.js.map +1 -0
- package/src/compilers/web-component/lib/web-component-name.d.ts +3 -0
- package/src/compilers/web-component/lib/web-component-name.d.ts.map +1 -0
- package/src/compilers/web-component/lib/web-component-name.js +47 -0
- package/src/compilers/web-component/lib/web-component-name.js.map +1 -0
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts +3 -0
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts.map +1 -0
- package/src/compilers/web-component/lib/web-component-wrapper.js +335 -0
- package/src/compilers/web-component/lib/web-component-wrapper.js.map +1 -0
- package/src/compilers/web-component/model/type.d.ts +29 -0
- package/src/compilers/web-component/model/type.d.ts.map +1 -0
- package/src/compilers/web-component/model/type.js +3 -0
- package/src/compilers/web-component/model/type.js.map +1 -0
- package/src/compilers/worker-compiler.d.ts +12 -0
- package/src/compilers/worker-compiler.d.ts.map +1 -0
- package/src/compilers/worker-compiler.js +123 -0
- package/src/compilers/worker-compiler.js.map +1 -0
- package/src/compilers/yaml-compiler.d.ts +18 -0
- package/src/compilers/yaml-compiler.d.ts.map +1 -0
- package/src/compilers/yaml-compiler.js +139 -0
- package/src/compilers/yaml-compiler.js.map +1 -0
- package/src/core/base-compiler.d.ts +17 -0
- package/src/core/base-compiler.d.ts.map +1 -0
- package/src/core/base-compiler.js +78 -0
- package/src/core/base-compiler.js.map +1 -0
- package/src/core/config.d.ts +640 -0
- package/src/core/config.d.ts.map +1 -0
- package/src/core/config.js +432 -0
- package/src/core/config.js.map +1 -0
- package/src/core/file-watcher.d.ts +23 -0
- package/src/core/file-watcher.d.ts.map +1 -0
- package/src/core/file-watcher.js +63 -0
- package/src/core/file-watcher.js.map +1 -0
- package/src/index.d.ts +31 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +34 -0
- package/src/index.js.map +1 -0
- package/src/types/asset-configs.d.ts +189 -0
- package/src/types/asset-configs.d.ts.map +1 -0
- package/src/types/asset-configs.js +7 -0
- package/src/types/asset-configs.js.map +1 -0
- package/src/types/theme.d.ts +67 -0
- package/src/types/theme.d.ts.map +1 -0
- package/src/types/theme.js +3 -0
- package/src/types/theme.js.map +1 -0
- package/src/utils/file-utils.d.ts +16 -0
- package/src/utils/file-utils.d.ts.map +1 -0
- package/src/utils/file-utils.js +58 -0
- package/src/utils/file-utils.js.map +1 -0
- package/src/utils/i18n-compile-validator.d.ts +20 -0
- package/src/utils/i18n-compile-validator.d.ts.map +1 -0
- package/src/utils/i18n-compile-validator.js +198 -0
- package/src/utils/i18n-compile-validator.js.map +1 -0
- package/src/utils/i18n-fixer.d.ts +39 -0
- package/src/utils/i18n-fixer.d.ts.map +1 -0
- package/src/utils/i18n-fixer.js +396 -0
- package/src/utils/i18n-fixer.js.map +1 -0
- package/src/utils/i18n-sanitizer.d.ts +17 -0
- package/src/utils/i18n-sanitizer.d.ts.map +1 -0
- package/src/utils/i18n-sanitizer.js +101 -0
- package/src/utils/i18n-sanitizer.js.map +1 -0
- package/src/utils/i18n-utils.d.ts +21 -0
- package/src/utils/i18n-utils.d.ts.map +1 -0
- package/src/utils/i18n-utils.js +89 -0
- package/src/utils/i18n-utils.js.map +1 -0
- package/src/utils/interactive-translator.d.ts +18 -0
- package/src/utils/interactive-translator.d.ts.map +1 -0
- package/src/utils/interactive-translator.js +401 -0
- package/src/utils/interactive-translator.js.map +1 -0
- package/src/utils/llama-cpp-translator.d.ts +33 -0
- package/src/utils/llama-cpp-translator.d.ts.map +1 -0
- package/src/utils/llama-cpp-translator.js +267 -0
- package/src/utils/llama-cpp-translator.js.map +1 -0
- package/src/utils/logger.d.ts +14 -0
- package/src/utils/logger.d.ts.map +1 -0
- package/src/utils/logger.js +42 -0
- package/src/utils/logger.js.map +1 -0
- package/src/utils/ollama-translator.d.ts +38 -0
- package/src/utils/ollama-translator.d.ts.map +1 -0
- package/src/utils/ollama-translator.js +371 -0
- package/src/utils/ollama-translator.js.map +1 -0
- package/src/utils/option-utils.d.ts +58 -0
- package/src/utils/option-utils.d.ts.map +1 -0
- package/src/utils/option-utils.js +123 -0
- package/src/utils/option-utils.js.map +1 -0
- package/src/utils/platform-utils.d.ts +33 -0
- package/src/utils/platform-utils.d.ts.map +1 -0
- package/src/utils/platform-utils.js +114 -0
- package/src/utils/platform-utils.js.map +1 -0
- package/src/utils/pwa-utils.d.ts +28 -0
- package/src/utils/pwa-utils.d.ts.map +1 -0
- package/src/utils/pwa-utils.js +48 -0
- package/src/utils/pwa-utils.js.map +1 -0
- package/src/utils/translation-manager.d.ts +43 -0
- package/src/utils/translation-manager.d.ts.map +1 -0
- package/src/utils/translation-manager.js +302 -0
- package/src/utils/translation-manager.js.map +1 -0
- package/src/utils/web-translation-providers.d.ts +53 -0
- package/src/utils/web-translation-providers.d.ts.map +1 -0
- package/src/utils/web-translation-providers.js +190 -0
- package/src/utils/web-translation-providers.js.map +1 -0
- package/src/utils/yaml-utils.d.ts +9 -0
- package/src/utils/yaml-utils.d.ts.map +1 -0
- package/src/utils/yaml-utils.js +26 -0
- package/src/utils/yaml-utils.js.map +1 -0
- package/templates/mag-compile.config.js +77 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.I18nFixer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const logger_1 = require("./logger");
|
|
8
|
+
const web_translation_providers_1 = require("./web-translation-providers");
|
|
9
|
+
async function runConcurrent(tasks, limit) {
|
|
10
|
+
const results = new Array(tasks.length);
|
|
11
|
+
let idx = 0;
|
|
12
|
+
async function worker() {
|
|
13
|
+
while (idx < tasks.length) {
|
|
14
|
+
const i = idx++;
|
|
15
|
+
results[i] = await tasks[i]();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
await Promise.all(Array.from({ length: Math.min(limit, tasks.length) }, worker));
|
|
19
|
+
return results;
|
|
20
|
+
}
|
|
21
|
+
function snakeCaseToTitle(key) {
|
|
22
|
+
return key
|
|
23
|
+
.split('_')
|
|
24
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
25
|
+
.join(' ');
|
|
26
|
+
}
|
|
27
|
+
function parseYaml(content) {
|
|
28
|
+
const result = {};
|
|
29
|
+
for (const line of content.split('\n')) {
|
|
30
|
+
const match = line.match(/^([a-z]{2,3}):\s*(.+)$/);
|
|
31
|
+
if (match)
|
|
32
|
+
result[match[1]] = match[2].trim();
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
class I18nFixer {
|
|
37
|
+
constructor(workspaceRoot, verbose = false) {
|
|
38
|
+
this.referenceLanguages = null;
|
|
39
|
+
this.workspaceRoot = workspaceRoot;
|
|
40
|
+
this.logger = new logger_1.Logger(verbose);
|
|
41
|
+
}
|
|
42
|
+
// ── Reference language list ───────────────────────────────────────────────
|
|
43
|
+
// Find the MOST COMPLETE YAML in the workspace — that defines the full lang set.
|
|
44
|
+
async getReferenceLanguages(_appName) {
|
|
45
|
+
if (this.referenceLanguages)
|
|
46
|
+
return this.referenceLanguages;
|
|
47
|
+
const langFile = path_1.default.join(this.workspaceRoot, 'libs', 'cli', 'mag_assets', 'i18n', 'lang.yml');
|
|
48
|
+
if (await this.pathExists(langFile)) {
|
|
49
|
+
const content = await fs_1.promises.readFile(langFile, 'utf-8');
|
|
50
|
+
// Parse indented lang codes under `langs:` block: " en: 'English'"
|
|
51
|
+
const langs = (content.match(/^\s{2}([a-z]{2,3}):/gm) ?? [])
|
|
52
|
+
.map((l) => l.trim().replace(':', ''));
|
|
53
|
+
if (langs.length > 0) {
|
|
54
|
+
this.referenceLanguages = langs;
|
|
55
|
+
this.logger.info(`Reference language set: ${langs.length} languages (from lang.yml)`);
|
|
56
|
+
return langs;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
this.logger.warn('lang.yml not found — falling back to largest existing YAML');
|
|
60
|
+
this.referenceLanguages = ['en'];
|
|
61
|
+
return this.referenceLanguages;
|
|
62
|
+
}
|
|
63
|
+
// ── Scan ──────────────────────────────────────────────────────────────────
|
|
64
|
+
async scan() {
|
|
65
|
+
this.logger.info('Scanning templates, TypeScript, and all mag_assets/i18n YAML files...');
|
|
66
|
+
const keyToApps = new Map();
|
|
67
|
+
const appDirs = await this.getAppDirs();
|
|
68
|
+
// Source 1: keys used in templates / TS
|
|
69
|
+
for (const appName of appDirs) {
|
|
70
|
+
const srcDir = path_1.default.join(this.workspaceRoot, 'apps', appName, 'src');
|
|
71
|
+
if (!(await this.pathExists(srcDir)))
|
|
72
|
+
continue;
|
|
73
|
+
const keys = await this.extractKeysFromDir(srcDir);
|
|
74
|
+
for (const key of keys) {
|
|
75
|
+
if (!keyToApps.has(key))
|
|
76
|
+
keyToApps.set(key, new Set());
|
|
77
|
+
keyToApps.get(key)?.add(appName);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Source 2: ALL existing YAML files in every mag_assets/i18n dir
|
|
81
|
+
const i18nRoots = [
|
|
82
|
+
path_1.default.join(this.workspaceRoot, 'libs', 'one', 'mag_assets', 'i18n'),
|
|
83
|
+
...appDirs.map((a) => path_1.default.join(this.workspaceRoot, 'apps', a, 'mag_assets', 'i18n')),
|
|
84
|
+
];
|
|
85
|
+
for (let i = 0; i < i18nRoots.length; i++) {
|
|
86
|
+
const dir = i18nRoots[i];
|
|
87
|
+
const appName = i === 0 ? null : appDirs[i - 1];
|
|
88
|
+
const ymls = await this.walkFiles(dir, ['.yml', '.yaml']);
|
|
89
|
+
for (const yml of ymls) {
|
|
90
|
+
const key = path_1.default.basename(yml, path_1.default.extname(yml));
|
|
91
|
+
if (!keyToApps.has(key))
|
|
92
|
+
keyToApps.set(key, new Set());
|
|
93
|
+
if (appName)
|
|
94
|
+
keyToApps.get(key)?.add(appName);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const refApp = appDirs[0];
|
|
98
|
+
const refLangs = await this.getReferenceLanguages(refApp);
|
|
99
|
+
const incomplete = [];
|
|
100
|
+
for (const [key, appsSet] of keyToApps) {
|
|
101
|
+
const apps = Array.from(appsSet);
|
|
102
|
+
const existingFile = await this.findExistingYaml(key, apps);
|
|
103
|
+
const existingLangs = existingFile ? parseYaml(await fs_1.promises.readFile(existingFile, 'utf-8')) : {};
|
|
104
|
+
const existingLangCodes = new Set(Object.keys(existingLangs));
|
|
105
|
+
const missingLangs = refLangs.filter((l) => !existingLangCodes.has(l));
|
|
106
|
+
if (missingLangs.length > 0) {
|
|
107
|
+
incomplete.push({ key, apps, existingFile, existingLangs, missingLangs });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const newFiles = incomplete.filter((k) => k.existingFile === null).length;
|
|
111
|
+
const partial = incomplete.filter((k) => k.existingFile !== null).length;
|
|
112
|
+
this.logger.info(`Found ${incomplete.length} key(s) needing work: ${newFiles} missing files, ${partial} incomplete`);
|
|
113
|
+
return incomplete;
|
|
114
|
+
}
|
|
115
|
+
async getAppDirs() {
|
|
116
|
+
const appsDir = path_1.default.join(this.workspaceRoot, 'apps');
|
|
117
|
+
try {
|
|
118
|
+
const entries = await fs_1.promises.readdir(appsDir);
|
|
119
|
+
const result = [];
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
try {
|
|
122
|
+
const stats = await fs_1.promises.lstat(path_1.default.join(appsDir, entry));
|
|
123
|
+
if (stats.isDirectory() && entry.startsWith('m-') && !entry.endsWith('-e2e')) {
|
|
124
|
+
result.push(entry);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// ignore error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return ['m-ui', 'm-comics', 'm-finance', 'm-radio', 'm-wallet'];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async extractKeysFromDir(dir) {
|
|
138
|
+
const keys = new Set();
|
|
139
|
+
const files = await this.walkFiles(dir, ['.html', '.ts']);
|
|
140
|
+
for (const file of files) {
|
|
141
|
+
const content = await fs_1.promises.readFile(file, 'utf-8');
|
|
142
|
+
const fileKeys = file.endsWith('.html')
|
|
143
|
+
? this.extractFromTemplate(content)
|
|
144
|
+
: this.extractFromTs(content);
|
|
145
|
+
fileKeys.forEach((k) => keys.add(k));
|
|
146
|
+
}
|
|
147
|
+
return keys;
|
|
148
|
+
}
|
|
149
|
+
extractFromTemplate(content) {
|
|
150
|
+
const matches = content.matchAll(/['"]([a-z][a-z0-9_-]*)['"][\s]*\|[\s]*translate/g);
|
|
151
|
+
return Array.from(matches, (m) => m[1]);
|
|
152
|
+
}
|
|
153
|
+
extractFromTs(content) {
|
|
154
|
+
const matches = content.matchAll(/\.translate\(['"]([a-z][a-z0-9_-]*)['"]\)/g);
|
|
155
|
+
return Array.from(matches, (m) => m[1]);
|
|
156
|
+
}
|
|
157
|
+
async findExistingYaml(key, apps) {
|
|
158
|
+
const first = key[0].toLowerCase();
|
|
159
|
+
const candidates = [
|
|
160
|
+
path_1.default.join(this.workspaceRoot, 'libs', 'one', 'mag_assets', 'i18n', first, `${key}.yml`),
|
|
161
|
+
...apps.map((app) => path_1.default.join(this.workspaceRoot, 'apps', app, 'mag_assets', 'i18n', first, `${key}.yml`)),
|
|
162
|
+
];
|
|
163
|
+
for (const p of candidates) {
|
|
164
|
+
if (await this.pathExists(p))
|
|
165
|
+
return p;
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
// ── Fix ───────────────────────────────────────────────────────────────────
|
|
170
|
+
async fix(options = {}) {
|
|
171
|
+
const { dryRun = false } = options;
|
|
172
|
+
const pool = new web_translation_providers_1.ProviderPool({ verbose: options.verbose });
|
|
173
|
+
// Auto-detect llama-server — no flag required
|
|
174
|
+
const ollama = await web_translation_providers_1.LlamaCppProvider.create(options.llamaHost);
|
|
175
|
+
if (ollama) {
|
|
176
|
+
this.logger.info('llama-server available — will handle non-mainstream languages and web API failures');
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.logger.info('llama-server not available — using web APIs only');
|
|
180
|
+
}
|
|
181
|
+
const results = [];
|
|
182
|
+
const allIncomplete = await this.scan();
|
|
183
|
+
if (allIncomplete.length === 0) {
|
|
184
|
+
this.logger.success('All i18n keys have complete translations — nothing to do.');
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
if (dryRun) {
|
|
188
|
+
this.logger.info(`\n[dry-run] Would process ${allIncomplete.length} key(s):`);
|
|
189
|
+
for (const { key, existingFile, missingLangs } of allIncomplete) {
|
|
190
|
+
this.logger.info(` ${existingFile ? '~' : '+'} ${key}: ${missingLangs.length} lang(s) missing`);
|
|
191
|
+
}
|
|
192
|
+
await this.cleanupStaleCopies(true);
|
|
193
|
+
return allIncomplete.map(({ key, apps, existingFile, missingLangs }) => ({
|
|
194
|
+
key,
|
|
195
|
+
targetPath: existingFile ?? (apps.length > 0
|
|
196
|
+
? path_1.default.join(this.workspaceRoot, 'apps', apps[0], 'mag_assets', 'i18n', key[0], `${key}.yml`)
|
|
197
|
+
: path_1.default.join(this.workspaceRoot, 'libs', 'one', 'mag_assets', 'i18n', key[0], `${key}.yml`)),
|
|
198
|
+
langsWritten: missingLangs.length,
|
|
199
|
+
langsSkipped: 0,
|
|
200
|
+
deletedFrom: [],
|
|
201
|
+
dryRun: true,
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
const incomplete = options.limit ? allIncomplete.slice(0, options.limit) : allIncomplete;
|
|
205
|
+
if (options.limit && allIncomplete.length > options.limit) {
|
|
206
|
+
this.logger.warn(`Processing ${options.limit} of ${allIncomplete.length} keys (--limit applied). Re-run to continue.`);
|
|
207
|
+
}
|
|
208
|
+
for (const { key, apps, existingFile, existingLangs, missingLangs } of incomplete) {
|
|
209
|
+
this.logger.info(`\n[${key}] ${existingFile ? 'incomplete' : 'missing'} — need ${missingLangs.length} lang(s)`);
|
|
210
|
+
const sourceText = existingLangs['en'] ?? snakeCaseToTitle(key);
|
|
211
|
+
const newTranslations = {};
|
|
212
|
+
let skipped = 0;
|
|
213
|
+
// Handle 'en' trivially
|
|
214
|
+
if (missingLangs.includes('en'))
|
|
215
|
+
newTranslations['en'] = sourceText;
|
|
216
|
+
const langs = missingLangs.filter((l) => l !== 'en');
|
|
217
|
+
// ── Web first for ALL langs (concurrency 5) ──────────────────────────
|
|
218
|
+
// MyMemory handles mainstream; Google unofficial handles the rest (zh, co,
|
|
219
|
+
// eo, fy, br, rm, sc, lo, lb, mi, sm, sn, yo, ceb, ny, jw, ilo, …).
|
|
220
|
+
// Only langs that web genuinely cannot translate fall through to Ollama.
|
|
221
|
+
const WEB_CONCURRENCY = 5;
|
|
222
|
+
const webFailed = [];
|
|
223
|
+
if (langs.length > 0) {
|
|
224
|
+
const tasks = langs.map((lang) => () => pool.translate(sourceText, 'en', lang).then((r) => ({ lang, result: r })));
|
|
225
|
+
const webResults = await runConcurrent(tasks, WEB_CONCURRENCY);
|
|
226
|
+
for (const { lang, result } of webResults) {
|
|
227
|
+
if (result) {
|
|
228
|
+
newTranslations[lang] = result;
|
|
229
|
+
if (options.verbose)
|
|
230
|
+
this.logger.debug(` ${lang} [web]: ${result}`);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
webFailed.push(lang);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// ── llama-cpp: only truly web-failed langs ──────────────────────────
|
|
238
|
+
// Batch mode sends all target langs in one JSON prompt — far better than
|
|
239
|
+
// single-lang calls for Unicode scripts (hi, bn, ta…) and minority codes.
|
|
240
|
+
if (webFailed.length > 0) {
|
|
241
|
+
if (!ollama) {
|
|
242
|
+
skipped += webFailed.length;
|
|
243
|
+
if (options.verbose)
|
|
244
|
+
this.logger.warn(` ${webFailed.join(', ')}: skipped (llama-server unavailable)`);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const batchResults = await ollama.translateBatch(sourceText, 'en', webFailed);
|
|
248
|
+
for (const lang of webFailed) {
|
|
249
|
+
if (batchResults[lang]) {
|
|
250
|
+
newTranslations[lang] = batchResults[lang];
|
|
251
|
+
if (options.verbose)
|
|
252
|
+
this.logger.debug(` ${lang} [llama-cpp-batch]: ${batchResults[lang]}`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
skipped++;
|
|
256
|
+
if (options.verbose)
|
|
257
|
+
this.logger.warn(` ${lang}: skipped`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Merge existing + new, sorted
|
|
263
|
+
const merged = { ...existingLangs, ...newTranslations };
|
|
264
|
+
const yamlContent = Object.keys(merged)
|
|
265
|
+
.sort()
|
|
266
|
+
.map((lang) => `${lang}: ${merged[lang]}`)
|
|
267
|
+
.join('\n');
|
|
268
|
+
// Determine target path
|
|
269
|
+
const isShared = apps.length === 0 || apps.length > 1;
|
|
270
|
+
const targetDir = isShared
|
|
271
|
+
? path_1.default.join(this.workspaceRoot, 'libs', 'one', 'mag_assets', 'i18n', key[0])
|
|
272
|
+
: existingFile
|
|
273
|
+
? path_1.default.dirname(existingFile)
|
|
274
|
+
: path_1.default.join(this.workspaceRoot, 'apps', apps[0], 'mag_assets', 'i18n', key[0]);
|
|
275
|
+
const targetFile = path_1.default.join(targetDir, `${key}.yml`);
|
|
276
|
+
// If moving to shared, delete individual app copies
|
|
277
|
+
const deletedFrom = [];
|
|
278
|
+
if (isShared) {
|
|
279
|
+
for (const app of apps) {
|
|
280
|
+
const appFile = path_1.default.join(this.workspaceRoot, 'apps', app, 'mag_assets', 'i18n', key[0], `${key}.yml`);
|
|
281
|
+
if (await this.pathExists(appFile) && appFile !== targetFile) {
|
|
282
|
+
deletedFrom.push(appFile);
|
|
283
|
+
if (!dryRun) {
|
|
284
|
+
try {
|
|
285
|
+
await fs_1.promises.unlink(appFile);
|
|
286
|
+
this.logger.warn(`${dryRun ? '[dry-run] Would delete' : 'Deleted'}: ${appFile}`);
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
this.logger.warn(`Could not delete stale copy: ${appFile} (${err.message})`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (!dryRun) {
|
|
296
|
+
await fs_1.promises.mkdir(targetDir, { recursive: true });
|
|
297
|
+
await fs_1.promises.writeFile(targetFile, yamlContent, 'utf-8');
|
|
298
|
+
}
|
|
299
|
+
this.logger.success(`${dryRun ? '[dry-run] Would write' : 'Written'}: ${targetFile} (+${Object.keys(newTranslations).length} langs, ${skipped} skipped)`);
|
|
300
|
+
results.push({
|
|
301
|
+
key,
|
|
302
|
+
targetPath: targetFile,
|
|
303
|
+
langsWritten: Object.keys(newTranslations).length,
|
|
304
|
+
langsSkipped: skipped,
|
|
305
|
+
deletedFrom,
|
|
306
|
+
dryRun,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
const status = pool.getStatus();
|
|
310
|
+
if (status.rateLimited.length > 0) {
|
|
311
|
+
this.logger.warn(`Rate-limited providers: ${status.rateLimited.join(', ')}`);
|
|
312
|
+
}
|
|
313
|
+
// ── Cleanup: delete stale app copies that duplicate a complete libs/one file ──
|
|
314
|
+
// When a key's canonical file lives in libs/one (complete), any app-specific
|
|
315
|
+
// copy is stale. The scan misses these because the canonical is already complete.
|
|
316
|
+
await this.cleanupStaleCopies(dryRun);
|
|
317
|
+
return results;
|
|
318
|
+
}
|
|
319
|
+
async cleanupStaleCopies(dryRun) {
|
|
320
|
+
const appDirs = await this.getAppDirs();
|
|
321
|
+
const refLangs = await this.getReferenceLanguages(appDirs[0] ?? '');
|
|
322
|
+
const threshold = 0.75; // matches lint rule threshold
|
|
323
|
+
const libsI18nDir = path_1.default.join(this.workspaceRoot, 'libs', 'one', 'mag_assets', 'i18n');
|
|
324
|
+
const libsFiles = await this.walkFiles(libsI18nDir, ['.yml', '.yaml']);
|
|
325
|
+
for (const libsFile of libsFiles) {
|
|
326
|
+
const key = path_1.default.basename(libsFile, path_1.default.extname(libsFile));
|
|
327
|
+
if (key === 'lang')
|
|
328
|
+
continue;
|
|
329
|
+
let content;
|
|
330
|
+
try {
|
|
331
|
+
content = await fs_1.promises.readFile(libsFile, 'utf-8');
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const presentCount = (content.match(/^[a-z]{2,3}:/gm) ?? []).length;
|
|
337
|
+
if (presentCount / refLangs.length < (1 - threshold))
|
|
338
|
+
continue; // libs/one copy too incomplete — skip
|
|
339
|
+
for (const app of appDirs) {
|
|
340
|
+
const appFile = path_1.default.join(this.workspaceRoot, 'apps', app, 'mag_assets', 'i18n', key[0], `${key}.yml`);
|
|
341
|
+
if (await this.pathExists(appFile)) {
|
|
342
|
+
if (!dryRun) {
|
|
343
|
+
try {
|
|
344
|
+
await fs_1.promises.unlink(appFile);
|
|
345
|
+
this.logger.warn(`${dryRun ? '[dry-run] Would delete' : 'Deleted'} stale copy: ${appFile}`);
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
this.logger.warn(`Could not delete stale copy: ${appFile} (${err.message})`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
this.logger.warn(`[dry-run] Would delete stale copy: ${appFile}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
// ── Utils ─────────────────────────────────────────────────────────────────
|
|
359
|
+
async pathExists(p) {
|
|
360
|
+
try {
|
|
361
|
+
await fs_1.promises.access(p);
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async walkFiles(dir, exts) {
|
|
369
|
+
const result = [];
|
|
370
|
+
let entries;
|
|
371
|
+
try {
|
|
372
|
+
entries = await fs_1.promises.readdir(dir);
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
for (const entry of entries) {
|
|
378
|
+
const full = path_1.default.join(dir, entry);
|
|
379
|
+
try {
|
|
380
|
+
const stat = await fs_1.promises.lstat(full);
|
|
381
|
+
if (stat.isDirectory()) {
|
|
382
|
+
result.push(...(await this.walkFiles(full, exts)));
|
|
383
|
+
}
|
|
384
|
+
else if (exts.some((e) => entry.endsWith(e))) {
|
|
385
|
+
result.push(full);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
// ignore error
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
exports.I18nFixer = I18nFixer;
|
|
396
|
+
//# sourceMappingURL=i18n-fixer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-fixer.js","sourceRoot":"","sources":["../../../../../libs/cli/src/utils/i18n-fixer.ts"],"names":[],"mappings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C5B,IAAI,OAAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACnC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,aAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAClC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;oBACvB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;gBACrD,CAAC;qBAAM,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,eAAe;YACjB,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5YD,8BA4YC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface SanitizeResult {
|
|
2
|
+
file: string;
|
|
3
|
+
fixed: boolean;
|
|
4
|
+
linesChanged: number;
|
|
5
|
+
unfixable: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class I18nSanitizer {
|
|
9
|
+
private readonly logger;
|
|
10
|
+
constructor(verbose?: boolean);
|
|
11
|
+
sanitizeAll(roots: string[], dryRun?: boolean): Promise<SanitizeResult[]>;
|
|
12
|
+
sanitizeFile(filePath: string, dryRun?: boolean): Promise<SanitizeResult>;
|
|
13
|
+
private sanitizeLine;
|
|
14
|
+
private walkYamlFiles;
|
|
15
|
+
private walk;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=i18n-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-sanitizer.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/utils/i18n-sanitizer.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,OAAO,UAAQ;IAIrB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAwBvE,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;IAwC7E,OAAO,CAAC,YAAY;YAIN,aAAa;YAQb,IAAI;CAiBnB"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.I18nSanitizer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const yaml_1 = require("yaml");
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
const i18n_utils_1 = require("./i18n-utils");
|
|
10
|
+
class I18nSanitizer {
|
|
11
|
+
constructor(verbose = false) {
|
|
12
|
+
this.logger = new logger_1.Logger(verbose);
|
|
13
|
+
}
|
|
14
|
+
async sanitizeAll(roots, dryRun = false) {
|
|
15
|
+
const files = await this.walkYamlFiles(roots);
|
|
16
|
+
this.logger.info(`Scanning ${files.length} YAML files...`);
|
|
17
|
+
const results = [];
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const result = await this.sanitizeFile(file, dryRun);
|
|
20
|
+
if (result.fixed || result.unfixable) {
|
|
21
|
+
results.push(result);
|
|
22
|
+
if (result.unfixable) {
|
|
23
|
+
this.logger.warn(`Unfixable: ${file} — ${result.error}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.logger.success(`${dryRun ? '[dry-run] Would fix' : 'Fixed'}: ${file} (${result.linesChanged} line(s))`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const fixed = results.filter((r) => r.fixed).length;
|
|
31
|
+
const unfixable = results.filter((r) => r.unfixable).length;
|
|
32
|
+
this.logger.info(`Done. Fixed: ${fixed}, Unfixable: ${unfixable}, Clean: ${files.length - results.length}`);
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
async sanitizeFile(filePath, dryRun = false) {
|
|
36
|
+
let content;
|
|
37
|
+
try {
|
|
38
|
+
content = await fs_1.promises.readFile(filePath, 'utf-8');
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return { file: filePath, fixed: false, linesChanged: 0, unfixable: true, error: String(e) };
|
|
42
|
+
}
|
|
43
|
+
// Fast path: try parsing first
|
|
44
|
+
try {
|
|
45
|
+
(0, yaml_1.parse)(content);
|
|
46
|
+
return { file: filePath, fixed: false, linesChanged: 0, unfixable: false };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// fall through to fix
|
|
50
|
+
}
|
|
51
|
+
const original = content.split('\n');
|
|
52
|
+
const sanitized = original.map((line) => this.sanitizeLine(line));
|
|
53
|
+
const linesChanged = sanitized.filter((l, i) => l !== original[i]).length;
|
|
54
|
+
if (linesChanged === 0) {
|
|
55
|
+
return { file: filePath, fixed: false, linesChanged: 0, unfixable: true, error: 'No auto-fixable patterns found' };
|
|
56
|
+
}
|
|
57
|
+
const fixed = sanitized.join('\n');
|
|
58
|
+
// Validate the fix actually resolves the parse error
|
|
59
|
+
try {
|
|
60
|
+
(0, yaml_1.parse)(fixed);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return { file: filePath, fixed: false, linesChanged: 0, unfixable: true, error: `Still invalid after fix: ${e}` };
|
|
64
|
+
}
|
|
65
|
+
if (!dryRun) {
|
|
66
|
+
await fs_1.promises.writeFile(filePath, fixed, 'utf-8');
|
|
67
|
+
}
|
|
68
|
+
return { file: filePath, fixed: true, linesChanged, unfixable: false };
|
|
69
|
+
}
|
|
70
|
+
sanitizeLine(line) {
|
|
71
|
+
return (0, i18n_utils_1.sanitizeI18nLine)(line);
|
|
72
|
+
}
|
|
73
|
+
async walkYamlFiles(roots) {
|
|
74
|
+
const files = [];
|
|
75
|
+
for (const root of roots) {
|
|
76
|
+
await this.walk(root, files);
|
|
77
|
+
}
|
|
78
|
+
return files;
|
|
79
|
+
}
|
|
80
|
+
async walk(dir, acc) {
|
|
81
|
+
let entries;
|
|
82
|
+
try {
|
|
83
|
+
entries = await fs_1.promises.readdir(dir);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
const full = path_1.default.join(dir, entry);
|
|
90
|
+
const stat = await fs_1.promises.lstat(full);
|
|
91
|
+
if (stat.isDirectory()) {
|
|
92
|
+
await this.walk(full, acc);
|
|
93
|
+
}
|
|
94
|
+
else if (entry.endsWith('.yml') || entry.endsWith('.yaml')) {
|
|
95
|
+
acc.push(full);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.I18nSanitizer = I18nSanitizer;
|
|
101
|
+
//# sourceMappingURL=i18n-sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,CAAC;IAEO,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,GAAa;QAC3C,IAAI,OAAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,aAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO;QACT,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACnC,MAAM,IAAI,GAAG,MAAM,aAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBACvB,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC7B,CAAC;iBAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7D,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AApGD,sCAoGC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared i18n utilities for sanitization and validation
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Escapes a string for use in a double-quoted YAML scalar.
|
|
6
|
+
* Replaces backslashes and double quotes.
|
|
7
|
+
*/
|
|
8
|
+
export declare function escapeForYaml(value: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Sanitizes a single line of i18n YAML.
|
|
11
|
+
* Consolidates logic from I18nSanitizer and I18nCompileValidator.
|
|
12
|
+
*
|
|
13
|
+
* Handles:
|
|
14
|
+
* - Tabs to spaces
|
|
15
|
+
* - Unclosed double/single quotes
|
|
16
|
+
* - Trailing text after closing quotes
|
|
17
|
+
* - Special YAML characters at start of scalar (%, &, *, !, |, >, -)
|
|
18
|
+
* - Trailing colons or colon-space in unquoted scalars (preventing nested mappings)
|
|
19
|
+
*/
|
|
20
|
+
export declare function sanitizeI18nLine(line: string): string;
|
|
21
|
+
//# sourceMappingURL=i18n-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n-utils.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/utils/i18n-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiErD"}
|