@worldware/msg-cli 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{chunk-OJ3XG3HP.mjs → chunk-4FXDFVEO.mjs} +17 -15
- package/dist/commands/import.cjs +17 -14
- package/dist/commands/import.mjs +2 -2
- package/dist/lib/import-helpers.cjs +18 -17
- package/dist/lib/import-helpers.d.mts +8 -18
- package/dist/lib/import-helpers.d.ts +8 -18
- package/dist/lib/import-helpers.mjs +3 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -313,7 +313,7 @@ msg import -l zh
|
|
|
313
313
|
- A locale in the filename must match `trgLang` (case-insensitive). Otherwise the file is skipped with a warning, e.g. `Skipping …/myApp.fr.xliff: file name locale 'fr' does not match trgLang 'de'`. Directory names are not checked against `trgLang`.
|
|
314
314
|
- **Dotted project names:** `my.app.xliff` can mean project `my.app`, or project `my` with locale `app`. When `app` isn't the file's `trgLang` and `i18n/projects` has a `my.app` project, the file imports as project `my.app` (locale from `trgLang`). Otherwise the mismatch warning above applies. `my.app.zh.xliff` is always project `my.app`, locale `zh`.
|
|
315
315
|
- `--project` keeps files whose filename names exactly that project (`app.xliff`, `app.zh.xliff`, in any directory), the project import will load. `--project app` does not select `application.zh.xliff`, nor `l10n/xliff/app/zh/file.xliff` (project `file`). For a dotted name, either reading counts: `--project my.app` selects `my.app.xliff`. A file that then resolves to another project is not imported.
|
|
316
|
-
- `--language`
|
|
316
|
+
- `--language` keeps files whose `trgLang` is that locale (case-insensitive), wherever they sit; the path is not consulted. `--language zh` selects a bilingual `l10n/xliff/app.xliff` with `trgLang="zh"`, and does not select `l10n/xliff/zh/app.xliff` whose `trgLang` is `de`. Monolingual files are not selected. A malformed file is kept, so the import fails on it as an unfiltered `msg import` would.
|
|
317
317
|
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
318
318
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
319
319
|
- Skips files whose `trgLang` is not in the project's `targetLocales`.
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
// src/lib/import-helpers.ts
|
|
15
15
|
import { MsgResource } from "@worldware/msg";
|
|
16
16
|
import { readdir, readFile, writeFile, mkdir } from "fs/promises";
|
|
17
|
-
import { basename, extname,
|
|
17
|
+
import { basename, extname, join } from "path";
|
|
18
18
|
import { pathToFileURL } from "url";
|
|
19
19
|
import { XMLParser } from "fast-xml-parser";
|
|
20
20
|
import { existsSync } from "fs";
|
|
@@ -36,25 +36,28 @@ async function findXliffFilePaths(directory) {
|
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
|
-
function xliffDirSegments(xliffDir, filePath) {
|
|
40
|
-
const rel = relative(xliffDir, filePath);
|
|
41
|
-
if (!rel || rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
return rel.split(/[/\\]/).slice(0, -1);
|
|
45
|
-
}
|
|
46
39
|
function filterXliffPathsByProject(filePaths, projectName) {
|
|
47
40
|
return filePaths.filter((p) => {
|
|
48
41
|
const stem = basename(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
49
42
|
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
50
43
|
});
|
|
51
44
|
}
|
|
52
|
-
function filterXliffPathsByLocale(filePaths, locale
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
45
|
+
async function filterXliffPathsByLocale(filePaths, locale) {
|
|
46
|
+
const wanted = locale.toLowerCase();
|
|
47
|
+
const keep = await Promise.all(
|
|
48
|
+
filePaths.map(async (p) => {
|
|
49
|
+
let parsed;
|
|
50
|
+
try {
|
|
51
|
+
parsed = parseXliff20(await readFile(p, "utf-8"));
|
|
52
|
+
} catch {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const root = parsed.xliff;
|
|
56
|
+
const trgLang = root?.["@_trgLang"];
|
|
57
|
+
return typeof trgLang === "string" && trgLang.toLowerCase() === wanted;
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
return filePaths.filter((_, i) => keep[i]);
|
|
58
61
|
}
|
|
59
62
|
function parseXliffFilename(filePath) {
|
|
60
63
|
const filename = basename(filePath);
|
|
@@ -370,7 +373,6 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
370
373
|
|
|
371
374
|
export {
|
|
372
375
|
findXliffFilePaths,
|
|
373
|
-
xliffDirSegments,
|
|
374
376
|
filterXliffPathsByProject,
|
|
375
377
|
filterXliffPathsByLocale,
|
|
376
378
|
parseXliffFilename,
|
package/dist/commands/import.cjs
CHANGED
|
@@ -388,25 +388,28 @@ async function findXliffFilePaths(directory) {
|
|
|
388
388
|
}
|
|
389
389
|
return result;
|
|
390
390
|
}
|
|
391
|
-
function xliffDirSegments(xliffDir, filePath) {
|
|
392
|
-
const rel = (0, import_path2.relative)(xliffDir, filePath);
|
|
393
|
-
if (!rel || rel === ".." || rel.startsWith(`..${import_path2.sep}`) || (0, import_path2.isAbsolute)(rel)) {
|
|
394
|
-
return [];
|
|
395
|
-
}
|
|
396
|
-
return rel.split(/[/\\]/).slice(0, -1);
|
|
397
|
-
}
|
|
398
391
|
function filterXliffPathsByProject(filePaths, projectName) {
|
|
399
392
|
return filePaths.filter((p) => {
|
|
400
393
|
const stem = (0, import_path2.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
401
394
|
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
402
395
|
});
|
|
403
396
|
}
|
|
404
|
-
function filterXliffPathsByLocale(filePaths, locale
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
397
|
+
async function filterXliffPathsByLocale(filePaths, locale) {
|
|
398
|
+
const wanted = locale.toLowerCase();
|
|
399
|
+
const keep = await Promise.all(
|
|
400
|
+
filePaths.map(async (p) => {
|
|
401
|
+
let parsed;
|
|
402
|
+
try {
|
|
403
|
+
parsed = parseXliff20(await (0, import_promises.readFile)(p, "utf-8"));
|
|
404
|
+
} catch {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
const root = parsed.xliff;
|
|
408
|
+
const trgLang = root?.["@_trgLang"];
|
|
409
|
+
return typeof trgLang === "string" && trgLang.toLowerCase() === wanted;
|
|
410
|
+
})
|
|
411
|
+
);
|
|
412
|
+
return filePaths.filter((_, i) => keep[i]);
|
|
410
413
|
}
|
|
411
414
|
function parseXliffFilename(filePath) {
|
|
412
415
|
const filename = (0, import_path2.basename)(filePath);
|
|
@@ -775,7 +778,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
775
778
|
this.log(`Filtered to project '${flags.project}'.`);
|
|
776
779
|
}
|
|
777
780
|
if (flags.language) {
|
|
778
|
-
filePaths = filterXliffPathsByLocale(filePaths, flags.language
|
|
781
|
+
filePaths = await filterXliffPathsByLocale(filePaths, flags.language);
|
|
779
782
|
if (filePaths.length === 0) {
|
|
780
783
|
this.log(`No XLIFF files found for language '${flags.language}'. Nothing to import.`);
|
|
781
784
|
return;
|
package/dist/commands/import.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
parseXliffFilename,
|
|
6
6
|
processXliffFile,
|
|
7
7
|
writeTranslationFiles
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-4FXDFVEO.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
10
|
import "../chunk-QMSV2PP2.mjs";
|
|
11
11
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -72,7 +72,7 @@ var Import = class _Import extends Command {
|
|
|
72
72
|
this.log(`Filtered to project '${flags.project}'.`);
|
|
73
73
|
}
|
|
74
74
|
if (flags.language) {
|
|
75
|
-
filePaths = filterXliffPathsByLocale(filePaths, flags.language
|
|
75
|
+
filePaths = await filterXliffPathsByLocale(filePaths, flags.language);
|
|
76
76
|
if (filePaths.length === 0) {
|
|
77
77
|
this.log(`No XLIFF files found for language '${flags.language}'. Nothing to import.`);
|
|
78
78
|
return;
|
|
@@ -29,8 +29,7 @@ __export(import_helpers_exports, {
|
|
|
29
29
|
parseXliffFilename: () => parseXliffFilename,
|
|
30
30
|
processXliffFile: () => processXliffFile,
|
|
31
31
|
projectFileExists: () => projectFileExists,
|
|
32
|
-
writeTranslationFiles: () => writeTranslationFiles
|
|
33
|
-
xliffDirSegments: () => xliffDirSegments
|
|
32
|
+
writeTranslationFiles: () => writeTranslationFiles
|
|
34
33
|
});
|
|
35
34
|
module.exports = __toCommonJS(import_helpers_exports);
|
|
36
35
|
var import_msg2 = require("@worldware/msg");
|
|
@@ -330,25 +329,28 @@ async function findXliffFilePaths(directory) {
|
|
|
330
329
|
}
|
|
331
330
|
return result;
|
|
332
331
|
}
|
|
333
|
-
function xliffDirSegments(xliffDir, filePath) {
|
|
334
|
-
const rel = (0, import_path.relative)(xliffDir, filePath);
|
|
335
|
-
if (!rel || rel === ".." || rel.startsWith(`..${import_path.sep}`) || (0, import_path.isAbsolute)(rel)) {
|
|
336
|
-
return [];
|
|
337
|
-
}
|
|
338
|
-
return rel.split(/[/\\]/).slice(0, -1);
|
|
339
|
-
}
|
|
340
332
|
function filterXliffPathsByProject(filePaths, projectName) {
|
|
341
333
|
return filePaths.filter((p) => {
|
|
342
334
|
const stem = (0, import_path.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
343
335
|
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
344
336
|
});
|
|
345
337
|
}
|
|
346
|
-
function filterXliffPathsByLocale(filePaths, locale
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
338
|
+
async function filterXliffPathsByLocale(filePaths, locale) {
|
|
339
|
+
const wanted = locale.toLowerCase();
|
|
340
|
+
const keep = await Promise.all(
|
|
341
|
+
filePaths.map(async (p) => {
|
|
342
|
+
let parsed;
|
|
343
|
+
try {
|
|
344
|
+
parsed = parseXliff20(await (0, import_promises.readFile)(p, "utf-8"));
|
|
345
|
+
} catch {
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
const root = parsed.xliff;
|
|
349
|
+
const trgLang = root?.["@_trgLang"];
|
|
350
|
+
return typeof trgLang === "string" && trgLang.toLowerCase() === wanted;
|
|
351
|
+
})
|
|
352
|
+
);
|
|
353
|
+
return filePaths.filter((_, i) => keep[i]);
|
|
352
354
|
}
|
|
353
355
|
function parseXliffFilename(filePath) {
|
|
354
356
|
const filename = (0, import_path.basename)(filePath);
|
|
@@ -672,6 +674,5 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
672
674
|
parseXliffFilename,
|
|
673
675
|
processXliffFile,
|
|
674
676
|
projectFileExists,
|
|
675
|
-
writeTranslationFiles
|
|
676
|
-
xliffDirSegments
|
|
677
|
+
writeTranslationFiles
|
|
677
678
|
});
|
|
@@ -6,18 +6,6 @@ import { MsgResource } from '@worldware/msg';
|
|
|
6
6
|
* @returns Promise resolving to array of absolute file paths
|
|
7
7
|
*/
|
|
8
8
|
declare function findXliffFilePaths(directory: string): Promise<string[]>;
|
|
9
|
-
/**
|
|
10
|
-
* Returns the directory names between the xliff root and an XLIFF file.
|
|
11
|
-
*
|
|
12
|
-
* Path-based project/locale detection must only look below the xliff root:
|
|
13
|
-
* directories above it (`/var`, `/tmp`, `src`, ...) belong to the machine,
|
|
14
|
-
* not to the msg layout, and many of them look like locale codes.
|
|
15
|
-
* @param xliffDir - Absolute path to the xliff directory (e.g. l10n/xliff)
|
|
16
|
-
* @param filePath - Absolute path to an XLIFF file
|
|
17
|
-
* @returns Directory segments under xliffDir, excluding the file name; empty
|
|
18
|
-
* when the file is directly in xliffDir or outside it
|
|
19
|
-
*/
|
|
20
|
-
declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
21
9
|
/**
|
|
22
10
|
* Filters XLIFF file paths by project name.
|
|
23
11
|
* Keeps paths whose file name parses to exactly that project (`project.xliff`,
|
|
@@ -30,14 +18,16 @@ declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
|
30
18
|
*/
|
|
31
19
|
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
32
20
|
/**
|
|
33
|
-
* Filters XLIFF file paths by locale
|
|
34
|
-
*
|
|
21
|
+
* Filters XLIFF file paths by target locale: keeps files whose `trgLang`
|
|
22
|
+
* equals `locale` (case-insensitive), wherever they sit. Import takes a file's
|
|
23
|
+
* locale from `trgLang` (#57), so the path is not consulted (#69).
|
|
24
|
+
* Monolingual files (no `trgLang`) are dropped; files that cannot be read or
|
|
25
|
+
* parsed are kept so the import reports them.
|
|
35
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
36
27
|
* @param locale - Locale code to filter by
|
|
37
|
-
* @
|
|
38
|
-
* @returns Filtered array of paths
|
|
28
|
+
* @returns Filtered array of paths, in input order
|
|
39
29
|
*/
|
|
40
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string
|
|
30
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): Promise<string[]>;
|
|
41
31
|
/**
|
|
42
32
|
* Extracts project name and locale from an XLIFF file name
|
|
43
33
|
* (`project.locale.xliff` or `project.xliff`).
|
|
@@ -120,4 +110,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
120
110
|
*/
|
|
121
111
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
122
112
|
|
|
123
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles
|
|
113
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles };
|
|
@@ -6,18 +6,6 @@ import { MsgResource } from '@worldware/msg';
|
|
|
6
6
|
* @returns Promise resolving to array of absolute file paths
|
|
7
7
|
*/
|
|
8
8
|
declare function findXliffFilePaths(directory: string): Promise<string[]>;
|
|
9
|
-
/**
|
|
10
|
-
* Returns the directory names between the xliff root and an XLIFF file.
|
|
11
|
-
*
|
|
12
|
-
* Path-based project/locale detection must only look below the xliff root:
|
|
13
|
-
* directories above it (`/var`, `/tmp`, `src`, ...) belong to the machine,
|
|
14
|
-
* not to the msg layout, and many of them look like locale codes.
|
|
15
|
-
* @param xliffDir - Absolute path to the xliff directory (e.g. l10n/xliff)
|
|
16
|
-
* @param filePath - Absolute path to an XLIFF file
|
|
17
|
-
* @returns Directory segments under xliffDir, excluding the file name; empty
|
|
18
|
-
* when the file is directly in xliffDir or outside it
|
|
19
|
-
*/
|
|
20
|
-
declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
21
9
|
/**
|
|
22
10
|
* Filters XLIFF file paths by project name.
|
|
23
11
|
* Keeps paths whose file name parses to exactly that project (`project.xliff`,
|
|
@@ -30,14 +18,16 @@ declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
|
30
18
|
*/
|
|
31
19
|
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
32
20
|
/**
|
|
33
|
-
* Filters XLIFF file paths by locale
|
|
34
|
-
*
|
|
21
|
+
* Filters XLIFF file paths by target locale: keeps files whose `trgLang`
|
|
22
|
+
* equals `locale` (case-insensitive), wherever they sit. Import takes a file's
|
|
23
|
+
* locale from `trgLang` (#57), so the path is not consulted (#69).
|
|
24
|
+
* Monolingual files (no `trgLang`) are dropped; files that cannot be read or
|
|
25
|
+
* parsed are kept so the import reports them.
|
|
35
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
36
27
|
* @param locale - Locale code to filter by
|
|
37
|
-
* @
|
|
38
|
-
* @returns Filtered array of paths
|
|
28
|
+
* @returns Filtered array of paths, in input order
|
|
39
29
|
*/
|
|
40
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string
|
|
30
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): Promise<string[]>;
|
|
41
31
|
/**
|
|
42
32
|
* Extracts project name and locale from an XLIFF file name
|
|
43
33
|
* (`project.locale.xliff` or `project.xliff`).
|
|
@@ -120,4 +110,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
120
110
|
*/
|
|
121
111
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
122
112
|
|
|
123
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles
|
|
113
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles };
|
|
@@ -8,9 +8,8 @@ import {
|
|
|
8
8
|
parseXliffFilename,
|
|
9
9
|
processXliffFile,
|
|
10
10
|
projectFileExists,
|
|
11
|
-
writeTranslationFiles
|
|
12
|
-
|
|
13
|
-
} from "../chunk-OJ3XG3HP.mjs";
|
|
11
|
+
writeTranslationFiles
|
|
12
|
+
} from "../chunk-4FXDFVEO.mjs";
|
|
14
13
|
import "../chunk-Q775ZGC5.mjs";
|
|
15
14
|
import "../chunk-QMSV2PP2.mjs";
|
|
16
15
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -26,6 +25,5 @@ export {
|
|
|
26
25
|
parseXliffFilename,
|
|
27
26
|
processXliffFile,
|
|
28
27
|
projectFileExists,
|
|
29
|
-
writeTranslationFiles
|
|
30
|
-
xliffDirSegments
|
|
28
|
+
writeTranslationFiles
|
|
31
29
|
};
|