@worldware/msg-cli 0.6.5 → 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 +3 -2
- package/dist/{chunk-OUQSCR6C.mjs → chunk-4FXDFVEO.mjs} +37 -22
- package/dist/commands/import.cjs +37 -21
- package/dist/commands/import.mjs +3 -2
- package/dist/lib/import-helpers.cjs +39 -24
- package/dist/lib/import-helpers.d.mts +17 -20
- package/dist/lib/import-helpers.d.ts +17 -20
- package/dist/lib/import-helpers.mjs +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -311,8 +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
|
-
-
|
|
315
|
-
- `--
|
|
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` 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.
|
|
316
317
|
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
317
318
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
318
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,23 +36,29 @@ 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
|
-
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
48
|
-
}
|
|
49
|
-
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
50
40
|
return filePaths.filter((p) => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
41
|
+
const stem = basename(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
42
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
54
43
|
});
|
|
55
44
|
}
|
|
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]);
|
|
61
|
+
}
|
|
56
62
|
function parseXliffFilename(filePath) {
|
|
57
63
|
const filename = basename(filePath);
|
|
58
64
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
@@ -64,10 +70,10 @@ function isMsgProjectLike(value) {
|
|
|
64
70
|
const loc = value.locales?.targetLocales;
|
|
65
71
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
66
72
|
}
|
|
73
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
67
74
|
async function importMsgProject(projectsDir, projectName) {
|
|
68
75
|
const basePath = join(projectsDir, projectName);
|
|
69
|
-
const
|
|
70
|
-
for (const ext of exts) {
|
|
76
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
71
77
|
const p = `${basePath}${ext}`;
|
|
72
78
|
if (existsSync(p)) {
|
|
73
79
|
const url = pathToFileURL(p).href;
|
|
@@ -81,6 +87,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
81
87
|
}
|
|
82
88
|
throw new Error(`Project file not found: ${projectName}`);
|
|
83
89
|
}
|
|
90
|
+
function projectFileExists(projectsDir, projectName) {
|
|
91
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => existsSync(join(projectsDir, `${projectName}${ext}`)));
|
|
92
|
+
}
|
|
84
93
|
var xmlParser = new XMLParser({
|
|
85
94
|
ignoreAttributes: false,
|
|
86
95
|
attributeNamePrefix: "@_",
|
|
@@ -312,14 +321,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
312
321
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
313
322
|
return null;
|
|
314
323
|
}
|
|
324
|
+
const locale = xliffTrgLang;
|
|
325
|
+
let resolvedProject = projectName;
|
|
315
326
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
316
|
-
|
|
317
|
-
|
|
327
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
328
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
329
|
+
resolvedProject = dottedProject;
|
|
330
|
+
} else {
|
|
331
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
318
334
|
}
|
|
319
|
-
const locale = xliffTrgLang;
|
|
320
335
|
let project;
|
|
321
336
|
try {
|
|
322
|
-
project = await importMsgProject(projectsDir,
|
|
337
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
323
338
|
} catch {
|
|
324
339
|
return null;
|
|
325
340
|
}
|
|
@@ -343,7 +358,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
343
358
|
}
|
|
344
359
|
}
|
|
345
360
|
if (resources.length === 0) return null;
|
|
346
|
-
return { project:
|
|
361
|
+
return { project: resolvedProject, locale, resources };
|
|
347
362
|
}
|
|
348
363
|
async function writeTranslationFiles(translationsDir, result) {
|
|
349
364
|
const { project, locale, resources } = result;
|
|
@@ -358,11 +373,11 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
358
373
|
|
|
359
374
|
export {
|
|
360
375
|
findXliffFilePaths,
|
|
361
|
-
xliffDirSegments,
|
|
362
376
|
filterXliffPathsByProject,
|
|
363
377
|
filterXliffPathsByLocale,
|
|
364
378
|
parseXliffFilename,
|
|
365
379
|
importMsgProject,
|
|
380
|
+
projectFileExists,
|
|
366
381
|
parseXliff20,
|
|
367
382
|
extractResourceFromXliffFile,
|
|
368
383
|
processXliffFile,
|
package/dist/commands/import.cjs
CHANGED
|
@@ -388,23 +388,29 @@ 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
|
-
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
400
|
-
}
|
|
401
|
-
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
402
392
|
return filePaths.filter((p) => {
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
393
|
+
const stem = (0, import_path2.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
394
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
406
395
|
});
|
|
407
396
|
}
|
|
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]);
|
|
413
|
+
}
|
|
408
414
|
function parseXliffFilename(filePath) {
|
|
409
415
|
const filename = (0, import_path2.basename)(filePath);
|
|
410
416
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
@@ -416,10 +422,10 @@ function isMsgProjectLike(value) {
|
|
|
416
422
|
const loc = value.locales?.targetLocales;
|
|
417
423
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
418
424
|
}
|
|
425
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
419
426
|
async function importMsgProject(projectsDir, projectName) {
|
|
420
427
|
const basePath = (0, import_path2.join)(projectsDir, projectName);
|
|
421
|
-
const
|
|
422
|
-
for (const ext of exts) {
|
|
428
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
423
429
|
const p = `${basePath}${ext}`;
|
|
424
430
|
if ((0, import_fs2.existsSync)(p)) {
|
|
425
431
|
const url = (0, import_url2.pathToFileURL)(p).href;
|
|
@@ -433,6 +439,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
433
439
|
}
|
|
434
440
|
throw new Error(`Project file not found: ${projectName}`);
|
|
435
441
|
}
|
|
442
|
+
function projectFileExists(projectsDir, projectName) {
|
|
443
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => (0, import_fs2.existsSync)((0, import_path2.join)(projectsDir, `${projectName}${ext}`)));
|
|
444
|
+
}
|
|
436
445
|
var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
437
446
|
ignoreAttributes: false,
|
|
438
447
|
attributeNamePrefix: "@_",
|
|
@@ -664,14 +673,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
664
673
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
665
674
|
return null;
|
|
666
675
|
}
|
|
676
|
+
const locale = xliffTrgLang;
|
|
677
|
+
let resolvedProject = projectName;
|
|
667
678
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
668
|
-
|
|
669
|
-
|
|
679
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
680
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
681
|
+
resolvedProject = dottedProject;
|
|
682
|
+
} else {
|
|
683
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
670
686
|
}
|
|
671
|
-
const locale = xliffTrgLang;
|
|
672
687
|
let project;
|
|
673
688
|
try {
|
|
674
|
-
project = await importMsgProject(projectsDir,
|
|
689
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
675
690
|
} catch {
|
|
676
691
|
return null;
|
|
677
692
|
}
|
|
@@ -695,7 +710,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
695
710
|
}
|
|
696
711
|
}
|
|
697
712
|
if (resources.length === 0) return null;
|
|
698
|
-
return { project:
|
|
713
|
+
return { project: resolvedProject, locale, resources };
|
|
699
714
|
}
|
|
700
715
|
async function writeTranslationFiles(translationsDir, result) {
|
|
701
716
|
const { project, locale, resources } = result;
|
|
@@ -763,7 +778,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
763
778
|
this.log(`Filtered to project '${flags.project}'.`);
|
|
764
779
|
}
|
|
765
780
|
if (flags.language) {
|
|
766
|
-
filePaths = filterXliffPathsByLocale(filePaths, flags.language
|
|
781
|
+
filePaths = await filterXliffPathsByLocale(filePaths, flags.language);
|
|
767
782
|
if (filePaths.length === 0) {
|
|
768
783
|
this.log(`No XLIFF files found for language '${flags.language}'. Nothing to import.`);
|
|
769
784
|
return;
|
|
@@ -782,6 +797,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
782
797
|
filenameLocale,
|
|
783
798
|
(message) => this.warn(message)
|
|
784
799
|
);
|
|
800
|
+
if (result && flags.project && result.project !== flags.project) continue;
|
|
785
801
|
if (result) {
|
|
786
802
|
await writeTranslationFiles(translationsDir, result);
|
|
787
803
|
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-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;
|
|
@@ -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,8 +28,8 @@ __export(import_helpers_exports, {
|
|
|
28
28
|
parseXliff20: () => parseXliff20,
|
|
29
29
|
parseXliffFilename: () => parseXliffFilename,
|
|
30
30
|
processXliffFile: () => processXliffFile,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
projectFileExists: () => projectFileExists,
|
|
32
|
+
writeTranslationFiles: () => writeTranslationFiles
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(import_helpers_exports);
|
|
35
35
|
var import_msg2 = require("@worldware/msg");
|
|
@@ -329,23 +329,29 @@ async function findXliffFilePaths(directory) {
|
|
|
329
329
|
}
|
|
330
330
|
return result;
|
|
331
331
|
}
|
|
332
|
-
function xliffDirSegments(xliffDir, filePath) {
|
|
333
|
-
const rel = (0, import_path.relative)(xliffDir, filePath);
|
|
334
|
-
if (!rel || rel === ".." || rel.startsWith(`..${import_path.sep}`) || (0, import_path.isAbsolute)(rel)) {
|
|
335
|
-
return [];
|
|
336
|
-
}
|
|
337
|
-
return rel.split(/[/\\]/).slice(0, -1);
|
|
338
|
-
}
|
|
339
332
|
function filterXliffPathsByProject(filePaths, projectName) {
|
|
340
|
-
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
341
|
-
}
|
|
342
|
-
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
343
333
|
return filePaths.filter((p) => {
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
334
|
+
const stem = (0, import_path.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
|
|
335
|
+
return parseXliffFilename(p).project === projectName || stem === projectName;
|
|
347
336
|
});
|
|
348
337
|
}
|
|
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]);
|
|
354
|
+
}
|
|
349
355
|
function parseXliffFilename(filePath) {
|
|
350
356
|
const filename = (0, import_path.basename)(filePath);
|
|
351
357
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
@@ -357,10 +363,10 @@ function isMsgProjectLike(value) {
|
|
|
357
363
|
const loc = value.locales?.targetLocales;
|
|
358
364
|
return typeof loc === "object" && loc !== null && !Array.isArray(loc);
|
|
359
365
|
}
|
|
366
|
+
var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
|
|
360
367
|
async function importMsgProject(projectsDir, projectName) {
|
|
361
368
|
const basePath = (0, import_path.join)(projectsDir, projectName);
|
|
362
|
-
const
|
|
363
|
-
for (const ext of exts) {
|
|
369
|
+
for (const ext of PROJECT_FILE_EXTENSIONS) {
|
|
364
370
|
const p = `${basePath}${ext}`;
|
|
365
371
|
if ((0, import_fs.existsSync)(p)) {
|
|
366
372
|
const url = (0, import_url2.pathToFileURL)(p).href;
|
|
@@ -374,6 +380,9 @@ async function importMsgProject(projectsDir, projectName) {
|
|
|
374
380
|
}
|
|
375
381
|
throw new Error(`Project file not found: ${projectName}`);
|
|
376
382
|
}
|
|
383
|
+
function projectFileExists(projectsDir, projectName) {
|
|
384
|
+
return PROJECT_FILE_EXTENSIONS.some((ext) => (0, import_fs.existsSync)((0, import_path.join)(projectsDir, `${projectName}${ext}`)));
|
|
385
|
+
}
|
|
377
386
|
var xmlParser = new import_fast_xml_parser.XMLParser({
|
|
378
387
|
ignoreAttributes: false,
|
|
379
388
|
attributeNamePrefix: "@_",
|
|
@@ -605,14 +614,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
605
614
|
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
606
615
|
return null;
|
|
607
616
|
}
|
|
617
|
+
const locale = xliffTrgLang;
|
|
618
|
+
let resolvedProject = projectName;
|
|
608
619
|
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
609
|
-
|
|
610
|
-
|
|
620
|
+
const dottedProject = `${projectName}.${filenameLocale}`;
|
|
621
|
+
if (projectFileExists(projectsDir, dottedProject)) {
|
|
622
|
+
resolvedProject = dottedProject;
|
|
623
|
+
} else {
|
|
624
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
611
627
|
}
|
|
612
|
-
const locale = xliffTrgLang;
|
|
613
628
|
let project;
|
|
614
629
|
try {
|
|
615
|
-
project = await importMsgProject(projectsDir,
|
|
630
|
+
project = await importMsgProject(projectsDir, resolvedProject);
|
|
616
631
|
} catch {
|
|
617
632
|
return null;
|
|
618
633
|
}
|
|
@@ -636,7 +651,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
|
|
|
636
651
|
}
|
|
637
652
|
}
|
|
638
653
|
if (resources.length === 0) return null;
|
|
639
|
-
return { project:
|
|
654
|
+
return { project: resolvedProject, locale, resources };
|
|
640
655
|
}
|
|
641
656
|
async function writeTranslationFiles(translationsDir, result) {
|
|
642
657
|
const { project, locale, resources } = result;
|
|
@@ -658,6 +673,6 @@ async function writeTranslationFiles(translationsDir, result) {
|
|
|
658
673
|
parseXliff20,
|
|
659
674
|
parseXliffFilename,
|
|
660
675
|
processXliffFile,
|
|
661
|
-
|
|
662
|
-
|
|
676
|
+
projectFileExists,
|
|
677
|
+
writeTranslationFiles
|
|
663
678
|
});
|
|
@@ -6,37 +6,28 @@ 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`,
|
|
24
|
-
* `project.locale.xliff`),
|
|
25
|
-
*
|
|
12
|
+
* `project.locale.xliff`), or whose whole file name stem is the project (a
|
|
13
|
+
* dotted name such as `my.app.xliff`), wherever they sit. Directories are not
|
|
14
|
+
* matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
26
15
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
27
16
|
* @param projectName - Project name to filter by
|
|
28
17
|
* @returns Filtered array of paths
|
|
29
18
|
*/
|
|
30
19
|
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
31
20
|
/**
|
|
32
|
-
* Filters XLIFF file paths by locale
|
|
33
|
-
*
|
|
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.
|
|
34
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
35
27
|
* @param locale - Locale code to filter by
|
|
36
|
-
* @
|
|
37
|
-
* @returns Filtered array of paths
|
|
28
|
+
* @returns Filtered array of paths, in input order
|
|
38
29
|
*/
|
|
39
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string
|
|
30
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): Promise<string[]>;
|
|
40
31
|
/**
|
|
41
32
|
* Extracts project name and locale from an XLIFF file name
|
|
42
33
|
* (`project.locale.xliff` or `project.xliff`).
|
|
@@ -63,6 +54,12 @@ declare function importMsgProject(projectsDir: string, projectName: string): Pro
|
|
|
63
54
|
targetLocales: Record<string, string[]>;
|
|
64
55
|
};
|
|
65
56
|
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Whether `i18n/projects` has a project file (`.ts` or `.js`) with this name.
|
|
59
|
+
* @param projectsDir - Absolute path to i18n/projects
|
|
60
|
+
* @param projectName - Project name (file name without extension)
|
|
61
|
+
*/
|
|
62
|
+
declare function projectFileExists(projectsDir: string, projectName: string): boolean;
|
|
66
63
|
/**
|
|
67
64
|
* Parses XLIFF 2.x XML string to a JavaScript object (2.0 and 2.2 supported).
|
|
68
65
|
* @param xml - XLIFF XML string
|
|
@@ -113,4 +110,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
113
110
|
*/
|
|
114
111
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
115
112
|
|
|
116
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile,
|
|
113
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles };
|
|
@@ -6,37 +6,28 @@ 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`,
|
|
24
|
-
* `project.locale.xliff`),
|
|
25
|
-
*
|
|
12
|
+
* `project.locale.xliff`), or whose whole file name stem is the project (a
|
|
13
|
+
* dotted name such as `my.app.xliff`), wherever they sit. Directories are not
|
|
14
|
+
* matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
26
15
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
27
16
|
* @param projectName - Project name to filter by
|
|
28
17
|
* @returns Filtered array of paths
|
|
29
18
|
*/
|
|
30
19
|
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
31
20
|
/**
|
|
32
|
-
* Filters XLIFF file paths by locale
|
|
33
|
-
*
|
|
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.
|
|
34
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
35
27
|
* @param locale - Locale code to filter by
|
|
36
|
-
* @
|
|
37
|
-
* @returns Filtered array of paths
|
|
28
|
+
* @returns Filtered array of paths, in input order
|
|
38
29
|
*/
|
|
39
|
-
declare function filterXliffPathsByLocale(filePaths: string[], locale: string
|
|
30
|
+
declare function filterXliffPathsByLocale(filePaths: string[], locale: string): Promise<string[]>;
|
|
40
31
|
/**
|
|
41
32
|
* Extracts project name and locale from an XLIFF file name
|
|
42
33
|
* (`project.locale.xliff` or `project.xliff`).
|
|
@@ -63,6 +54,12 @@ declare function importMsgProject(projectsDir: string, projectName: string): Pro
|
|
|
63
54
|
targetLocales: Record<string, string[]>;
|
|
64
55
|
};
|
|
65
56
|
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Whether `i18n/projects` has a project file (`.ts` or `.js`) with this name.
|
|
59
|
+
* @param projectsDir - Absolute path to i18n/projects
|
|
60
|
+
* @param projectName - Project name (file name without extension)
|
|
61
|
+
*/
|
|
62
|
+
declare function projectFileExists(projectsDir: string, projectName: string): boolean;
|
|
66
63
|
/**
|
|
67
64
|
* Parses XLIFF 2.x XML string to a JavaScript object (2.0 and 2.2 supported).
|
|
68
65
|
* @param xml - XLIFF XML string
|
|
@@ -113,4 +110,4 @@ declare function processXliffFile(xliffPath: string, projectsDir: string, projec
|
|
|
113
110
|
*/
|
|
114
111
|
declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
|
|
115
112
|
|
|
116
|
-
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile,
|
|
113
|
+
export { type ImportResult, type XmlSpace, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, projectFileExists, writeTranslationFiles };
|
|
@@ -7,9 +7,9 @@ import {
|
|
|
7
7
|
parseXliff20,
|
|
8
8
|
parseXliffFilename,
|
|
9
9
|
processXliffFile,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from "../chunk-
|
|
10
|
+
projectFileExists,
|
|
11
|
+
writeTranslationFiles
|
|
12
|
+
} from "../chunk-4FXDFVEO.mjs";
|
|
13
13
|
import "../chunk-Q775ZGC5.mjs";
|
|
14
14
|
import "../chunk-QMSV2PP2.mjs";
|
|
15
15
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -24,6 +24,6 @@ export {
|
|
|
24
24
|
parseXliff20,
|
|
25
25
|
parseXliffFilename,
|
|
26
26
|
processXliffFile,
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
projectFileExists,
|
|
28
|
+
writeTranslationFiles
|
|
29
29
|
};
|