@worldware/msg-cli 0.6.4 → 0.6.5
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 +2 -1
- package/dist/{chunk-A6XUN4LX.mjs → chunk-OUQSCR6C.mjs} +4 -10
- package/dist/commands/import.cjs +6 -12
- package/dist/commands/import.mjs +3 -3
- package/dist/lib/import-helpers.cjs +4 -10
- package/dist/lib/import-helpers.d.mts +13 -13
- package/dist/lib/import-helpers.d.ts +13 -13
- package/dist/lib/import-helpers.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -311,7 +311,8 @@ msg import -l zh
|
|
|
311
311
|
- The project is taken from the filename (`myApp.zh.xliff` or `myApp.xliff` → `myApp`).
|
|
312
312
|
- The target locale is the file's `trgLang`, wherever the file sits under `l10n/xliff` (e.g. `l10n/xliff/zh/myApp.xliff`, `l10n/xliff/vendor/zh/myApp.xliff`, or `l10n/xliff/myApp.xliff`).
|
|
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
|
-
- `--project`
|
|
314
|
+
- `--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`).
|
|
315
|
+
- `--language` matches the filename or a directory under `l10n/xliff`. Directories above `l10n/xliff` are ignored, so a path like `/var/…` or `/tmp/…` never matches.
|
|
315
316
|
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
316
317
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
317
318
|
- Skips files whose `trgLang` is not in the project's `targetLocales`.
|
|
@@ -43,12 +43,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
43
43
|
}
|
|
44
44
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
45
45
|
}
|
|
46
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
47
|
-
return filePaths.filter((p) =>
|
|
48
|
-
const filename = basename(p);
|
|
49
|
-
if (filename.startsWith(projectName)) return true;
|
|
50
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
51
|
-
});
|
|
46
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
47
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
52
48
|
}
|
|
53
49
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
54
50
|
return filePaths.filter((p) => {
|
|
@@ -57,13 +53,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
57
53
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
58
54
|
});
|
|
59
55
|
}
|
|
60
|
-
|
|
61
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
56
|
+
function parseXliffFilename(filePath) {
|
|
62
57
|
const filename = basename(filePath);
|
|
63
58
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
64
59
|
const project = match?.[1] ?? basename(filename, extname(filename));
|
|
65
|
-
|
|
66
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
60
|
+
return { project, locale: match?.[2] };
|
|
67
61
|
}
|
|
68
62
|
function isMsgProjectLike(value) {
|
|
69
63
|
if (!value || typeof value !== "object") return false;
|
package/dist/commands/import.cjs
CHANGED
|
@@ -395,12 +395,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
395
395
|
}
|
|
396
396
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
397
397
|
}
|
|
398
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
399
|
-
return filePaths.filter((p) =>
|
|
400
|
-
const filename = (0, import_path2.basename)(p);
|
|
401
|
-
if (filename.startsWith(projectName)) return true;
|
|
402
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
403
|
-
});
|
|
398
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
399
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
404
400
|
}
|
|
405
401
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
406
402
|
return filePaths.filter((p) => {
|
|
@@ -409,13 +405,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
409
405
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
410
406
|
});
|
|
411
407
|
}
|
|
412
|
-
|
|
413
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
408
|
+
function parseXliffFilename(filePath) {
|
|
414
409
|
const filename = (0, import_path2.basename)(filePath);
|
|
415
410
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
416
411
|
const project = match?.[1] ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
417
|
-
|
|
418
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
412
|
+
return { project, locale: match?.[2] };
|
|
419
413
|
}
|
|
420
414
|
function isMsgProjectLike(value) {
|
|
421
415
|
if (!value || typeof value !== "object") return false;
|
|
@@ -761,7 +755,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
761
755
|
}
|
|
762
756
|
this.log(`Found ${filePaths.length} XLIFF file(s).`);
|
|
763
757
|
if (flags.project) {
|
|
764
|
-
filePaths = filterXliffPathsByProject(filePaths, flags.project
|
|
758
|
+
filePaths = filterXliffPathsByProject(filePaths, flags.project);
|
|
765
759
|
if (filePaths.length === 0) {
|
|
766
760
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
767
761
|
return;
|
|
@@ -779,7 +773,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
779
773
|
let wroteCount = 0;
|
|
780
774
|
let errorCount = 0;
|
|
781
775
|
for (const xliffPath of filePaths) {
|
|
782
|
-
const { project: projectName, filenameLocale } = parseXliffFilename(xliffPath
|
|
776
|
+
const { project: projectName, locale: filenameLocale } = parseXliffFilename(xliffPath);
|
|
783
777
|
try {
|
|
784
778
|
const result = await processXliffFile(
|
|
785
779
|
xliffPath,
|
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-OUQSCR6C.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
10
|
import "../chunk-QMSV2PP2.mjs";
|
|
11
11
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -64,7 +64,7 @@ var Import = class _Import extends Command {
|
|
|
64
64
|
}
|
|
65
65
|
this.log(`Found ${filePaths.length} XLIFF file(s).`);
|
|
66
66
|
if (flags.project) {
|
|
67
|
-
filePaths = filterXliffPathsByProject(filePaths, flags.project
|
|
67
|
+
filePaths = filterXliffPathsByProject(filePaths, flags.project);
|
|
68
68
|
if (filePaths.length === 0) {
|
|
69
69
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
70
70
|
return;
|
|
@@ -82,7 +82,7 @@ var Import = class _Import extends Command {
|
|
|
82
82
|
let wroteCount = 0;
|
|
83
83
|
let errorCount = 0;
|
|
84
84
|
for (const xliffPath of filePaths) {
|
|
85
|
-
const { project: projectName, filenameLocale } = parseXliffFilename(xliffPath
|
|
85
|
+
const { project: projectName, locale: filenameLocale } = parseXliffFilename(xliffPath);
|
|
86
86
|
try {
|
|
87
87
|
const result = await processXliffFile(
|
|
88
88
|
xliffPath,
|
|
@@ -336,12 +336,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
336
336
|
}
|
|
337
337
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
338
338
|
}
|
|
339
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
340
|
-
return filePaths.filter((p) =>
|
|
341
|
-
const filename = (0, import_path.basename)(p);
|
|
342
|
-
if (filename.startsWith(projectName)) return true;
|
|
343
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
344
|
-
});
|
|
339
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
340
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
345
341
|
}
|
|
346
342
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
347
343
|
return filePaths.filter((p) => {
|
|
@@ -350,13 +346,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
350
346
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
351
347
|
});
|
|
352
348
|
}
|
|
353
|
-
|
|
354
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
349
|
+
function parseXliffFilename(filePath) {
|
|
355
350
|
const filename = (0, import_path.basename)(filePath);
|
|
356
351
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
357
352
|
const project = match?.[1] ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
358
|
-
|
|
359
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
353
|
+
return { project, locale: match?.[2] };
|
|
360
354
|
}
|
|
361
355
|
function isMsgProjectLike(value) {
|
|
362
356
|
if (!value || typeof value !== "object") return false;
|
|
@@ -20,13 +20,14 @@ declare function findXliffFilePaths(directory: string): Promise<string[]>;
|
|
|
20
20
|
declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
21
21
|
/**
|
|
22
22
|
* Filters XLIFF file paths by project name.
|
|
23
|
-
* Keeps paths
|
|
23
|
+
* Keeps paths whose file name parses to exactly that project (`project.xliff`,
|
|
24
|
+
* `project.locale.xliff`), wherever they sit. This is the project import loads,
|
|
25
|
+
* so directories are not matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
27
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
28
|
* @returns Filtered array of paths
|
|
28
29
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
30
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
31
|
/**
|
|
31
32
|
* Filters XLIFF file paths by locale.
|
|
32
33
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,19 +38,18 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
38
|
*/
|
|
38
39
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
40
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
41
|
+
* Extracts project name and locale from an XLIFF file name
|
|
42
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
43
|
+
*
|
|
44
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
45
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
46
|
+
* locale from directories let short names like `app` win (#55).
|
|
47
|
+
* @param filePath - Path to an XLIFF file
|
|
48
|
+
* @returns Object with project and the file name's locale, if any
|
|
48
49
|
*/
|
|
49
|
-
declare function parseXliffFilename(filePath: string
|
|
50
|
+
declare function parseXliffFilename(filePath: string): {
|
|
50
51
|
project: string;
|
|
51
52
|
locale?: string;
|
|
52
|
-
filenameLocale?: string;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Dynamically imports MsgProject from i18n/projects by project name.
|
|
@@ -20,13 +20,14 @@ declare function findXliffFilePaths(directory: string): Promise<string[]>;
|
|
|
20
20
|
declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
|
|
21
21
|
/**
|
|
22
22
|
* Filters XLIFF file paths by project name.
|
|
23
|
-
* Keeps paths
|
|
23
|
+
* Keeps paths whose file name parses to exactly that project (`project.xliff`,
|
|
24
|
+
* `project.locale.xliff`), wherever they sit. This is the project import loads,
|
|
25
|
+
* so directories are not matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
27
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
28
|
* @returns Filtered array of paths
|
|
28
29
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
30
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
31
|
/**
|
|
31
32
|
* Filters XLIFF file paths by locale.
|
|
32
33
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,19 +38,18 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
38
|
*/
|
|
38
39
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
40
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
41
|
+
* Extracts project name and locale from an XLIFF file name
|
|
42
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
43
|
+
*
|
|
44
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
45
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
46
|
+
* locale from directories let short names like `app` win (#55).
|
|
47
|
+
* @param filePath - Path to an XLIFF file
|
|
48
|
+
* @returns Object with project and the file name's locale, if any
|
|
48
49
|
*/
|
|
49
|
-
declare function parseXliffFilename(filePath: string
|
|
50
|
+
declare function parseXliffFilename(filePath: string): {
|
|
50
51
|
project: string;
|
|
51
52
|
locale?: string;
|
|
52
|
-
filenameLocale?: string;
|
|
53
53
|
};
|
|
54
54
|
/**
|
|
55
55
|
* Dynamically imports MsgProject from i18n/projects by project name.
|