@worldware/msg-cli 0.1.3 → 0.2.1

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.
Files changed (38) hide show
  1. package/README.md +99 -13
  2. package/dist/{chunk-BRZS5LYD.mjs → chunk-6A6JGF7U.mjs} +2 -2
  3. package/dist/chunk-BM3O7ZJW.mjs +176 -0
  4. package/dist/{chunk-AT7DHQF7.mjs → chunk-F7XZRKP7.mjs} +2 -2
  5. package/dist/chunk-KKATA5YE.mjs +324 -0
  6. package/dist/{chunk-T4ENP5TS.mjs → chunk-LNCUPVEF.mjs} +2 -2
  7. package/dist/commands/create/project.cjs +24 -12
  8. package/dist/commands/create/project.mjs +27 -15
  9. package/dist/commands/create/resource.cjs +2 -2
  10. package/dist/commands/create/resource.mjs +3 -3
  11. package/dist/commands/export.cjs +356 -0
  12. package/dist/commands/export.d.mts +16 -0
  13. package/dist/commands/export.d.ts +16 -0
  14. package/dist/commands/export.mjs +91 -0
  15. package/dist/commands/import.cjs +526 -0
  16. package/dist/commands/import.d.mts +17 -0
  17. package/dist/commands/import.d.ts +17 -0
  18. package/dist/commands/import.mjs +116 -0
  19. package/dist/commands/init.cjs +2 -2
  20. package/dist/commands/init.mjs +1 -1
  21. package/dist/lib/create-project-helpers.mjs +3 -3
  22. package/dist/lib/create-resource-helpers.cjs +1 -1
  23. package/dist/lib/create-resource-helpers.mjs +2 -2
  24. package/dist/lib/export-helpers.cjs +229 -0
  25. package/dist/lib/export-helpers.d.mts +55 -0
  26. package/dist/lib/export-helpers.d.ts +55 -0
  27. package/dist/lib/export-helpers.mjs +18 -0
  28. package/dist/lib/import-helpers.cjs +380 -0
  29. package/dist/lib/import-helpers.d.mts +92 -0
  30. package/dist/lib/import-helpers.d.ts +92 -0
  31. package/dist/lib/import-helpers.mjs +24 -0
  32. package/dist/lib/init-helpers.cjs +2 -2
  33. package/dist/lib/init-helpers.mjs +1 -1
  34. package/package.json +2 -2
  35. package/dist/lib/utilities.cjs +0 -203
  36. package/dist/lib/utilities.d.mts +0 -59
  37. package/dist/lib/utilities.d.ts +0 -59
  38. package/dist/lib/utilities.mjs +0 -172
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/import-helpers.ts
21
+ var import_helpers_exports = {};
22
+ __export(import_helpers_exports, {
23
+ extractResourceFromXliffFile: () => extractResourceFromXliffFile,
24
+ filterXliffPathsByLocale: () => filterXliffPathsByLocale,
25
+ filterXliffPathsByProject: () => filterXliffPathsByProject,
26
+ findXliffFilePaths: () => findXliffFilePaths,
27
+ importMsgProject: () => importMsgProject,
28
+ parseXliff20: () => parseXliff20,
29
+ parseXliffFilename: () => parseXliffFilename,
30
+ processXliffFile: () => processXliffFile,
31
+ writeTranslationFiles: () => writeTranslationFiles
32
+ });
33
+ module.exports = __toCommonJS(import_helpers_exports);
34
+ var import_msg = require("@worldware/msg");
35
+ var import_promises = require("fs/promises");
36
+ var import_path = require("path");
37
+ var import_url2 = require("url");
38
+ var import_fast_xml_parser = require("fast-xml-parser");
39
+ var import_fs = require("fs");
40
+
41
+ // src/lib/create-resource-helpers.ts
42
+ var import_module = require("module");
43
+ var import_url = require("url");
44
+ async function dynamicImportFromUrl(url) {
45
+ try {
46
+ return await import(
47
+ /* @vite-ignore */
48
+ url
49
+ );
50
+ } catch (err) {
51
+ const msg = err instanceof Error ? err.message : String(err);
52
+ const useRequire = msg.includes("dynamic import callback") || msg.includes("ERR_VM_DYNAMIC_IMPORT");
53
+ if (useRequire) {
54
+ try {
55
+ const path = url.startsWith("file:") ? (0, import_url.fileURLToPath)(url) : url;
56
+ const base = (0, import_url.pathToFileURL)(process.cwd()).href;
57
+ const req = (0, import_module.createRequire)(base);
58
+ const mod = req(path);
59
+ return Promise.resolve(mod ?? {});
60
+ } catch {
61
+ }
62
+ }
63
+ throw err;
64
+ }
65
+ }
66
+
67
+ // src/lib/import-helpers.ts
68
+ var XLIFF_EXTENSIONS = [".xliff", ".xlf"];
69
+ var XLIFF_FILENAME_PATTERN = /^(.+?)(?:\.([a-zA-Z]{2,}(?:-[a-zA-Z0-9]+)*))?\.(?:xliff|xlf)$/i;
70
+ async function findXliffFilePaths(directory) {
71
+ const result = [];
72
+ const entries = await (0, import_promises.readdir)(directory, { withFileTypes: true });
73
+ for (const entry of entries) {
74
+ const fullPath = (0, import_path.join)(directory, entry.name);
75
+ if (entry.isFile()) {
76
+ const ext = (0, import_path.extname)(entry.name).toLowerCase();
77
+ if (XLIFF_EXTENSIONS.includes(ext)) {
78
+ result.push(fullPath);
79
+ }
80
+ } else if (entry.isDirectory()) {
81
+ result.push(...await findXliffFilePaths(fullPath));
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ function filterXliffPathsByProject(filePaths, projectName) {
87
+ return filePaths.filter((p) => {
88
+ const filename = (0, import_path.basename)(p);
89
+ if (filename.startsWith(projectName)) return true;
90
+ const pathParts = p.split(/[/\\]/);
91
+ return pathParts.some((part) => part === projectName);
92
+ });
93
+ }
94
+ function filterXliffPathsByLocale(filePaths, locale) {
95
+ return filePaths.filter((p) => {
96
+ const filename = (0, import_path.basename)(p);
97
+ if (filename.includes(`.${locale}.`)) return true;
98
+ const pathParts = p.split(/[/\\]/);
99
+ return pathParts.some((part) => part === locale);
100
+ });
101
+ }
102
+ var LOCALE_PATTERN = /^[a-zA-Z]{2,3}(-[a-zA-Z0-9]+)*$/;
103
+ function parseXliffFilename(filePath) {
104
+ const filename = (0, import_path.basename)(filePath);
105
+ const match = filename.match(XLIFF_FILENAME_PATTERN);
106
+ const pathParts = filePath.split(/[/\\]/);
107
+ let project;
108
+ let locale;
109
+ if (match) {
110
+ const [, proj, loc] = match;
111
+ project = proj ?? (0, import_path.basename)(filename, (0, import_path.extname)(filename));
112
+ locale = loc;
113
+ } else {
114
+ project = (0, import_path.basename)(filename, (0, import_path.extname)(filename));
115
+ }
116
+ if (!locale) {
117
+ for (const part of pathParts) {
118
+ if (LOCALE_PATTERN.test(part) && part.length >= 2) {
119
+ locale = part;
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ if (!project && pathParts.length >= 2) {
125
+ for (const part of pathParts) {
126
+ if (part && !XLIFF_EXTENSIONS.some((e) => part.endsWith(e))) {
127
+ project = part;
128
+ break;
129
+ }
130
+ }
131
+ }
132
+ return { project, locale };
133
+ }
134
+ function isMsgProjectLike(value) {
135
+ if (!value || typeof value !== "object") return false;
136
+ const loc = value.locales?.targetLocales;
137
+ return typeof loc === "object" && loc !== null && !Array.isArray(loc);
138
+ }
139
+ async function importMsgProject(projectsDir, projectName) {
140
+ const basePath = (0, import_path.join)(projectsDir, projectName);
141
+ const exts = [".ts", ".js"];
142
+ for (const ext of exts) {
143
+ const p = `${basePath}${ext}`;
144
+ if ((0, import_fs.existsSync)(p)) {
145
+ const url = (0, import_url2.pathToFileURL)(p).href;
146
+ const mod = await dynamicImportFromUrl(url);
147
+ const project = mod?.default ?? mod;
148
+ if (!isMsgProjectLike(project)) {
149
+ throw new Error(`Project file '${projectName}${ext}' does not export a valid MsgProject.`);
150
+ }
151
+ return project;
152
+ }
153
+ }
154
+ throw new Error(`Project file not found: ${projectName}`);
155
+ }
156
+ var xmlParser = new import_fast_xml_parser.XMLParser({
157
+ ignoreAttributes: false,
158
+ attributeNamePrefix: "@_"
159
+ });
160
+ function parseXliff20(xml) {
161
+ try {
162
+ const parsed = xmlParser.parse(xml);
163
+ if (!parsed || typeof parsed !== "object") {
164
+ throw new Error("Failed to parse XLIFF");
165
+ }
166
+ return parsed;
167
+ } catch (err) {
168
+ const message = err instanceof Error ? err.message : "Failed to parse XLIFF";
169
+ throw new Error(`Malformed XLIFF 2.0: ${message}`);
170
+ }
171
+ }
172
+ function categoryToNoteType(category) {
173
+ const lower = category.toLowerCase();
174
+ if (lower.startsWith("x-")) return category.toUpperCase();
175
+ const map = {
176
+ description: "DESCRIPTION",
177
+ authorship: "AUTHORSHIP",
178
+ parameters: "PARAMETERS",
179
+ context: "CONTEXT",
180
+ comment: "COMMENT"
181
+ };
182
+ return map[lower] ?? category.toUpperCase();
183
+ }
184
+ function extractSegmentText(segment) {
185
+ if (segment == null) return "";
186
+ const seg = segment;
187
+ const target = seg.target ?? seg.source;
188
+ if (typeof target === "string") return target;
189
+ if (target && typeof target === "object") {
190
+ return extractInlineText(target);
191
+ }
192
+ return "";
193
+ }
194
+ function extractInlineText(node) {
195
+ let text = "";
196
+ if ("#text" in node && typeof node["#text"] === "string") {
197
+ text += node["#text"];
198
+ }
199
+ const children = ["pc", "sc", "ec", "ph", "mrk", "sm", "em", "cp", "target", "source"];
200
+ for (const tag of children) {
201
+ const child = node[tag];
202
+ if (Array.isArray(child)) {
203
+ for (const c of child) {
204
+ const childObj = typeof c === "object" && c !== null ? c : {};
205
+ text += extractInlineText(childObj);
206
+ }
207
+ } else if (child && typeof child === "object") {
208
+ text += extractInlineText(child);
209
+ }
210
+ }
211
+ return text;
212
+ }
213
+ function processUnitsFromItems(units, fileAttrs) {
214
+ const messages = [];
215
+ for (const u of units) {
216
+ const msg = processUnit(u, fileAttrs);
217
+ if (msg) messages.push(msg);
218
+ }
219
+ return messages;
220
+ }
221
+ function processGroupsForMessages(groups, fileAttrs) {
222
+ const messages = [];
223
+ for (const item of groups) {
224
+ const obj = item;
225
+ if (obj.unit) {
226
+ const units = Array.isArray(obj.unit) ? obj.unit : [obj.unit];
227
+ messages.push(...processUnitsFromItems(units, fileAttrs));
228
+ }
229
+ if (obj.group) {
230
+ const nestedGroups = Array.isArray(obj.group) ? obj.group : [obj.group];
231
+ messages.push(...processGroupsForMessages(nestedGroups, fileAttrs));
232
+ }
233
+ }
234
+ return messages;
235
+ }
236
+ function processUnit(unit, fileAttrs) {
237
+ const name = unit["@_name"] ?? unit["@_id"] ?? "";
238
+ const trgLang = unit["@_trgLang"] ?? fileAttrs.trgLang;
239
+ const trgDir = unit["@_trgDir"] ?? fileAttrs.trgDir;
240
+ const translate = (unit["@_translate"] ?? "yes").toLowerCase();
241
+ const dnt = translate === "no" || translate === "false";
242
+ const fileTranslate = (fileAttrs.translate ?? "yes").toLowerCase();
243
+ const fileDnt = fileTranslate === "no" || fileTranslate === "false";
244
+ const notes = [];
245
+ const notesEl = unit.notes;
246
+ if (notesEl?.note) {
247
+ const noteArr = Array.isArray(notesEl.note) ? notesEl.note : [notesEl.note];
248
+ for (const n of noteArr) {
249
+ const note = n;
250
+ const category = note["@_category"] ?? "comment";
251
+ const content = note["#text"] ?? "";
252
+ notes.push({ type: categoryToNoteType(category), content });
253
+ }
254
+ }
255
+ const segments = unit.segment ? Array.isArray(unit.segment) ? unit.segment : [unit.segment] : [];
256
+ const targetParts = [];
257
+ for (const seg of segments) {
258
+ targetParts.push(extractSegmentText(seg));
259
+ }
260
+ const value = targetParts.join("");
261
+ const attributes = {};
262
+ if (trgLang !== fileAttrs.trgLang) attributes.lang = trgLang || void 0;
263
+ if (trgDir !== fileAttrs.trgDir) attributes.dir = trgDir || void 0;
264
+ if (dnt !== fileDnt) attributes.dnt = dnt;
265
+ return {
266
+ key: name,
267
+ value,
268
+ attributes,
269
+ notes
270
+ };
271
+ }
272
+ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocales) {
273
+ const trgLang = fileEl["@_trgLang"] ?? xliffTrgLang;
274
+ if (!trgLang) return null;
275
+ if (!targetLocales.includes(trgLang)) return null;
276
+ const original = fileEl["@_original"] ?? "unknown.json";
277
+ const title = (0, import_path.basename)(original, (0, import_path.extname)(original)) || original;
278
+ const trgDir = fileEl["@_trgDir"];
279
+ const translate = (fileEl["@_translate"] ?? "yes").toLowerCase();
280
+ const dnt = translate === "no" || translate === "false";
281
+ const attributes = {
282
+ lang: trgLang,
283
+ dir: trgDir ?? "",
284
+ dnt
285
+ };
286
+ const notes = [];
287
+ const notesEl = fileEl.notes;
288
+ if (notesEl?.note) {
289
+ const noteArr = Array.isArray(notesEl.note) ? notesEl.note : [notesEl.note];
290
+ for (const n of noteArr) {
291
+ const note = n;
292
+ const category = note["@_category"] ?? "comment";
293
+ const content = note["#text"] ?? "";
294
+ notes.push({ type: categoryToNoteType(category), content });
295
+ }
296
+ }
297
+ const fileAttrs = {
298
+ trgLang,
299
+ trgDir,
300
+ translate
301
+ };
302
+ const allMessages = [
303
+ ...processUnitsFromItems(
304
+ fileEl.unit ? Array.isArray(fileEl.unit) ? fileEl.unit : [fileEl.unit] : [],
305
+ fileAttrs
306
+ ),
307
+ ...processGroupsForMessages(
308
+ fileEl.group ? Array.isArray(fileEl.group) ? fileEl.group : [fileEl.group] : [],
309
+ fileAttrs
310
+ )
311
+ ];
312
+ const resourceData = {
313
+ title,
314
+ attributes,
315
+ notes,
316
+ messages: allMessages.map((m) => ({
317
+ key: m.key,
318
+ value: m.value,
319
+ attributes: m.attributes,
320
+ notes: m.notes.length > 0 ? m.notes : void 0
321
+ }))
322
+ };
323
+ const proj = project;
324
+ return import_msg.MsgResource.create(resourceData, proj);
325
+ }
326
+ async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
327
+ let project;
328
+ try {
329
+ project = await importMsgProject(projectsDir, projectName);
330
+ } catch {
331
+ return null;
332
+ }
333
+ const targetLocales = Object.keys(project.locales.targetLocales);
334
+ if (!targetLocales.includes(locale)) return null;
335
+ const xml = await (0, import_promises.readFile)(xliffPath, "utf-8");
336
+ const parsed = parseXliff20(xml);
337
+ const xliffRoot = parsed.xliff;
338
+ if (!xliffRoot) return null;
339
+ const xliffTrgLang = xliffRoot["@_trgLang"];
340
+ if (!xliffTrgLang) return null;
341
+ const fileEls = xliffRoot.file;
342
+ const files = Array.isArray(fileEls) ? fileEls : fileEls ? [fileEls] : [];
343
+ const resources = [];
344
+ for (const fileEl of files) {
345
+ const resource = extractResourceFromXliffFile(
346
+ fileEl,
347
+ xliffTrgLang,
348
+ project,
349
+ targetLocales
350
+ );
351
+ if (resource) {
352
+ const json = resource.toJSON(true);
353
+ resources.push({ title: resource.title, json });
354
+ }
355
+ }
356
+ if (resources.length === 0) return null;
357
+ return { project: projectName, locale, resources };
358
+ }
359
+ async function writeTranslationFiles(translationsDir, result) {
360
+ const { project, locale, resources } = result;
361
+ const projectDir = (0, import_path.join)(translationsDir, project);
362
+ const localeDir = (0, import_path.join)(projectDir, locale);
363
+ await (0, import_promises.mkdir)(localeDir, { recursive: true });
364
+ for (const { title, json } of resources) {
365
+ const filePath = (0, import_path.join)(localeDir, `${title}.json`);
366
+ await (0, import_promises.writeFile)(filePath, json, "utf-8");
367
+ }
368
+ }
369
+ // Annotate the CommonJS export names for ESM import in node:
370
+ 0 && (module.exports = {
371
+ extractResourceFromXliffFile,
372
+ filterXliffPathsByLocale,
373
+ filterXliffPathsByProject,
374
+ findXliffFilePaths,
375
+ importMsgProject,
376
+ parseXliff20,
377
+ parseXliffFilename,
378
+ processXliffFile,
379
+ writeTranslationFiles
380
+ });
@@ -0,0 +1,92 @@
1
+ import { MsgResource } from '@worldware/msg';
2
+
3
+ /**
4
+ * Recursively finds all XLIFF files in a directory.
5
+ * @param directory - Absolute path to the xliff directory (e.g. l10n/xliff)
6
+ * @returns Promise resolving to array of absolute file paths
7
+ */
8
+ declare function findXliffFilePaths(directory: string): Promise<string[]>;
9
+ /**
10
+ * Filters XLIFF file paths by project name.
11
+ * Keeps paths where filename starts with projectName or projectName is a directory in the path.
12
+ * @param filePaths - Array of absolute XLIFF file paths
13
+ * @param projectName - Project name to filter by
14
+ * @returns Filtered array of paths
15
+ */
16
+ declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
17
+ /**
18
+ * Filters XLIFF file paths by locale.
19
+ * Keeps paths that have .[locale]. in the filename or locale as a directory in the path.
20
+ * @param filePaths - Array of absolute XLIFF file paths
21
+ * @param locale - Locale code to filter by
22
+ * @returns Filtered array of paths
23
+ */
24
+ declare function filterXliffPathsByLocale(filePaths: string[], locale: string): string[];
25
+ /**
26
+ * Extracts project name and locale from an XLIFF file path.
27
+ * Filename patterns: project.locale.xliff, project.xliff. Path segments may also indicate project/locale.
28
+ * @param filePath - Absolute path to XLIFF file
29
+ * @returns Object with project and locale (locale may be undefined for monolingual)
30
+ */
31
+ declare function parseXliffFilename(filePath: string): {
32
+ project: string;
33
+ locale?: string;
34
+ };
35
+ /**
36
+ * Dynamically imports MsgProject from i18n/projects by project name.
37
+ * @param projectsDir - Absolute path to i18n/projects
38
+ * @param projectName - Project name (filename without extension)
39
+ * @returns Promise resolving to MsgProject-like object with targetLocales
40
+ * @throws Error if project cannot be loaded
41
+ */
42
+ declare function importMsgProject(projectsDir: string, projectName: string): Promise<{
43
+ locales: {
44
+ targetLocales: Record<string, string[]>;
45
+ };
46
+ }>;
47
+ /**
48
+ * Parses XLIFF 2.0 XML string to a JavaScript object.
49
+ * @param xml - XLIFF 2.0 XML string
50
+ * @returns Parsed object
51
+ * @throws Error if XML is malformed
52
+ */
53
+ declare function parseXliff20(xml: string): object;
54
+ /**
55
+ * Extracts MsgResource from parsed XLIFF 2.0 object for a single file element.
56
+ * @param fileEl - Parsed file element
57
+ * @param xliffTrgLang - trgLang from xliff root (may be undefined for monolingual)
58
+ * @param project - MsgProject instance
59
+ * @param targetLocales - Array of supported target locale keys
60
+ * @returns MsgResource or null if file should be skipped (monolingual or unsupported locale)
61
+ */
62
+ declare function extractResourceFromXliffFile(fileEl: Record<string, unknown>, xliffTrgLang: string | undefined, project: {
63
+ locales: {
64
+ targetLocales: Record<string, string[]>;
65
+ };
66
+ }, targetLocales: string[]): MsgResource | null;
67
+ /** Result of processing one XLIFF file: project, locale, and resources to write. */
68
+ interface ImportResult {
69
+ project: string;
70
+ locale: string;
71
+ resources: Array<{
72
+ title: string;
73
+ json: string;
74
+ }>;
75
+ }
76
+ /**
77
+ * Processes one XLIFF file: reads, parses, extracts resources, returns JSON strings for writing.
78
+ * @param xliffPath - Absolute path to XLIFF file
79
+ * @param projectsDir - Absolute path to i18n/projects
80
+ * @param projectName - Project name (from filename, for loading MsgProject)
81
+ * @param locale - Target locale (from filename)
82
+ * @returns ImportResult or null if file should be skipped
83
+ */
84
+ declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string, locale: string): Promise<ImportResult | null>;
85
+ /**
86
+ * Writes translation JSON files to l10n/translations/project/locale/.
87
+ * @param translationsDir - Absolute path to l10n/translations
88
+ * @param result - ImportResult from processXliffFile
89
+ */
90
+ declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
91
+
92
+ export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles };
@@ -0,0 +1,92 @@
1
+ import { MsgResource } from '@worldware/msg';
2
+
3
+ /**
4
+ * Recursively finds all XLIFF files in a directory.
5
+ * @param directory - Absolute path to the xliff directory (e.g. l10n/xliff)
6
+ * @returns Promise resolving to array of absolute file paths
7
+ */
8
+ declare function findXliffFilePaths(directory: string): Promise<string[]>;
9
+ /**
10
+ * Filters XLIFF file paths by project name.
11
+ * Keeps paths where filename starts with projectName or projectName is a directory in the path.
12
+ * @param filePaths - Array of absolute XLIFF file paths
13
+ * @param projectName - Project name to filter by
14
+ * @returns Filtered array of paths
15
+ */
16
+ declare function filterXliffPathsByProject(filePaths: string[], projectName: string): string[];
17
+ /**
18
+ * Filters XLIFF file paths by locale.
19
+ * Keeps paths that have .[locale]. in the filename or locale as a directory in the path.
20
+ * @param filePaths - Array of absolute XLIFF file paths
21
+ * @param locale - Locale code to filter by
22
+ * @returns Filtered array of paths
23
+ */
24
+ declare function filterXliffPathsByLocale(filePaths: string[], locale: string): string[];
25
+ /**
26
+ * Extracts project name and locale from an XLIFF file path.
27
+ * Filename patterns: project.locale.xliff, project.xliff. Path segments may also indicate project/locale.
28
+ * @param filePath - Absolute path to XLIFF file
29
+ * @returns Object with project and locale (locale may be undefined for monolingual)
30
+ */
31
+ declare function parseXliffFilename(filePath: string): {
32
+ project: string;
33
+ locale?: string;
34
+ };
35
+ /**
36
+ * Dynamically imports MsgProject from i18n/projects by project name.
37
+ * @param projectsDir - Absolute path to i18n/projects
38
+ * @param projectName - Project name (filename without extension)
39
+ * @returns Promise resolving to MsgProject-like object with targetLocales
40
+ * @throws Error if project cannot be loaded
41
+ */
42
+ declare function importMsgProject(projectsDir: string, projectName: string): Promise<{
43
+ locales: {
44
+ targetLocales: Record<string, string[]>;
45
+ };
46
+ }>;
47
+ /**
48
+ * Parses XLIFF 2.0 XML string to a JavaScript object.
49
+ * @param xml - XLIFF 2.0 XML string
50
+ * @returns Parsed object
51
+ * @throws Error if XML is malformed
52
+ */
53
+ declare function parseXliff20(xml: string): object;
54
+ /**
55
+ * Extracts MsgResource from parsed XLIFF 2.0 object for a single file element.
56
+ * @param fileEl - Parsed file element
57
+ * @param xliffTrgLang - trgLang from xliff root (may be undefined for monolingual)
58
+ * @param project - MsgProject instance
59
+ * @param targetLocales - Array of supported target locale keys
60
+ * @returns MsgResource or null if file should be skipped (monolingual or unsupported locale)
61
+ */
62
+ declare function extractResourceFromXliffFile(fileEl: Record<string, unknown>, xliffTrgLang: string | undefined, project: {
63
+ locales: {
64
+ targetLocales: Record<string, string[]>;
65
+ };
66
+ }, targetLocales: string[]): MsgResource | null;
67
+ /** Result of processing one XLIFF file: project, locale, and resources to write. */
68
+ interface ImportResult {
69
+ project: string;
70
+ locale: string;
71
+ resources: Array<{
72
+ title: string;
73
+ json: string;
74
+ }>;
75
+ }
76
+ /**
77
+ * Processes one XLIFF file: reads, parses, extracts resources, returns JSON strings for writing.
78
+ * @param xliffPath - Absolute path to XLIFF file
79
+ * @param projectsDir - Absolute path to i18n/projects
80
+ * @param projectName - Project name (from filename, for loading MsgProject)
81
+ * @param locale - Target locale (from filename)
82
+ * @returns ImportResult or null if file should be skipped
83
+ */
84
+ declare function processXliffFile(xliffPath: string, projectsDir: string, projectName: string, locale: string): Promise<ImportResult | null>;
85
+ /**
86
+ * Writes translation JSON files to l10n/translations/project/locale/.
87
+ * @param translationsDir - Absolute path to l10n/translations
88
+ * @param result - ImportResult from processXliffFile
89
+ */
90
+ declare function writeTranslationFiles(translationsDir: string, result: ImportResult): Promise<void>;
91
+
92
+ export { type ImportResult, extractResourceFromXliffFile, filterXliffPathsByLocale, filterXliffPathsByProject, findXliffFilePaths, importMsgProject, parseXliff20, parseXliffFilename, processXliffFile, writeTranslationFiles };
@@ -0,0 +1,24 @@
1
+ import {
2
+ extractResourceFromXliffFile,
3
+ filterXliffPathsByLocale,
4
+ filterXliffPathsByProject,
5
+ findXliffFilePaths,
6
+ importMsgProject,
7
+ parseXliff20,
8
+ parseXliffFilename,
9
+ processXliffFile,
10
+ writeTranslationFiles
11
+ } from "../chunk-KKATA5YE.mjs";
12
+ import "../chunk-LNCUPVEF.mjs";
13
+ import "../chunk-F7XZRKP7.mjs";
14
+ export {
15
+ extractResourceFromXliffFile,
16
+ filterXliffPathsByLocale,
17
+ filterXliffPathsByProject,
18
+ findXliffFilePaths,
19
+ importMsgProject,
20
+ parseXliff20,
21
+ parseXliffFilename,
22
+ processXliffFile,
23
+ writeTranslationFiles
24
+ };
@@ -161,8 +161,8 @@ function addImportAliasesToPackageJson(pkg, i18nDir, l10nDir) {
161
161
  function addScriptsToPackageJson(pkg) {
162
162
  const scripts = {
163
163
  ...pkg.scripts,
164
- "i18n-export": "msg export resources",
165
- "l10n-import": "msg import translations"
164
+ "i18n-export": "msg export",
165
+ "l10n-import": "msg import"
166
166
  };
167
167
  return { ...pkg, scripts };
168
168
  }
@@ -12,7 +12,7 @@ import {
12
12
  readPackageJson,
13
13
  validatePaths,
14
14
  writePackageJson
15
- } from "../chunk-AT7DHQF7.mjs";
15
+ } from "../chunk-F7XZRKP7.mjs";
16
16
  export {
17
17
  DEFAULT_I18N_DIR,
18
18
  DEFAULT_L10N_DIR,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg-cli",
3
- "version": "0.1.3",
3
+ "version": "0.2.1",
4
4
  "description": "CLI for msg library",
5
5
  "main": "dist/commands/init.cjs",
6
6
  "module": "dist/commands/init.mjs",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@oclif/core": "^4.8.0",
34
- "@worldware/msg": "^0.6.1",
34
+ "@worldware/msg": "^0.6.4",
35
35
  "fast-xml-parser": "^5.3.4"
36
36
  },
37
37
  "devDependencies": {