@worldware/msg-cli 0.6.3 → 0.6.4
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 +15 -6
- package/dist/{chunk-KOTPQTLG.mjs → chunk-A6XUN4LX.mjs} +17 -8
- package/dist/commands/import.cjs +20 -14
- package/dist/commands/import.mjs +4 -7
- package/dist/lib/import-helpers.cjs +17 -8
- package/dist/lib/import-helpers.d.mts +9 -4
- package/dist/lib/import-helpers.d.ts +9 -4
- package/dist/lib/import-helpers.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -264,6 +264,14 @@ Import translations from bilingual XLIFF 2.0 or 2.2 files in `l10n/xliff` to JSO
|
|
|
264
264
|
- Unit `type` of `msg:NONE` / `msg:MF1` / `msg:MF2` (or bare `NONE` / `MF1` / `MF2`) is restored as the message `attributes.format`.
|
|
265
265
|
- Units with `pgs:switch` are reassembled from segment bodies (`<target>` when present): **MF1** → nested ICU MessageFormat 1; otherwise (including missing type) → MessageFormat 2 `.match`. Single-segment units are unchanged.
|
|
266
266
|
|
|
267
|
+
**Inline elements on import:** segment text is rebuilt in document order, keeping the text and spacing around inline elements (e.g. `Hello <pc id="1">bold</pc>!` → `Hello bold!`).
|
|
268
|
+
|
|
269
|
+
- `<pc>`, `<mrk>`, and unrecognized elements contribute their content (nested elements included).
|
|
270
|
+
- `<ph>`, `<sc>`, `<ec>` contribute their `equiv` attribute, else `disp`, else nothing (e.g. `<ph id="1" equiv="{name}"/>` → `{name}`).
|
|
271
|
+
- `<cp hex="…"/>` becomes that character, or U+FFFD if the hex value is not a valid code point.
|
|
272
|
+
- `<sm>` and `<em>` contribute nothing.
|
|
273
|
+
- CDATA text is kept in place.
|
|
274
|
+
|
|
267
275
|
**Whitespace on import:**
|
|
268
276
|
|
|
269
277
|
- `xml:space` is inherited per XLIFF 2: `<xliff>` → `<file>` → `<group>` → `<unit>` → `<source>`/`<target>`, defaulting to `default`. Invalid values are ignored.
|
|
@@ -300,14 +308,15 @@ msg import -l zh
|
|
|
300
308
|
**Behavior:**
|
|
301
309
|
|
|
302
310
|
- Recursively finds all `.xliff` and `.xlf` files under `l10n/xliff`.
|
|
303
|
-
-
|
|
304
|
-
-
|
|
305
|
-
-
|
|
311
|
+
- The project is taken from the filename (`myApp.zh.xliff` or `myApp.xliff` → `myApp`).
|
|
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
|
+
- 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` and `--language` match the filename or a directory under `l10n/xliff`. Directories above `l10n/xliff` are ignored, so a path like `/var/…` or `/tmp/…` never matches.
|
|
315
|
+
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
306
316
|
- Dynamically imports `MsgProject` from `i18n/projects` to validate target locales.
|
|
307
|
-
- Skips
|
|
308
|
-
- Skips files whose target locale is not in the project's `targetLocales`.
|
|
317
|
+
- Skips files whose `trgLang` is not in the project's `targetLocales`.
|
|
309
318
|
- Skips files when the matching project file does not exist or cannot be loaded.
|
|
310
|
-
- Writes JSON to `l10n/translations/<project>/<
|
|
319
|
+
- Writes JSON to `l10n/translations/<project>/<trgLang>/<title>.json`.
|
|
311
320
|
- Preserves existing translation files for other projects or locales when filtering.
|
|
312
321
|
- Errors on malformed XLIFF and logs each step.
|
|
313
322
|
|
|
@@ -63,7 +63,7 @@ function parseXliffFilename(filePath, xliffDir) {
|
|
|
63
63
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
64
64
|
const project = match?.[1] ?? basename(filename, extname(filename));
|
|
65
65
|
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
66
|
-
return { project, locale };
|
|
66
|
+
return { project, locale, filenameLocale: match?.[2] };
|
|
67
67
|
}
|
|
68
68
|
function isMsgProjectLike(value) {
|
|
69
69
|
if (!value || typeof value !== "object") return false;
|
|
@@ -307,7 +307,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
307
307
|
const proj = project;
|
|
308
308
|
return MsgResource.create(resourceData, proj);
|
|
309
309
|
}
|
|
310
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
310
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
311
|
+
}) {
|
|
312
|
+
const xml = await readFile(xliffPath, "utf-8");
|
|
313
|
+
const parsed = parseXliff20(xml);
|
|
314
|
+
const xliffRoot = parsed.xliff;
|
|
315
|
+
if (!xliffRoot) return null;
|
|
316
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
317
|
+
if (!xliffTrgLang) {
|
|
318
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
322
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const locale = xliffTrgLang;
|
|
311
326
|
let project;
|
|
312
327
|
try {
|
|
313
328
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -316,12 +331,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
316
331
|
}
|
|
317
332
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
318
333
|
if (!targetLocales.includes(locale)) return null;
|
|
319
|
-
const xml = await readFile(xliffPath, "utf-8");
|
|
320
|
-
const parsed = parseXliff20(xml);
|
|
321
|
-
const xliffRoot = parsed.xliff;
|
|
322
|
-
if (!xliffRoot) return null;
|
|
323
|
-
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
324
|
-
if (!xliffTrgLang) return null;
|
|
325
334
|
const fileEls = xliffRoot.file;
|
|
326
335
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
327
336
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
package/dist/commands/import.cjs
CHANGED
|
@@ -415,7 +415,7 @@ function parseXliffFilename(filePath, xliffDir) {
|
|
|
415
415
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
416
416
|
const project = match?.[1] ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
417
417
|
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
418
|
-
return { project, locale };
|
|
418
|
+
return { project, locale, filenameLocale: match?.[2] };
|
|
419
419
|
}
|
|
420
420
|
function isMsgProjectLike(value) {
|
|
421
421
|
if (!value || typeof value !== "object") return false;
|
|
@@ -659,7 +659,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
659
659
|
const proj = project;
|
|
660
660
|
return import_msg2.MsgResource.create(resourceData, proj);
|
|
661
661
|
}
|
|
662
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
662
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
663
|
+
}) {
|
|
664
|
+
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
665
|
+
const parsed = parseXliff20(xml);
|
|
666
|
+
const xliffRoot = parsed.xliff;
|
|
667
|
+
if (!xliffRoot) return null;
|
|
668
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
669
|
+
if (!xliffTrgLang) {
|
|
670
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
674
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
const locale = xliffTrgLang;
|
|
663
678
|
let project;
|
|
664
679
|
try {
|
|
665
680
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -668,12 +683,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
668
683
|
}
|
|
669
684
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
670
685
|
if (!targetLocales.includes(locale)) return null;
|
|
671
|
-
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
672
|
-
const parsed = parseXliff20(xml);
|
|
673
|
-
const xliffRoot = parsed.xliff;
|
|
674
|
-
if (!xliffRoot) return null;
|
|
675
|
-
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
676
|
-
if (!xliffTrgLang) return null;
|
|
677
686
|
const fileEls = xliffRoot.file;
|
|
678
687
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
679
688
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
|
@@ -770,17 +779,14 @@ var Import = class _Import extends import_core.Command {
|
|
|
770
779
|
let wroteCount = 0;
|
|
771
780
|
let errorCount = 0;
|
|
772
781
|
for (const xliffPath of filePaths) {
|
|
773
|
-
const { project: projectName,
|
|
774
|
-
if (!locale) {
|
|
775
|
-
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
776
|
-
continue;
|
|
777
|
-
}
|
|
782
|
+
const { project: projectName, filenameLocale } = parseXliffFilename(xliffPath, xliffDir);
|
|
778
783
|
try {
|
|
779
784
|
const result = await processXliffFile(
|
|
780
785
|
xliffPath,
|
|
781
786
|
projectsDir,
|
|
782
787
|
projectName,
|
|
783
|
-
|
|
788
|
+
filenameLocale,
|
|
789
|
+
(message) => this.warn(message)
|
|
784
790
|
);
|
|
785
791
|
if (result) {
|
|
786
792
|
await writeTranslationFiles(translationsDir, result);
|
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-A6XUN4LX.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
10
|
import "../chunk-QMSV2PP2.mjs";
|
|
11
11
|
import "../chunk-Z7H6FUD6.mjs";
|
|
@@ -82,17 +82,14 @@ 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,
|
|
86
|
-
if (!locale) {
|
|
87
|
-
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
85
|
+
const { project: projectName, filenameLocale } = parseXliffFilename(xliffPath, xliffDir);
|
|
90
86
|
try {
|
|
91
87
|
const result = await processXliffFile(
|
|
92
88
|
xliffPath,
|
|
93
89
|
projectsDir,
|
|
94
90
|
projectName,
|
|
95
|
-
|
|
91
|
+
filenameLocale,
|
|
92
|
+
(message) => this.warn(message)
|
|
96
93
|
);
|
|
97
94
|
if (result) {
|
|
98
95
|
await writeTranslationFiles(translationsDir, result);
|
|
@@ -356,7 +356,7 @@ function parseXliffFilename(filePath, xliffDir) {
|
|
|
356
356
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
357
357
|
const project = match?.[1] ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
358
358
|
const locale = match?.[2] ?? xliffDirSegments(xliffDir, filePath).find((part) => LOCALE_PATTERN.test(part));
|
|
359
|
-
return { project, locale };
|
|
359
|
+
return { project, locale, filenameLocale: match?.[2] };
|
|
360
360
|
}
|
|
361
361
|
function isMsgProjectLike(value) {
|
|
362
362
|
if (!value || typeof value !== "object") return false;
|
|
@@ -600,7 +600,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
600
600
|
const proj = project;
|
|
601
601
|
return import_msg2.MsgResource.create(resourceData, proj);
|
|
602
602
|
}
|
|
603
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
603
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
604
|
+
}) {
|
|
605
|
+
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
606
|
+
const parsed = parseXliff20(xml);
|
|
607
|
+
const xliffRoot = parsed.xliff;
|
|
608
|
+
if (!xliffRoot) return null;
|
|
609
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
610
|
+
if (!xliffTrgLang) {
|
|
611
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
615
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
const locale = xliffTrgLang;
|
|
604
619
|
let project;
|
|
605
620
|
try {
|
|
606
621
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -609,12 +624,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
609
624
|
}
|
|
610
625
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
611
626
|
if (!targetLocales.includes(locale)) return null;
|
|
612
|
-
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
613
|
-
const parsed = parseXliff20(xml);
|
|
614
|
-
const xliffRoot = parsed.xliff;
|
|
615
|
-
if (!xliffRoot) return null;
|
|
616
|
-
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
617
|
-
if (!xliffTrgLang) return null;
|
|
618
627
|
const fileEls = xliffRoot.file;
|
|
619
628
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
620
629
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
|
@@ -42,11 +42,14 @@ declare function filterXliffPathsByLocale(filePaths: string[], locale: string, x
|
|
|
42
42
|
* xliffDir may also indicate project/locale (e.g. xliff/zh/project.xliff).
|
|
43
43
|
* @param filePath - Absolute path to XLIFF file
|
|
44
44
|
* @param xliffDir - Absolute path to the xliff directory the file was found in
|
|
45
|
-
* @returns Object with project
|
|
45
|
+
* @returns Object with project, a path-based locale hint, and `filenameLocale`
|
|
46
|
+
* (the locale from the file name alone, `project.locale.xliff`). Import takes
|
|
47
|
+
* the locale from the file's `trgLang` and checks only `filenameLocale` against it.
|
|
46
48
|
*/
|
|
47
49
|
declare function parseXliffFilename(filePath: string, xliffDir: string): {
|
|
48
50
|
project: string;
|
|
49
51
|
locale?: string;
|
|
52
|
+
filenameLocale?: string;
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
52
55
|
* Dynamically imports MsgProject from i18n/projects by project name.
|
|
@@ -97,10 +100,12 @@ interface ImportResult {
|
|
|
97
100
|
* @param xliffPath - Absolute path to XLIFF file
|
|
98
101
|
* @param projectsDir - Absolute path to i18n/projects
|
|
99
102
|
* @param projectName - Project name (from filename, for loading MsgProject)
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
103
|
+
* @param filenameLocale - Locale from the file name, if any; must match the file's `trgLang`
|
|
104
|
+
* @param warn - Receives a message for each skip the user should hear about
|
|
105
|
+
* (monolingual file, file name locale that disagrees with `trgLang`)
|
|
106
|
+
* @returns ImportResult (locale = the file's `trgLang`) or null if the file should be skipped
|
|
102
107
|
*/
|
|
103
|
-
declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string,
|
|
108
|
+
declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string, filenameLocale: string | undefined, warn?: (message: string) => void): Promise<ImportResult | null>;
|
|
104
109
|
/**
|
|
105
110
|
* Writes translation JSON files to l10n/translations/project/locale/.
|
|
106
111
|
* @param translationsDir - Absolute path to l10n/translations
|
|
@@ -42,11 +42,14 @@ declare function filterXliffPathsByLocale(filePaths: string[], locale: string, x
|
|
|
42
42
|
* xliffDir may also indicate project/locale (e.g. xliff/zh/project.xliff).
|
|
43
43
|
* @param filePath - Absolute path to XLIFF file
|
|
44
44
|
* @param xliffDir - Absolute path to the xliff directory the file was found in
|
|
45
|
-
* @returns Object with project
|
|
45
|
+
* @returns Object with project, a path-based locale hint, and `filenameLocale`
|
|
46
|
+
* (the locale from the file name alone, `project.locale.xliff`). Import takes
|
|
47
|
+
* the locale from the file's `trgLang` and checks only `filenameLocale` against it.
|
|
46
48
|
*/
|
|
47
49
|
declare function parseXliffFilename(filePath: string, xliffDir: string): {
|
|
48
50
|
project: string;
|
|
49
51
|
locale?: string;
|
|
52
|
+
filenameLocale?: string;
|
|
50
53
|
};
|
|
51
54
|
/**
|
|
52
55
|
* Dynamically imports MsgProject from i18n/projects by project name.
|
|
@@ -97,10 +100,12 @@ interface ImportResult {
|
|
|
97
100
|
* @param xliffPath - Absolute path to XLIFF file
|
|
98
101
|
* @param projectsDir - Absolute path to i18n/projects
|
|
99
102
|
* @param projectName - Project name (from filename, for loading MsgProject)
|
|
100
|
-
* @param
|
|
101
|
-
* @
|
|
103
|
+
* @param filenameLocale - Locale from the file name, if any; must match the file's `trgLang`
|
|
104
|
+
* @param warn - Receives a message for each skip the user should hear about
|
|
105
|
+
* (monolingual file, file name locale that disagrees with `trgLang`)
|
|
106
|
+
* @returns ImportResult (locale = the file's `trgLang`) or null if the file should be skipped
|
|
102
107
|
*/
|
|
103
|
-
declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string,
|
|
108
|
+
declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string, filenameLocale: string | undefined, warn?: (message: string) => void): Promise<ImportResult | null>;
|
|
104
109
|
/**
|
|
105
110
|
* Writes translation JSON files to l10n/translations/project/locale/.
|
|
106
111
|
* @param translationsDir - Absolute path to l10n/translations
|