@worldware/msg-cli 0.6.4 → 0.6.6
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 +3 -1
- package/dist/{chunk-A6XUN4LX.mjs → chunk-OJ3XG3HP.mjs} +22 -15
- package/dist/commands/import.cjs +24 -17
- package/dist/commands/import.mjs +4 -3
- package/dist/lib/import-helpers.cjs +23 -15
- package/dist/lib/import-helpers.d.mts +21 -14
- package/dist/lib/import-helpers.d.ts +21 -14
- package/dist/lib/import-helpers.mjs +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -311,7 +311,9 @@ 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
|
-
-
|
|
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
|
+
- `--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` 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
317
|
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
316
318
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
317
319
|
- Skips files whose `trgLang` is not in the project's `targetLocales`.
|
|
@@ -43,11 +43,10 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
43
43
|
}
|
|
44
44
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
45
45
|
}
|
|
46
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
46
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
47
47
|
return filePaths.filter((p) => {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
48
|
+
const stem = basename(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
49
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
@@ -57,23 +56,21 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
57
56
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
59
|
+
function parseXliffFilename(filePath) {
|
|
62
60
|
const filename = basename(filePath);
|
|
63
61
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
64
62
|
const project = match?.[1] ?? basename(filename, extname(filename));
|
|
65
|
-
|
|
66
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
63
|
+
return { project, locale: match?.[2] };
|
|
67
64
|
}
|
|
68
65
|
function isMsgProjectLike(value) {
|
|
69
66
|
if (!value || typeof value !== "object") return false;
|
|
70
67
|
const loc = value.locales?.targetLocales;
|
|
71
68
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
72
69
|
}
|
|
70
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
73
71
|
async function importMsgProject(projectsDir, projectName) {
|
|
74
72
|
const basePath = join(projectsDir, projectName);
|
|
75
|
-
const
|
|
76
|
-
for (const ext of exts) {
|
|
73
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
77
74
|
const p = `${basePath}${ext}`;
|
|
78
75
|
if (existsSync(p)) {
|
|
79
76
|
const url = pathToFileURL(p).href;
|
|
@@ -87,6 +84,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
87
84
|
}
|
|
88
85
|
throw new Error(`Project file not found: ${projectName}`);
|
|
89
86
|
}
|
|
87
|
+
function projectFileExists(projectsDir, projectName) {
|
|
88
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => existsSync(join(projectsDir, `${projectName}${ext}`)));
|
|
89
|
+
}
|
|
90
90
|
var xmlParser = new XMLParser({
|
|
91
91
|
ignoreAttributes: false,
|
|
92
92
|
attributeNamePrefix: "@_",
|
|
@@ -318,14 +318,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
318
318
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
319
319
|
return null;
|
|
320
320
|
}
|
|
321
|
+
const locale = xliffTrgLang;
|
|
322
|
+
let resolvedProject = projectName;
|
|
321
323
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
325
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
326
|
+
resolvedProject = dottedProject;
|
|
327
|
+
} else {
|
|
328
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
324
331
|
}
|
|
325
|
-
const locale = xliffTrgLang;
|
|
326
332
|
let project;
|
|
327
333
|
try {
|
|
328
|
-
project = await importMsgProject(projectsDir,
|
|
334
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
329
335
|
} catch {
|
|
330
336
|
return null;
|
|
331
337
|
}
|
|
@@ -349,7 +355,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
349
355
|
}
|
|
350
356
|
}
|
|
351
357
|
if (resources.length === 0) return null;
|
|
352
|
-
return { project:
|
|
358
|
+
return { project: resolvedProject, locale, resources };
|
|
353
359
|
}
|
|
354
360
|
async function writeTranslationFiles(translationsDir, result) {
|
|
355
361
|
const { project, locale, resources } = result;
|
|
@@ -369,6 +375,7 @@ export {
|
|
|
369
375
|
filterXliffPathsByLocale,
|
|
370
376
|
parseXliffFilename,
|
|
371
377
|
importMsgProject,
|
|
378
|
+
projectFileExists,
|
|
372
379
|
parseXliff20,
|
|
373
380
|
extractResourceFromXliffFile,
|
|
374
381
|
processXliffFile,
|
package/dist/commands/import.cjs
CHANGED
|
@@ -395,11 +395,10 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
395
395
|
}
|
|
396
396
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
397
397
|
}
|
|
398
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
398
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
399
399
|
return filePaths.filter((p) => {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
400
|
+
const stem = (0, import_path2.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
401
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
403
402
|
});
|
|
404
403
|
}
|
|
405
404
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
@@ -409,23 +408,21 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
409
408
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
410
409
|
});
|
|
411
410
|
}
|
|
412
|
-
|
|
413
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
411
|
+
function parseXliffFilename(filePath) {
|
|
414
412
|
const filename = (0, import_path2.basename)(filePath);
|
|
415
413
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
416
414
|
const project = match?.[1] ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
417
|
-
|
|
418
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
415
|
+
return { project, locale: match?.[2] };
|
|
419
416
|
}
|
|
420
417
|
function isMsgProjectLike(value) {
|
|
421
418
|
if (!value || typeof value !== "object") return false;
|
|
422
419
|
const loc = value.locales?.targetLocales;
|
|
423
420
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
424
421
|
}
|
|
422
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
425
423
|
async function importMsgProject(projectsDir, projectName) {
|
|
426
424
|
const basePath = (0, import_path2.join)(projectsDir, projectName);
|
|
427
|
-
const
|
|
428
|
-
for (const ext of exts) {
|
|
425
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
429
426
|
const p = `${basePath}${ext}`;
|
|
430
427
|
if ((0, import_fs2.existsSync)(p)) {
|
|
431
428
|
const url = (0, import_url2.pathToFileURL)(p).href;
|
|
@@ -439,6 +436,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
439
436
|
}
|
|
440
437
|
throw new Error(`Project file not found: ${projectName}`);
|
|
441
438
|
}
|
|
439
|
+
function projectFileExists(projectsDir, projectName) {
|
|
440
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => (0, import_fs2.existsSync)((0, import_path2.join)(projectsDir, `${projectName}${ext}`)));
|
|
441
|
+
}
|
|
442
442
|
var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
443
443
|
ignoreAttributes: false,
|
|
444
444
|
attributeNamePrefix: "@_",
|
|
@@ -670,14 +670,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
670
670
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
671
671
|
return null;
|
|
672
672
|
}
|
|
673
|
+
const locale = xliffTrgLang;
|
|
674
|
+
let resolvedProject = projectName;
|
|
673
675
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
677
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
678
|
+
resolvedProject = dottedProject;
|
|
679
|
+
} else {
|
|
680
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
676
683
|
}
|
|
677
|
-
const locale = xliffTrgLang;
|
|
678
684
|
let project;
|
|
679
685
|
try {
|
|
680
|
-
project = await importMsgProject(projectsDir,
|
|
686
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
681
687
|
} catch {
|
|
682
688
|
return null;
|
|
683
689
|
}
|
|
@@ -701,7 +707,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
701
707
|
}
|
|
702
708
|
}
|
|
703
709
|
if (resources.length === 0) return null;
|
|
704
|
-
return { project:
|
|
710
|
+
return { project: resolvedProject, locale, resources };
|
|
705
711
|
}
|
|
706
712
|
async function writeTranslationFiles(translationsDir, result) {
|
|
707
713
|
const { project, locale, resources } = result;
|
|
@@ -761,7 +767,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
761
767
|
}
|
|
762
768
|
this.log(`Found ${filePaths.length} XLIFF file(s).`);
|
|
763
769
|
if (flags.project) {
|
|
764
|
-
filePaths = filterXliffPathsByProject(filePaths, flags.project
|
|
770
|
+
filePaths = filterXliffPathsByProject(filePaths, flags.project);
|
|
765
771
|
if (filePaths.length === 0) {
|
|
766
772
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
767
773
|
return;
|
|
@@ -779,7 +785,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
779
785
|
let wroteCount = 0;
|
|
780
786
|
let errorCount = 0;
|
|
781
787
|
for (const xliffPath of filePaths) {
|
|
782
|
-
const { project: projectName, filenameLocale } = parseXliffFilename(xliffPath
|
|
788
|
+
const { project: projectName, locale: filenameLocale } = parseXliffFilename(xliffPath);
|
|
783
789
|
try {
|
|
784
790
|
const result = await processXliffFile(
|
|
785
791
|
xliffPath,
|
|
@@ -788,6 +794,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
788
794
|
filenameLocale,
|
|
789
795
|
(message) => this.warn(message)
|
|
790
796
|
);
|
|
797
|
+
if (result && flags.project && result.project !== flags.project) continue;
|
|
791
798
|
if (result) {
|
|
792
799
|
await writeTranslationFiles(translationsDir, result);
|
|
793
800
|
for (const { title } of result.resources) {
|
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-OJ3XG3HP.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,
|
|
@@ -91,6 +91,7 @@ var Import = class _Import extends Command {
|
|
|
91
91
|
filenameLocale,
|
|
92
92
|
(message) => this.warn(message)
|
|
93
93
|
);
|
|
94
|
+
if (result && flags.project && result.project !== flags.project) continue;
|
|
94
95
|
if (result) {
|
|
95
96
|
await writeTranslationFiles(translationsDir, result);
|
|
96
97
|
for (const { title } of result.resources) {
|
|
@@ -28,6 +28,7 @@ __export(import_helpers_exports, {
|
|
|
28
28
|
parseXliff20: () => parseXliff20,
|
|
29
29
|
parseXliffFilename: () => parseXliffFilename,
|
|
30
30
|
processXliffFile: () => processXliffFile,
|
|
31
|
+
projectFileExists: () => projectFileExists,
|
|
31
32
|
writeTranslationFiles: () => writeTranslationFiles,
|
|
32
33
|
xliffDirSegments: () => xliffDirSegments
|
|
33
34
|
});
|
|
@@ -336,11 +337,10 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
336
337
|
}
|
|
337
338
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
338
339
|
}
|
|
339
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
340
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
340
341
|
return filePaths.filter((p) => {
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
342
|
+
const stem = (0, import_path.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
343
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
344
344
|
});
|
|
345
345
|
}
|
|
346
346
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
@@ -350,23 +350,21 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
350
350
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
351
351
|
});
|
|
352
352
|
}
|
|
353
|
-
|
|
354
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
353
|
+
function parseXliffFilename(filePath) {
|
|
355
354
|
const filename = (0, import_path.basename)(filePath);
|
|
356
355
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
357
356
|
const project = match?.[1] ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
358
|
-
|
|
359
|
-
return { project, locale, filenameLocale: match?.[2] };
|
|
357
|
+
return { project, locale: match?.[2] };
|
|
360
358
|
}
|
|
361
359
|
function isMsgProjectLike(value) {
|
|
362
360
|
if (!value || typeof value !== "object") return false;
|
|
363
361
|
const loc = value.locales?.targetLocales;
|
|
364
362
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
365
363
|
}
|
|
364
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
366
365
|
async function importMsgProject(projectsDir, projectName) {
|
|
367
366
|
const basePath = (0, import_path.join)(projectsDir, projectName);
|
|
368
|
-
const
|
|
369
|
-
for (const ext of exts) {
|
|
367
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
370
368
|
const p = `${basePath}${ext}`;
|
|
371
369
|
if ((0, import_fs.existsSync)(p)) {
|
|
372
370
|
const url = (0, import_url2.pathToFileURL)(p).href;
|
|
@@ -380,6 +378,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
380
378
|
}
|
|
381
379
|
throw new Error(`Project file not found: ${projectName}`);
|
|
382
380
|
}
|
|
381
|
+
function projectFileExists(projectsDir, projectName) {
|
|
382
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => (0, import_fs.existsSync)((0, import_path.join)(projectsDir, `${projectName}${ext}`)));
|
|
383
|
+
}
|
|
383
384
|
var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
384
385
|
ignoreAttributes: false,
|
|
385
386
|
attributeNamePrefix: "@_",
|
|
@@ -611,14 +612,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
611
612
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
612
613
|
return null;
|
|
613
614
|
}
|
|
615
|
+
const locale = xliffTrgLang;
|
|
616
|
+
let resolvedProject = projectName;
|
|
614
617
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
615
|
-
|
|
616
|
-
|
|
618
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
619
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
620
|
+
resolvedProject = dottedProject;
|
|
621
|
+
} else {
|
|
622
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
617
625
|
}
|
|
618
|
-
const locale = xliffTrgLang;
|
|
619
626
|
let project;
|
|
620
627
|
try {
|
|
621
|
-
project = await importMsgProject(projectsDir,
|
|
628
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
622
629
|
} catch {
|
|
623
630
|
return null;
|
|
624
631
|
}
|
|
@@ -642,7 +649,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
642
649
|
}
|
|
643
650
|
}
|
|
644
651
|
if (resources.length === 0) return null;
|
|
645
|
-
return { project:
|
|
652
|
+
return { project: resolvedProject, locale, resources };
|
|
646
653
|
}
|
|
647
654
|
async function writeTranslationFiles(translationsDir, result) {
|
|
648
655
|
const { project, locale, resources } = result;
|
|
@@ -664,6 +671,7 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
664
671
|
parseXliff20,
|
|
665
672
|
parseXliffFilename,
|
|
666
673
|
processXliffFile,
|
|
674
|
+
projectFileExists,
|
|
667
675
|
writeTranslationFiles,
|
|
668
676
|
xliffDirSegments
|
|
669
677
|
});
|
|
@@ -20,13 +20,15 @@ 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`), or whose whole file name stem is the project (a
|
|
25
|
+
* dotted name such as `my.app.xliff`), wherever they sit. Directories are not
|
|
26
|
+
* matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
27
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
28
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
29
|
* @returns Filtered array of paths
|
|
28
30
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
31
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
32
|
/**
|
|
31
33
|
* Filters XLIFF file paths by locale.
|
|
32
34
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,19 +39,18 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
39
|
*/
|
|
38
40
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
41
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* Extracts project name and locale from an XLIFF file name
|
|
43
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
44
|
+
*
|
|
45
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
46
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
47
|
+
* locale from directories let short names like `app` win (#55).
|
|
48
|
+
* @param filePath - Path to an XLIFF file
|
|
49
|
+
* @returns Object with project and the file name's locale, if any
|
|
48
50
|
*/
|
|
49
|
-
declare function parseXliffFilename(filePath: string
|
|
51
|
+
declare function parseXliffFilename(filePath: string): {
|
|
50
52
|
project: string;
|
|
51
53
|
locale?: string;
|
|
52
|
-
filenameLocale?: string;
|
|
53
54
|
};
|
|
54
55
|
/**
|
|
55
56
|
* Dynamically imports MsgProject from i18n/projects by project name.
|
|
@@ -63,6 +64,12 @@ declare function importMsgProject(projectsDir: string, projectName: string): Pro
|
|
|
63
64
|
targetLocales: Record<string, string[]>;
|
|
64
65
|
};
|
|
65
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether `i18n/projects` has a project file (`.ts` or `.js`) with this name.
|
|
69
|
+
* @param projectsDir - Absolute path to i18n/projects
|
|
70
|
+
* @param projectName - Project name (file name without extension)
|
|
71
|
+
*/
|
|
72
|
+
declare function projectFileExists(projectsDir: string, projectName: string): boolean;
|
|
66
73
|
/**
|
|
67
74
|
* Parses XLIFF 2.x XML string to a JavaScript object (2.0 and 2.2 supported).
|
|
68
75
|
* @param xml - XLIFF XML string
|
|
@@ -113,4 +120,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
113
120
|
*/
|
|
114
121
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
115
122
|
|
|
116
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles, xliffDirSegments };
|
|
123
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles, xliffDirSegments };
|
|
@@ -20,13 +20,15 @@ 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`), or whose whole file name stem is the project (a
|
|
25
|
+
* dotted name such as `my.app.xliff`), wherever they sit. Directories are not
|
|
26
|
+
* matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
27
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
28
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
29
|
* @returns Filtered array of paths
|
|
28
30
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
31
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
32
|
/**
|
|
31
33
|
* Filters XLIFF file paths by locale.
|
|
32
34
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,19 +39,18 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
39
|
*/
|
|
38
40
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
41
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* Extracts project name and locale from an XLIFF file name
|
|
43
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
44
|
+
*
|
|
45
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
46
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
47
|
+
* locale from directories let short names like `app` win (#55).
|
|
48
|
+
* @param filePath - Path to an XLIFF file
|
|
49
|
+
* @returns Object with project and the file name's locale, if any
|
|
48
50
|
*/
|
|
49
|
-
declare function parseXliffFilename(filePath: string
|
|
51
|
+
declare function parseXliffFilename(filePath: string): {
|
|
50
52
|
project: string;
|
|
51
53
|
locale?: string;
|
|
52
|
-
filenameLocale?: string;
|
|
53
54
|
};
|
|
54
55
|
/**
|
|
55
56
|
* Dynamically imports MsgProject from i18n/projects by project name.
|
|
@@ -63,6 +64,12 @@ declare function importMsgProject(projectsDir: string, projectName: string): Pro
|
|
|
63
64
|
targetLocales: Record<string, string[]>;
|
|
64
65
|
};
|
|
65
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Whether `i18n/projects` has a project file (`.ts` or `.js`) with this name.
|
|
69
|
+
* @param projectsDir - Absolute path to i18n/projects
|
|
70
|
+
* @param projectName - Project name (file name without extension)
|
|
71
|
+
*/
|
|
72
|
+
declare function projectFileExists(projectsDir: string, projectName: string): boolean;
|
|
66
73
|
/**
|
|
67
74
|
* Parses XLIFF 2.x XML string to a JavaScript object (2.0 and 2.2 supported).
|
|
68
75
|
* @param xml - XLIFF XML string
|
|
@@ -113,4 +120,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
113
120
|
*/
|
|
114
121
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
115
122
|
|
|
116
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles, xliffDirSegments };
|
|
123
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles, xliffDirSegments };
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
parseXliff20,
|
|
8
8
|
parseXliffFilename,
|
|
9
9
|
processXliffFile,
|
|
10
|
+
projectFileExists,
|
|
10
11
|
writeTranslationFiles,
|
|
11
12
|
xliffDirSegments
|
|
12
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-OJ3XG3HP.mjs";
|
|
13
14
|
import "../chunk-Q775ZGC5.mjs";
|
|
14
15
|
import "../chunk-QMSV2PP2.mjs";
|
|
15
16
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -24,6 +25,7 @@ export {
|
|
|
24
25
|
parseXliff20,
|
|
25
26
|
parseXliffFilename,
|
|
26
27
|
processXliffFile,
|
|
28
|
+
projectFileExists,
|
|
27
29
|
writeTranslationFiles,
|
|
28
30
|
xliffDirSegments
|
|
29
31
|
};
|