@worldware/msg-cli 0.6.5 → 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 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` 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`).
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.
315
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.
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.
@@ -44,7 +44,10 @@ function xliffDirSegments(xliffDir, filePath) {
44
44
  return rel.split(/[/\\]/).slice(0, -1);
45
45
  }
46
46
  function filterXliffPathsByProject(filePaths, projectName) {
47
- return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
47
+ return filePaths.filter((p) => {
48
+ const stem = basename(p).replace(/\.(?:xliff|xlf)$/i, "");
49
+ return parseXliffFilename(p).project === projectName || stem === projectName;
50
+ });
48
51
  }
49
52
  function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
50
53
  return filePaths.filter((p) => {
@@ -64,10 +67,10 @@ function isMsgProjectLike(value) {
64
67
  const loc = value.locales?.targetLocales;
65
68
  return typeof loc === "object" && loc !== null && !Array.isArray(loc);
66
69
  }
70
+ var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
67
71
  async function importMsgProject(projectsDir, projectName) {
68
72
  const basePath = join(projectsDir, projectName);
69
- const exts = [".ts", ".js"];
70
- for (const ext of exts) {
73
+ for (const ext of PROJECT_FILE_EXTENSIONS) {
71
74
  const p = `${basePath}${ext}`;
72
75
  if (existsSync(p)) {
73
76
  const url = pathToFileURL(p).href;
@@ -81,6 +84,9 @@ async function importMsgProject(projectsDir, projectName) {
81
84
  }
82
85
  throw new Error(`Project file not found: ${projectName}`);
83
86
  }
87
+ function projectFileExists(projectsDir, projectName) {
88
+ return PROJECT_FILE_EXTENSIONS.some((ext) => existsSync(join(projectsDir, `${projectName}${ext}`)));
89
+ }
84
90
  var xmlParser = new XMLParser({
85
91
  ignoreAttributes: false,
86
92
  attributeNamePrefix: "@_",
@@ -312,14 +318,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
312
318
  warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
313
319
  return null;
314
320
  }
321
+ const locale = xliffTrgLang;
322
+ let resolvedProject = projectName;
315
323
  if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
316
- warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
317
- return null;
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
+ }
318
331
  }
319
- const locale = xliffTrgLang;
320
332
  let project;
321
333
  try {
322
- project = await importMsgProject(projectsDir, projectName);
334
+ project = await importMsgProject(projectsDir, resolvedProject);
323
335
  } catch {
324
336
  return null;
325
337
  }
@@ -343,7 +355,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
343
355
  }
344
356
  }
345
357
  if (resources.length === 0) return null;
346
- return { project: projectName, locale, resources };
358
+ return { project: resolvedProject, locale, resources };
347
359
  }
348
360
  async function writeTranslationFiles(translationsDir, result) {
349
361
  const { project, locale, resources } = result;
@@ -363,6 +375,7 @@ export {
363
375
  filterXliffPathsByLocale,
364
376
  parseXliffFilename,
365
377
  importMsgProject,
378
+ projectFileExists,
366
379
  parseXliff20,
367
380
  extractResourceFromXliffFile,
368
381
  processXliffFile,
@@ -396,7 +396,10 @@ function xliffDirSegments(xliffDir, filePath) {
396
396
  return rel.split(/[/\\]/).slice(0, -1);
397
397
  }
398
398
  function filterXliffPathsByProject(filePaths, projectName) {
399
- return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
399
+ return filePaths.filter((p) => {
400
+ const stem = (0, import_path2.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
401
+ return parseXliffFilename(p).project === projectName || stem === projectName;
402
+ });
400
403
  }
401
404
  function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
402
405
  return filePaths.filter((p) => {
@@ -416,10 +419,10 @@ function isMsgProjectLike(value) {
416
419
  const loc = value.locales?.targetLocales;
417
420
  return typeof loc === "object" && loc !== null && !Array.isArray(loc);
418
421
  }
422
+ var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
419
423
  async function importMsgProject(projectsDir, projectName) {
420
424
  const basePath = (0, import_path2.join)(projectsDir, projectName);
421
- const exts = [".ts", ".js"];
422
- for (const ext of exts) {
425
+ for (const ext of PROJECT_FILE_EXTENSIONS) {
423
426
  const p = `${basePath}${ext}`;
424
427
  if ((0, import_fs2.existsSync)(p)) {
425
428
  const url = (0, import_url2.pathToFileURL)(p).href;
@@ -433,6 +436,9 @@ async function importMsgProject(projectsDir, projectName) {
433
436
  }
434
437
  throw new Error(`Project file not found: ${projectName}`);
435
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
+ }
436
442
  var xmlParser = new import_fast_xml_parser.XMLParser({
437
443
  ignoreAttributes: false,
438
444
  attributeNamePrefix: "@_",
@@ -664,14 +670,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
664
670
  warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
665
671
  return null;
666
672
  }
673
+ const locale = xliffTrgLang;
674
+ let resolvedProject = projectName;
667
675
  if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
668
- warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
669
- return null;
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
+ }
670
683
  }
671
- const locale = xliffTrgLang;
672
684
  let project;
673
685
  try {
674
- project = await importMsgProject(projectsDir, projectName);
686
+ project = await importMsgProject(projectsDir, resolvedProject);
675
687
  } catch {
676
688
  return null;
677
689
  }
@@ -695,7 +707,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
695
707
  }
696
708
  }
697
709
  if (resources.length === 0) return null;
698
- return { project: projectName, locale, resources };
710
+ return { project: resolvedProject, locale, resources };
699
711
  }
700
712
  async function writeTranslationFiles(translationsDir, result) {
701
713
  const { project, locale, resources } = result;
@@ -782,6 +794,7 @@ var Import = class _Import extends import_core.Command {
782
794
  filenameLocale,
783
795
  (message) => this.warn(message)
784
796
  );
797
+ if (result && flags.project && result.project !== flags.project) continue;
785
798
  if (result) {
786
799
  await writeTranslationFiles(translationsDir, result);
787
800
  for (const { title } of result.resources) {
@@ -5,7 +5,7 @@ import {
5
5
  parseXliffFilename,
6
6
  processXliffFile,
7
7
  writeTranslationFiles
8
- } from "../chunk-OUQSCR6C.mjs";
8
+ } from "../chunk-OJ3XG3HP.mjs";
9
9
  import "../chunk-Q775ZGC5.mjs";
10
10
  import "../chunk-QMSV2PP2.mjs";
11
11
  import "../chunk-Z7H6FUD6.mjs";
@@ -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
  });
@@ -337,7 +338,10 @@ function xliffDirSegments(xliffDir, filePath) {
337
338
  return rel.split(/[/\\]/).slice(0, -1);
338
339
  }
339
340
  function filterXliffPathsByProject(filePaths, projectName) {
340
- return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
341
+ return filePaths.filter((p) => {
342
+ const stem = (0, import_path.basename)(p).replace(/\.(?:xliff|xlf)$/i, "");
343
+ return parseXliffFilename(p).project === projectName || stem === projectName;
344
+ });
341
345
  }
342
346
  function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
343
347
  return filePaths.filter((p) => {
@@ -357,10 +361,10 @@ function isMsgProjectLike(value) {
357
361
  const loc = value.locales?.targetLocales;
358
362
  return typeof loc === "object" && loc !== null && !Array.isArray(loc);
359
363
  }
364
+ var PROJECT_FILE_EXTENSIONS = [".ts", ".js"];
360
365
  async function importMsgProject(projectsDir, projectName) {
361
366
  const basePath = (0, import_path.join)(projectsDir, projectName);
362
- const exts = [".ts", ".js"];
363
- for (const ext of exts) {
367
+ for (const ext of PROJECT_FILE_EXTENSIONS) {
364
368
  const p = `${basePath}${ext}`;
365
369
  if ((0, import_fs.existsSync)(p)) {
366
370
  const url = (0, import_url2.pathToFileURL)(p).href;
@@ -374,6 +378,9 @@ async function importMsgProject(projectsDir, projectName) {
374
378
  }
375
379
  throw new Error(`Project file not found: ${projectName}`);
376
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
+ }
377
384
  var xmlParser = new import_fast_xml_parser.XMLParser({
378
385
  ignoreAttributes: false,
379
386
  attributeNamePrefix: "@_",
@@ -605,14 +612,20 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
605
612
  warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
606
613
  return null;
607
614
  }
615
+ const locale = xliffTrgLang;
616
+ let resolvedProject = projectName;
608
617
  if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
609
- warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
610
- return null;
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
+ }
611
625
  }
612
- const locale = xliffTrgLang;
613
626
  let project;
614
627
  try {
615
- project = await importMsgProject(projectsDir, projectName);
628
+ project = await importMsgProject(projectsDir, resolvedProject);
616
629
  } catch {
617
630
  return null;
618
631
  }
@@ -636,7 +649,7 @@ async function processXliffFile(xliffPath, projectsDir, projectName, filenameLoc
636
649
  }
637
650
  }
638
651
  if (resources.length === 0) return null;
639
- return { project: projectName, locale, resources };
652
+ return { project: resolvedProject, locale, resources };
640
653
  }
641
654
  async function writeTranslationFiles(translationsDir, result) {
642
655
  const { project, locale, resources } = result;
@@ -658,6 +671,7 @@ async function writeTranslationFiles(translationsDir, result) {
658
671
  parseXliff20,
659
672
  parseXliffFilename,
660
673
  processXliffFile,
674
+ projectFileExists,
661
675
  writeTranslationFiles,
662
676
  xliffDirSegments
663
677
  });
@@ -21,8 +21,9 @@ declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
21
21
  /**
22
22
  * Filters XLIFF file paths by project name.
23
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
+ * `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`.
26
27
  * @param filePaths - Array of absolute XLIFF file paths
27
28
  * @param projectName - Project name to filter by
28
29
  * @returns Filtered array of paths
@@ -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 };
@@ -21,8 +21,9 @@ declare function xliffDirSegments(xliffDir: string, filePath: string): string[];
21
21
  /**
22
22
  * Filters XLIFF file paths by project name.
23
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
+ * `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`.
26
27
  * @param filePaths - Array of absolute XLIFF file paths
27
28
  * @param projectName - Project name to filter by
28
29
  * @returns Filtered array of paths
@@ -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-OUQSCR6C.mjs";
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg-cli",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "CLI for msg library",
5
5
  "main": "dist/commands/init.cjs",
6
6
  "module": "dist/commands/init.mjs",