@worldware/msg-cli 0.6.3 → 0.6.5
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 +16 -6
- package/dist/{chunk-KOTPQTLG.mjs → chunk-OUQSCR6C.mjs} +20 -17
- package/dist/commands/import.cjs +24 -24
- package/dist/commands/import.mjs +5 -8
- package/dist/lib/import-helpers.cjs +20 -17
- package/dist/lib/import-helpers.d.mts +18 -13
- package/dist/lib/import-helpers.d.ts +18 -13
- 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,16 @@ 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` 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`).
|
|
315
|
+
- `--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
|
+
- Skips (with a warning) monolingual files (no `trgLang`), such as the `myApp.xliff` written by `msg export`.
|
|
306
317
|
- 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`.
|
|
318
|
+
- Skips files whose `trgLang` is not in the project's `targetLocales`.
|
|
309
319
|
- Skips files when the matching project file does not exist or cannot be loaded.
|
|
310
|
-
- Writes JSON to `l10n/translations/<project>/<
|
|
320
|
+
- Writes JSON to `l10n/translations/<project>/<trgLang>/<title>.json`.
|
|
311
321
|
- Preserves existing translation files for other projects or locales when filtering.
|
|
312
322
|
- Errors on malformed XLIFF and logs each step.
|
|
313
323
|
|
|
@@ -43,12 +43,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
43
43
|
}
|
|
44
44
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
45
45
|
}
|
|
46
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
47
|
-
return filePaths.filter((p) =>
|
|
48
|
-
const filename = basename(p);
|
|
49
|
-
if (filename.startsWith(projectName)) return true;
|
|
50
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
51
|
-
});
|
|
46
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
47
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
52
48
|
}
|
|
53
49
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
54
50
|
return filePaths.filter((p) => {
|
|
@@ -57,13 +53,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
57
53
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
58
54
|
});
|
|
59
55
|
}
|
|
60
|
-
|
|
61
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
56
|
+
function parseXliffFilename(filePath) {
|
|
62
57
|
const filename = basename(filePath);
|
|
63
58
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
64
59
|
const project = match?.[1] ?? basename(filename, extname(filename));
|
|
65
|
-
|
|
66
|
-
return { project, locale };
|
|
60
|
+
return { project, locale: match?.[2] };
|
|
67
61
|
}
|
|
68
62
|
function isMsgProjectLike(value) {
|
|
69
63
|
if (!value || typeof value !== "object") return false;
|
|
@@ -307,7 +301,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
307
301
|
const proj = project;
|
|
308
302
|
return MsgResource.create(resourceData, proj);
|
|
309
303
|
}
|
|
310
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
304
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
305
|
+
}) {
|
|
306
|
+
const xml = await readFile(xliffPath, "utf-8");
|
|
307
|
+
const parsed = parseXliff20(xml);
|
|
308
|
+
const xliffRoot = parsed.xliff;
|
|
309
|
+
if (!xliffRoot) return null;
|
|
310
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
311
|
+
if (!xliffTrgLang) {
|
|
312
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
316
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
const locale = xliffTrgLang;
|
|
311
320
|
let project;
|
|
312
321
|
try {
|
|
313
322
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -316,12 +325,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
316
325
|
}
|
|
317
326
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
318
327
|
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
328
|
const fileEls = xliffRoot.file;
|
|
326
329
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
327
330
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
package/dist/commands/import.cjs
CHANGED
|
@@ -395,12 +395,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
395
395
|
}
|
|
396
396
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
397
397
|
}
|
|
398
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
399
|
-
return filePaths.filter((p) =>
|
|
400
|
-
const filename = (0, import_path2.basename)(p);
|
|
401
|
-
if (filename.startsWith(projectName)) return true;
|
|
402
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
403
|
-
});
|
|
398
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
399
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
404
400
|
}
|
|
405
401
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
406
402
|
return filePaths.filter((p) => {
|
|
@@ -409,13 +405,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
409
405
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
410
406
|
});
|
|
411
407
|
}
|
|
412
|
-
|
|
413
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
408
|
+
function parseXliffFilename(filePath) {
|
|
414
409
|
const filename = (0, import_path2.basename)(filePath);
|
|
415
410
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
416
411
|
const project = match?.[1] ?? (0, import_path2.basename)(filename, (0, import_path2.extname)(filename));
|
|
417
|
-
|
|
418
|
-
return { project, locale };
|
|
412
|
+
return { project, locale: match?.[2] };
|
|
419
413
|
}
|
|
420
414
|
function isMsgProjectLike(value) {
|
|
421
415
|
if (!value || typeof value !== "object") return false;
|
|
@@ -659,7 +653,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
659
653
|
const proj = project;
|
|
660
654
|
return import_msg2.MsgResource.create(resourceData, proj);
|
|
661
655
|
}
|
|
662
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
656
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
657
|
+
}) {
|
|
658
|
+
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
659
|
+
const parsed = parseXliff20(xml);
|
|
660
|
+
const xliffRoot = parsed.xliff;
|
|
661
|
+
if (!xliffRoot) return null;
|
|
662
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
663
|
+
if (!xliffTrgLang) {
|
|
664
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
665
|
+
return null;
|
|
666
|
+
}
|
|
667
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
668
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
const locale = xliffTrgLang;
|
|
663
672
|
let project;
|
|
664
673
|
try {
|
|
665
674
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -668,12 +677,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
668
677
|
}
|
|
669
678
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
670
679
|
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
680
|
const fileEls = xliffRoot.file;
|
|
678
681
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
679
682
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
|
@@ -752,7 +755,7 @@ var Import = class _Import extends import_core.Command {
|
|
|
752
755
|
}
|
|
753
756
|
this.log(`Found ${filePaths.length} XLIFF file(s).`);
|
|
754
757
|
if (flags.project) {
|
|
755
|
-
filePaths = filterXliffPathsByProject(filePaths, flags.project
|
|
758
|
+
filePaths = filterXliffPathsByProject(filePaths, flags.project);
|
|
756
759
|
if (filePaths.length === 0) {
|
|
757
760
|
this.log(`No XLIFF files found for project '${flags.project}'. Nothing to import.`);
|
|
758
761
|
return;
|
|
@@ -770,17 +773,14 @@ var Import = class _Import extends import_core.Command {
|
|
|
770
773
|
let wroteCount = 0;
|
|
771
774
|
let errorCount = 0;
|
|
772
775
|
for (const xliffPath of filePaths) {
|
|
773
|
-
const { project: projectName, locale } = parseXliffFilename(xliffPath
|
|
774
|
-
if (!locale) {
|
|
775
|
-
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
776
|
-
continue;
|
|
777
|
-
}
|
|
776
|
+
const { project: projectName, locale: filenameLocale } = parseXliffFilename(xliffPath);
|
|
778
777
|
try {
|
|
779
778
|
const result = await processXliffFile(
|
|
780
779
|
xliffPath,
|
|
781
780
|
projectsDir,
|
|
782
781
|
projectName,
|
|
783
|
-
|
|
782
|
+
filenameLocale,
|
|
783
|
+
(message) => this.warn(message)
|
|
784
784
|
);
|
|
785
785
|
if (result) {
|
|
786
786
|
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-OUQSCR6C.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,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, locale } = parseXliffFilename(xliffPath
|
|
86
|
-
if (!locale) {
|
|
87
|
-
this.warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
85
|
+
const { project: projectName, locale: filenameLocale } = parseXliffFilename(xliffPath);
|
|
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);
|
|
@@ -336,12 +336,8 @@ function xliffDirSegments(xliffDir, filePath) {
|
|
|
336
336
|
}
|
|
337
337
|
return rel.split(/[/\\]/).slice(0, -1);
|
|
338
338
|
}
|
|
339
|
-
function filterXliffPathsByProject(filePaths, projectName
|
|
340
|
-
return filePaths.filter((p) =>
|
|
341
|
-
const filename = (0, import_path.basename)(p);
|
|
342
|
-
if (filename.startsWith(projectName)) return true;
|
|
343
|
-
return xliffDirSegments(xliffDir, p).some((part) => part === projectName);
|
|
344
|
-
});
|
|
339
|
+
function filterXliffPathsByProject(filePaths, projectName) {
|
|
340
|
+
return filePaths.filter((p) => parseXliffFilename(p).project === projectName);
|
|
345
341
|
}
|
|
346
342
|
function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
347
343
|
return filePaths.filter((p) => {
|
|
@@ -350,13 +346,11 @@ function filterXliffPathsByLocale(filePaths, locale, xliffDir) {
|
|
|
350
346
|
return xliffDirSegments(xliffDir, p).some((part) => part === locale);
|
|
351
347
|
});
|
|
352
348
|
}
|
|
353
|
-
|
|
354
|
-
function parseXliffFilename(filePath, xliffDir) {
|
|
349
|
+
function parseXliffFilename(filePath) {
|
|
355
350
|
const filename = (0, import_path.basename)(filePath);
|
|
356
351
|
const match = filename.match(XLIFF_FILENAME_PATTERN);
|
|
357
352
|
const project = match?.[1] ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
|
|
358
|
-
|
|
359
|
-
return { project, locale };
|
|
353
|
+
return { project, locale: match?.[2] };
|
|
360
354
|
}
|
|
361
355
|
function isMsgProjectLike(value) {
|
|
362
356
|
if (!value || typeof value !== "object") return false;
|
|
@@ -600,7 +594,22 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
600
594
|
const proj = project;
|
|
601
595
|
return import_msg2.MsgResource.create(resourceData, proj);
|
|
602
596
|
}
|
|
603
|
-
async function processXliffFile(xliffPath, projectsDir, projectName,
|
|
597
|
+
async function processXliffFile(xliffPath, projectsDir, projectName, filenameLocale, warn = () => {
|
|
598
|
+
}) {
|
|
599
|
+
const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
|
|
600
|
+
const parsed = parseXliff20(xml);
|
|
601
|
+
const xliffRoot = parsed.xliff;
|
|
602
|
+
if (!xliffRoot) return null;
|
|
603
|
+
const xliffTrgLang = xliffRoot["@_trgLang"];
|
|
604
|
+
if (!xliffTrgLang) {
|
|
605
|
+
warn(`Skipping monolingual file (no target locale): ${xliffPath}`);
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
if (filenameLocale && filenameLocale.toLowerCase() !== xliffTrgLang.toLowerCase()) {
|
|
609
|
+
warn(`Skipping ${xliffPath}: file name locale '${filenameLocale}' does not match trgLang '${xliffTrgLang}'`);
|
|
610
|
+
return null;
|
|
611
|
+
}
|
|
612
|
+
const locale = xliffTrgLang;
|
|
604
613
|
let project;
|
|
605
614
|
try {
|
|
606
615
|
project = await importMsgProject(projectsDir, projectName);
|
|
@@ -609,12 +618,6 @@ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
|
|
|
609
618
|
}
|
|
610
619
|
const targetLocales = Object.keys(project.locales.targetLocales);
|
|
611
620
|
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
621
|
const fileEls = xliffRoot.file;
|
|
619
622
|
const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
|
|
620
623
|
const xliffSpace = resolveXmlSpace(xliffRoot, "default");
|
|
@@ -20,13 +20,14 @@ 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`), wherever they sit. This is the project import loads,
|
|
25
|
+
* so directories are not matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
27
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
28
|
* @returns Filtered array of paths
|
|
28
29
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
30
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
31
|
/**
|
|
31
32
|
* Filters XLIFF file paths by locale.
|
|
32
33
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,14 +38,16 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
38
|
*/
|
|
38
39
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
40
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* Extracts project name and locale from an XLIFF file name
|
|
42
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
43
|
+
*
|
|
44
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
45
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
46
|
+
* locale from directories let short names like `app` win (#55).
|
|
47
|
+
* @param filePath - Path to an XLIFF file
|
|
48
|
+
* @returns Object with project and the file name's locale, if any
|
|
46
49
|
*/
|
|
47
|
-
declare function parseXliffFilename(filePath: string
|
|
50
|
+
declare function parseXliffFilename(filePath: string): {
|
|
48
51
|
project: string;
|
|
49
52
|
locale?: string;
|
|
50
53
|
};
|
|
@@ -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
|
|
@@ -20,13 +20,14 @@ 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`), wherever they sit. This is the project import loads,
|
|
25
|
+
* so directories are not matched: `xliff/app/zh/file.xliff` imports as `file`.
|
|
24
26
|
* @param filePaths - Array of absolute XLIFF file paths
|
|
25
27
|
* @param projectName - Project name to filter by
|
|
26
|
-
* @param xliffDir - Absolute path to the xliff directory the paths were found in
|
|
27
28
|
* @returns Filtered array of paths
|
|
28
29
|
*/
|
|
29
|
-
declare function filterXliffPathsByProject(filePaths: string[], projectName: string
|
|
30
|
+
declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
|
|
30
31
|
/**
|
|
31
32
|
* Filters XLIFF file paths by locale.
|
|
32
33
|
* Keeps paths that have .[locale]. in the filename or locale as a directory under xliffDir.
|
|
@@ -37,14 +38,16 @@ declare function filterXliffPathsByProject(filePaths: string[], projectName: str
|
|
|
37
38
|
*/
|
|
38
39
|
declare function filterXliffPathsByLocale(filePaths: string[], locale: string, xliffDir: string): string[];
|
|
39
40
|
/**
|
|
40
|
-
* Extracts project name and locale from an XLIFF file
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
41
|
+
* Extracts project name and locale from an XLIFF file name
|
|
42
|
+
* (`project.locale.xliff` or `project.xliff`).
|
|
43
|
+
*
|
|
44
|
+
* Directories are not consulted: import takes the locale from the file's
|
|
45
|
+
* `trgLang` (#57) and only checks a file name locale against it. Guessing a
|
|
46
|
+
* locale from directories let short names like `app` win (#55).
|
|
47
|
+
* @param filePath - Path to an XLIFF file
|
|
48
|
+
* @returns Object with project and the file name's locale, if any
|
|
46
49
|
*/
|
|
47
|
-
declare function parseXliffFilename(filePath: string
|
|
50
|
+
declare function parseXliffFilename(filePath: string): {
|
|
48
51
|
project: string;
|
|
49
52
|
locale?: string;
|
|
50
53
|
};
|
|
@@ -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
|