@worldware/msg-cli 0.6.0 → 0.6.1
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 +5 -2
- package/dist/{chunk-VJKOG7EA.mjs → chunk-3MCULZ7L.mjs} +16 -34
- package/dist/commands/import.cjs +17 -36
- package/dist/commands/import.mjs +4 -4
- package/dist/lib/import-helpers.cjs +18 -35
- package/dist/lib/import-helpers.d.mts +23 -7
- package/dist/lib/import-helpers.d.ts +23 -7
- package/dist/lib/import-helpers.mjs +5 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -291,7 +291,9 @@ msg import -l zh
|
|
|
291
291
|
**Behavior:**
|
|
292
292
|
|
|
293
293
|
- Recursively finds all `.xliff` and `.xlf` files under `l10n/xliff`.
|
|
294
|
-
- Project and target locale are taken from the filename (e.g. `myApp.zh.xliff`) or from
|
|
294
|
+
- Project and target locale are taken from the filename (e.g. `myApp.zh.xliff`) or, when the filename has no locale, from a directory under `l10n/xliff` (e.g. `l10n/xliff/zh/myApp.xliff`). Directories above `l10n/xliff` are ignored, so a path like `/var/…` or `/tmp/…` is never read as a locale.
|
|
295
|
+
- `--project` and `--language` match the filename or a directory under `l10n/xliff` the same way.
|
|
296
|
+
- Skips (with a warning) files with no locale in the filename or under `l10n/xliff`, such as the monolingual `myApp.xliff` written by `msg export`.
|
|
295
297
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
296
298
|
- Skips monolingual XLIFF files (no `trgLang`).
|
|
297
299
|
- Skips files whose target locale is not in the project's `targetLocales`.
|
|
@@ -394,7 +396,8 @@ The CLI does not expose a programmatic API. For library usage, see [@worldware/m
|
|
|
394
396
|
- **Setup:** `npm install`
|
|
395
397
|
- **Build:** `npm run build`
|
|
396
398
|
- **Tests:** `npm run test`
|
|
397
|
-
- **
|
|
399
|
+
- **Type-check:** `npm run typecheck` (source and tests)
|
|
400
|
+
- **Coverage:** `npm run coverage` (fails below 90% lines, branches, functions, or statements)
|
|
398
401
|
|
|
399
402
|
Source layout:
|
|
400
403
|
|
|
@@ -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, join } from "path";
|
|
17
|
+
import { basename, extname, isAbsolute, join, relative, sep } from "path";
|
|
18
18
|
import { pathToFileURL } from "url";
|
|
19
19
|
import { XMLParser } from "fast-xml-parser";
|
|
20
20
|
import { existsSync } from "fs";
|
|
@@ -36,52 +36,33 @@ async function findXliffFilePaths(directory) {
|
|
|
36
36
|
}
|
|
37
37
|
return result;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
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
|
+
function filterXliffPathsByProject(filePaths, projectName, xliffDir) {
|
|
40
47
|
return filePaths.filter((p) => {
|
|
41
48
|
const filename = basename(p);
|
|
42
49
|
if (filename.startsWith(projectName)) return true;
|
|
43
|
-
|
|
44
|
-
return pathParts.some((part) => part === projectName);
|
|
50
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
|
-
function filterXliffPathsByLocale(filePaths, locale) {
|
|
53
|
+
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
48
54
|
return filePaths.filter((p) => {
|
|
49
55
|
const filename = basename(p);
|
|
50
56
|
if (filename.includes(`.${locale}.`)) return true;
|
|
51
|
-
|
|
52
|
-
return pathParts.some((part) => part === locale);
|
|
57
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
53
58
|
});
|
|
54
59
|
}
|
|
55
60
|
var LOCALE_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/;
|
|
56
|
-
function parseXliffFilename(filePath) {
|
|
61
|
+
function parseXliffFilename(filePath, xliffDir) {
|
|
57
62
|
const filename = basename(filePath);
|
|
58
63
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
let locale;
|
|
62
|
-
if (match) {
|
|
63
|
-
const [, proj, loc] = match;
|
|
64
|
-
project = proj ?? basename(filename, extname(filename));
|
|
65
|
-
locale = loc;
|
|
66
|
-
} else {
|
|
67
|
-
project = basename(filename, extname(filename));
|
|
68
|
-
}
|
|
69
|
-
if (!locale) {
|
|
70
|
-
for (const part of pathParts) {
|
|
71
|
-
if (LOCALE_PATTERN.test(part) && part.length >= 2) {
|
|
72
|
-
locale = part;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (!project && pathParts.length >= 2) {
|
|
78
|
-
for (const part of pathParts) {
|
|
79
|
-
if (part && !XLIFF_EXTENSIONS.some((e) => part.endsWith(e))) {
|
|
80
|
-
project = part;
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
64
|
+
const project = match?.[1] ?? basename(filename, extname(filename));
|
|
65
|
+
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
85
66
|
return { project, locale };
|
|
86
67
|
}
|
|
87
68
|
function isMsgProjectLike(value) {
|
|
@@ -334,6 +315,7 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
334
315
|
|
|
335
316
|
export {
|
|
336
317
|
findXliffFilePaths,
|
|
318
|
+
xliffDirSegments,
|
|
337
319
|
filterXliffPathsByProject,
|
|
338
320
|
filterXliffPathsByLocale,
|
|
339
321
|
parseXliffFilename,
|
package/dist/commands/import.cjs
CHANGED
|
@@ -390,52 +390,33 @@ async function findXliffFilePaths(directory) {
|
|
|
390
390
|
}
|
|
391
391
|
return result;
|
|
392
392
|
}
|
|
393
|
-
function
|
|
393
|
+
function xliffDirSegments(xliffDir, filePath) {
|
|
394
|
+
const rel = (0, import_path2.relative)(xliffDir, filePath);
|
|
395
|
+
if (!rel || rel === ".." || rel.startsWith(`..${import_path2.sep}`) || (0, import_path2.isAbsolute)(rel)) {
|
|
396
|
+
return [];
|
|
397
|
+
}
|
|
398
|
+
return rel.split(/[/\\]/).slice(0, -1);
|
|
399
|
+
}
|
|
400
|
+
function filterXliffPathsByProject(filePaths, projectName, xliffDir) {
|
|
394
401
|
return filePaths.filter((p) => {
|
|
395
402
|
const filename = (0, import_path2.basename)(p);
|
|
396
403
|
if (filename.startsWith(projectName)) return true;
|
|
397
|
-
|
|
398
|
-
return pathParts.some((part) => part === projectName);
|
|
404
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
399
405
|
});
|
|
400
406
|
}
|
|
401
|
-
function filterXliffPathsByLocale(filePaths, locale) {
|
|
407
|
+
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
402
408
|
return filePaths.filter((p) => {
|
|
403
409
|
const filename = (0, import_path2.basename)(p);
|
|
404
410
|
if (filename.includes(`.${locale}.`)) return true;
|
|
405
|
-
|
|
406
|
-
return pathParts.some((part) => part === locale);
|
|
411
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
407
412
|
});
|
|
408
413
|
}
|
|
409
414
|
var LOCALE_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/;
|
|
410
|
-
function parseXliffFilename(filePath) {
|
|
415
|
+
function parseXliffFilename(filePath, xliffDir) {
|
|
411
416
|
const filename = (0, import_path2.basename)(filePath);
|
|
412
417
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
let locale;
|
|
416
|
-
if (match) {
|
|
417
|
-
const [, proj, loc] = match;
|
|
418
|
-
project = proj ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
419
|
-
locale = loc;
|
|
420
|
-
} else {
|
|
421
|
-
project = (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
422
|
-
}
|
|
423
|
-
if (!locale) {
|
|
424
|
-
for (const part of pathParts) {
|
|
425
|
-
if (LOCALE_PATTERN.test(part) && part.length >= 2) {
|
|
426
|
-
locale = part;
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
if (!project && pathParts.length >= 2) {
|
|
432
|
-
for (const part of pathParts) {
|
|
433
|
-
if (part && !XLIFF_EXTENSIONS.some((e) => part.endsWith(e))) {
|
|
434
|
-
project = part;
|
|
435
|
-
break;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
418
|
+
const project = match?.[1] ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
419
|
+
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
439
420
|
return { project, locale };
|
|
440
421
|
}
|
|
441
422
|
function isMsgProjectLike(value) {
|
|
@@ -733,7 +714,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
733
714
|
}
|
|
734
715
|
this.log(`Found ${filePaths.length} XLIFF file(s).`);
|
|
735
716
|
if (flags.project) {
|
|
736
|
-
filePaths = filterXliffPathsByProject(filePaths, flags.project);
|
|
717
|
+
filePaths = filterXliffPathsByProject(filePaths, flags.project, xliffDir);
|
|
737
718
|
if (filePaths.length === 0) {
|
|
738
719
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
739
720
|
return;
|
|
@@ -741,7 +722,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
741
722
|
this.log(`Filtered to project '${flags.project}'.`);
|
|
742
723
|
}
|
|
743
724
|
if (flags.language) {
|
|
744
|
-
filePaths = filterXliffPathsByLocale(filePaths, flags.language);
|
|
725
|
+
filePaths = filterXliffPathsByLocale(filePaths, flags.language, xliffDir);
|
|
745
726
|
if (filePaths.length === 0) {
|
|
746
727
|
this.log(`No XLIFF files found for language '${flags.language}'. Nothing to import.`);
|
|
747
728
|
return;
|
|
@@ -751,7 +732,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
751
732
|
let wroteCount = 0;
|
|
752
733
|
let errorCount = 0;
|
|
753
734
|
for (const xliffPath of filePaths) {
|
|
754
|
-
const { project: projectName, locale } = parseXliffFilename(xliffPath);
|
|
735
|
+
const { project: projectName, locale } = parseXliffFilename(xliffPath, xliffDir);
|
|
755
736
|
if (!locale) {
|
|
756
737
|
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
757
738
|
continue;
|
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-3MCULZ7L.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
10
|
import "../chunk-PQJA3H4Z.mjs";
|
|
11
11
|
import "../chunk-HH6ZOHO4.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, xliffDir);
|
|
68
68
|
if (filePaths.length === 0) {
|
|
69
69
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
70
70
|
return;
|
|
@@ -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 = filterXliffPathsByLocale(filePaths, flags.language, xliffDir);
|
|
76
76
|
if (filePaths.length === 0) {
|
|
77
77
|
this.log(`No XLIFF files found for language '${flags.language}'. Nothing to import.`);
|
|
78
78
|
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, locale } = parseXliffFilename(xliffPath);
|
|
85
|
+
const { project: projectName, locale } = parseXliffFilename(xliffPath, xliffDir);
|
|
86
86
|
if (!locale) {
|
|
87
87
|
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
88
88
|
continue;
|
|
@@ -28,7 +28,8 @@ __export(import_helpers_exports, {
|
|
|
28
28
|
parseXliff20: () => parseXliff20,
|
|
29
29
|
parseXliffFilename: () => parseXliffFilename,
|
|
30
30
|
processXliffFile: () => processXliffFile,
|
|
31
|
-
writeTranslationFiles: () => writeTranslationFiles
|
|
31
|
+
writeTranslationFiles: () => writeTranslationFiles,
|
|
32
|
+
xliffDirSegments: () => xliffDirSegments
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(import_helpers_exports);
|
|
34
35
|
var import_msg2 = require("@worldware/msg");
|
|
@@ -330,52 +331,33 @@ async function findXliffFilePaths(directory) {
|
|
|
330
331
|
}
|
|
331
332
|
return result;
|
|
332
333
|
}
|
|
333
|
-
function
|
|
334
|
+
function xliffDirSegments(xliffDir, filePath) {
|
|
335
|
+
const rel = (0, import_path.relative)(xliffDir, filePath);
|
|
336
|
+
if (!rel || rel === ".." || rel.startsWith(`..${import_path.sep}`) || (0, import_path.isAbsolute)(rel)) {
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
return rel.split(/[/\\]/).slice(0, -1);
|
|
340
|
+
}
|
|
341
|
+
function filterXliffPathsByProject(filePaths, projectName, xliffDir) {
|
|
334
342
|
return filePaths.filter((p) => {
|
|
335
343
|
const filename = (0, import_path.basename)(p);
|
|
336
344
|
if (filename.startsWith(projectName)) return true;
|
|
337
|
-
|
|
338
|
-
return pathParts.some((part) => part === projectName);
|
|
345
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
339
346
|
});
|
|
340
347
|
}
|
|
341
|
-
function filterXliffPathsByLocale(filePaths, locale) {
|
|
348
|
+
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
342
349
|
return filePaths.filter((p) => {
|
|
343
350
|
const filename = (0, import_path.basename)(p);
|
|
344
351
|
if (filename.includes(`.${locale}.`)) return true;
|
|
345
|
-
|
|
346
|
-
return pathParts.some((part) => part === locale);
|
|
352
|
+
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
347
353
|
});
|
|
348
354
|
}
|
|
349
355
|
var LOCALE_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/;
|
|
350
|
-
function parseXliffFilename(filePath) {
|
|
356
|
+
function parseXliffFilename(filePath, xliffDir) {
|
|
351
357
|
const filename = (0, import_path.basename)(filePath);
|
|
352
358
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
let locale;
|
|
356
|
-
if (match) {
|
|
357
|
-
const [, proj, loc] = match;
|
|
358
|
-
project = proj ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
359
|
-
locale = loc;
|
|
360
|
-
} else {
|
|
361
|
-
project = (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
362
|
-
}
|
|
363
|
-
if (!locale) {
|
|
364
|
-
for (const part of pathParts) {
|
|
365
|
-
if (LOCALE_PATTERN.test(part) && part.length >= 2) {
|
|
366
|
-
locale = part;
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
if (!project && pathParts.length >= 2) {
|
|
372
|
-
for (const part of pathParts) {
|
|
373
|
-
if (part && !XLIFF_EXTENSIONS.some((e) => part.endsWith(e))) {
|
|
374
|
-
project = part;
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
359
|
+
const project = match?.[1] ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
360
|
+
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
379
361
|
return { project, locale };
|
|
380
362
|
}
|
|
381
363
|
function isMsgProjectLike(value) {
|
|
@@ -635,5 +617,6 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
635
617
|
parseXliff20,
|
|
636
618
|
parseXliffFilename,
|
|
637
619
|
processXliffFile,
|
|
638
|
-
writeTranslationFiles
|
|
620
|
+
writeTranslationFiles,
|
|
621
|
+
xliffDirSegments
|
|
639
622
|
});
|
|
@@ -6,29 +6,45 @@ 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[];
|
|
9
21
|
/**
|
|
10
22
|
* Filters XLIFF file paths by project name.
|
|
11
|
-
* Keeps paths where filename starts with projectName or projectName is a directory
|
|
23
|
+
* Keeps paths where filename starts with projectName or projectName is a directory under xliffDir.
|
|
12
24
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
13
25
|
* @param projectName - Project name to filter by
|
|
26
|
+
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
14
27
|
* @returns Filtered array of paths
|
|
15
28
|
*/
|
|
16
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
29
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string, xliffDir: string): string[];
|
|
17
30
|
/**
|
|
18
31
|
* Filters XLIFF file paths by locale.
|
|
19
|
-
* Keeps paths that have .[locale]. in the filename or locale as a directory
|
|
32
|
+
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
20
33
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
21
34
|
* @param locale - Locale code to filter by
|
|
35
|
+
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
22
36
|
* @returns Filtered array of paths
|
|
23
37
|
*/
|
|
24
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): string[];
|
|
38
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
25
39
|
/**
|
|
26
40
|
* Extracts project name and locale from an XLIFF file path.
|
|
27
|
-
* Filename patterns: project.locale.xliff, project.xliff.
|
|
41
|
+
* Filename patterns: project.locale.xliff, project.xliff. Directories under
|
|
42
|
+
* xliffDir may also indicate project/locale (e.g. xliff/zh/project.xliff).
|
|
28
43
|
* @param filePath - Absolute path to XLIFF file
|
|
44
|
+
* @param xliffDir - Absolute path to the xliff directory the file was found in
|
|
29
45
|
* @returns Object with project and locale (locale may be undefined for monolingual)
|
|
30
46
|
*/
|
|
31
|
-
declare function parseXliffFilename(filePath: string): {
|
|
47
|
+
declare function parseXliffFilename(filePath: string, xliffDir: string): {
|
|
32
48
|
project: string;
|
|
33
49
|
locale?: string;
|
|
34
50
|
};
|
|
@@ -89,4 +105,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
89
105
|
*/
|
|
90
106
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
91
107
|
|
|
92
|
-
export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles };
|
|
108
|
+
export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles, xliffDirSegments };
|
|
@@ -6,29 +6,45 @@ 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[];
|
|
9
21
|
/**
|
|
10
22
|
* Filters XLIFF file paths by project name.
|
|
11
|
-
* Keeps paths where filename starts with projectName or projectName is a directory
|
|
23
|
+
* Keeps paths where filename starts with projectName or projectName is a directory under xliffDir.
|
|
12
24
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
13
25
|
* @param projectName - Project name to filter by
|
|
26
|
+
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
14
27
|
* @returns Filtered array of paths
|
|
15
28
|
*/
|
|
16
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
29
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string, xliffDir: string): string[];
|
|
17
30
|
/**
|
|
18
31
|
* Filters XLIFF file paths by locale.
|
|
19
|
-
* Keeps paths that have .[locale]. in the filename or locale as a directory
|
|
32
|
+
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
20
33
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
21
34
|
* @param locale - Locale code to filter by
|
|
35
|
+
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
22
36
|
* @returns Filtered array of paths
|
|
23
37
|
*/
|
|
24
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): string[];
|
|
38
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
25
39
|
/**
|
|
26
40
|
* Extracts project name and locale from an XLIFF file path.
|
|
27
|
-
* Filename patterns: project.locale.xliff, project.xliff.
|
|
41
|
+
* Filename patterns: project.locale.xliff, project.xliff. Directories under
|
|
42
|
+
* xliffDir may also indicate project/locale (e.g. xliff/zh/project.xliff).
|
|
28
43
|
* @param filePath - Absolute path to XLIFF file
|
|
44
|
+
* @param xliffDir - Absolute path to the xliff directory the file was found in
|
|
29
45
|
* @returns Object with project and locale (locale may be undefined for monolingual)
|
|
30
46
|
*/
|
|
31
|
-
declare function parseXliffFilename(filePath: string): {
|
|
47
|
+
declare function parseXliffFilename(filePath: string, xliffDir: string): {
|
|
32
48
|
project: string;
|
|
33
49
|
locale?: string;
|
|
34
50
|
};
|
|
@@ -89,4 +105,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
89
105
|
*/
|
|
90
106
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
91
107
|
|
|
92
|
-
export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles };
|
|
108
|
+
export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles, xliffDirSegments };
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
parseXliff20,
|
|
8
8
|
parseXliffFilename,
|
|
9
9
|
processXliffFile,
|
|
10
|
-
writeTranslationFiles
|
|
11
|
-
|
|
10
|
+
writeTranslationFiles,
|
|
11
|
+
xliffDirSegments
|
|
12
|
+
} from "../chunk-3MCULZ7L.mjs";
|
|
12
13
|
import "../chunk-Q775ZGC5.mjs";
|
|
13
14
|
import "../chunk-PQJA3H4Z.mjs";
|
|
14
15
|
import "../chunk-HH6ZOHO4.mjs";
|
|
@@ -23,5 +24,6 @@ export {
|
|
|
23
24
|
parseXliff20,
|
|
24
25
|
parseXliffFilename,
|
|
25
26
|
processXliffFile,
|
|
26
|
-
writeTranslationFiles
|
|
27
|
+
writeTranslationFiles,
|
|
28
|
+
xliffDirSegments
|
|
27
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worldware/msg-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "CLI for msg library",
|
|
5
5
|
"main": "dist/commands/init.cjs",
|
|
6
6
|
"module": "dist/commands/init.mjs",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"build": "tsup",
|
|
11
11
|
"prepack": "npm run build",
|
|
12
12
|
"coverage": "vitest run --coverage",
|
|
13
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
|
|
13
14
|
"docs": "typedoc --entryPointStrategy expand src/commands src/lib"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|