@worldware/msg-cli 0.3.0 → 0.3.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.
@@ -91,7 +91,7 @@ function loadPackageJsonForMsg(cwd, options) {
91
91
  }
92
92
 
93
93
  // src/lib/import-helpers.ts
94
- var import_msg = require("@worldware/msg");
94
+ var import_msg2 = require("@worldware/msg");
95
95
  var import_promises = require("fs/promises");
96
96
  var import_path2 = require("path");
97
97
  var import_url2 = require("url");
@@ -124,6 +124,29 @@ async function dynamicImportFromUrl(url) {
124
124
  }
125
125
  }
126
126
 
127
+ // src/lib/msg-format.ts
128
+ var import_msg = require("@worldware/msg");
129
+ var MSG_TYPE_PREFIX = "msg";
130
+ var FORMAT_VALUES = /* @__PURE__ */ new Set(["NONE", "MF1", "MF2"]);
131
+ function unitTypeToFormat(type) {
132
+ if (type == null || type === "") return void 0;
133
+ if (FORMAT_VALUES.has(type)) {
134
+ return type;
135
+ }
136
+ const prefixed = new RegExp(
137
+ `^${MSG_TYPE_PREFIX}:(NONE|MF1|MF2)$`
138
+ ).exec(type);
139
+ if (prefixed?.[1] && FORMAT_VALUES.has(prefixed[1])) {
140
+ return prefixed[1];
141
+ }
142
+ return void 0;
143
+ }
144
+
145
+ // src/lib/pgs-mf1.ts
146
+ var import_parser = require("@messageformat/parser");
147
+ var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
148
+ var import_messageformat2 = require("messageformat");
149
+
127
150
  // src/lib/pgs-mf2.ts
128
151
  var import_messageformat = require("messageformat");
129
152
  var PGS_SWITCH_ITEM = /^(plural|ordinal|gender|select):([a-zA-Z_][a-zA-Z0-9_]*)$/;
@@ -247,6 +270,110 @@ function pgsImportToSelectMessage(switchAttr, segments) {
247
270
  );
248
271
  }
249
272
 
273
+ // src/lib/pgs-mf1.ts
274
+ function kindToIcuType(kind) {
275
+ if (kind === "plural") return "plural";
276
+ if (kind === "ordinal") return "selectordinal";
277
+ return "select";
278
+ }
279
+ function pluralVarNames(parsedSwitch) {
280
+ const names = /* @__PURE__ */ new Set();
281
+ for (const { kind, name } of parsedSwitch) {
282
+ if (kind === "plural" || kind === "ordinal") names.add(name);
283
+ }
284
+ return names;
285
+ }
286
+ function segmentBodyToMf1(body, hashVars) {
287
+ const trimmed = body.trim();
288
+ if (!trimmed) return "";
289
+ try {
290
+ const msg = (0, import_messageformat2.parseMessage)(trimmed);
291
+ if (msg.type !== "message") {
292
+ return escapeIcuLiteral(trimmed);
293
+ }
294
+ return patternPartsToMf1(
295
+ msg.pattern,
296
+ hashVars
297
+ );
298
+ } catch {
299
+ return escapeIcuLiteral(trimmed);
300
+ }
301
+ }
302
+ function patternPartsToMf1(pattern, hashVars) {
303
+ let out = "";
304
+ for (const part of pattern) {
305
+ if (typeof part === "string") {
306
+ out += escapeIcuLiteral(part);
307
+ continue;
308
+ }
309
+ if (!part || typeof part !== "object") continue;
310
+ const expr = part;
311
+ if (expr.type === "expression" && expr.arg?.type === "variable" && expr.arg.name) {
312
+ const name = expr.arg.name;
313
+ out += hashVars.has(name) ? "#" : `{${name}}`;
314
+ continue;
315
+ }
316
+ }
317
+ return out;
318
+ }
319
+ function escapeIcuLiteral(s) {
320
+ return s.replace(/'/g, "''").replace(/([{}])/g, "'$1'");
321
+ }
322
+ function insertCase(tree, tokens, body, depth) {
323
+ if (tokens.length === 0) return false;
324
+ const token = tokens[depth];
325
+ if (token === void 0) return false;
326
+ if (depth === tokens.length - 1) {
327
+ tree.set(token, body);
328
+ return true;
329
+ }
330
+ let child = tree.get(token);
331
+ if (typeof child === "string") return false;
332
+ if (!child) {
333
+ child = /* @__PURE__ */ new Map();
334
+ tree.set(token, child);
335
+ }
336
+ return insertCase(child, tokens, body, depth + 1);
337
+ }
338
+ function serializeCaseTree(tree, parsedSwitch, depth, hashVars) {
339
+ const item = parsedSwitch[depth];
340
+ if (!item) return null;
341
+ const icuType = kindToIcuType(item.kind);
342
+ const parts = [];
343
+ for (const [key, child] of tree) {
344
+ let content;
345
+ if (typeof child === "string") {
346
+ content = segmentBodyToMf1(child, hashVars);
347
+ } else {
348
+ const nested = serializeCaseTree(
349
+ child,
350
+ parsedSwitch,
351
+ depth + 1,
352
+ hashVars
353
+ );
354
+ if (nested == null) return null;
355
+ content = nested;
356
+ }
357
+ parts.push(`${key} {${content}}`);
358
+ }
359
+ if (parts.length === 0) return null;
360
+ return `{${item.name}, ${icuType}, ${parts.join(" ")}}`;
361
+ }
362
+ function pgsImportToMf1Message(switchAttr, segments) {
363
+ const parsedSwitch = parsePgsSwitch(switchAttr);
364
+ if (!parsedSwitch || parsedSwitch.length === 0) return null;
365
+ const n = parsedSwitch.length;
366
+ if (segments.length === 0) return null;
367
+ const hashVars = pluralVarNames(parsedSwitch);
368
+ const tree = /* @__PURE__ */ new Map();
369
+ for (const seg of segments) {
370
+ const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
371
+ if (tokens.length !== n) return null;
372
+ if (!insertCase(tree, tokens, seg.body, 0)) return null;
373
+ }
374
+ return serializeCaseTree(tree, parsedSwitch, 0, hashVars);
375
+ }
376
+
250
377
  // src/lib/import-helpers.ts
251
378
  var XLIFF_EXTENSIONS = [".xliff", ".xlf"];
252
379
  var XLIFF_FILENAME_PATTERN = /^(.+?)(?:\.([a-zA-Z]{2,}(?:-[a-zA-Z0-9]+)*))?\.(?:xliff|xlf)$/i;
@@ -422,6 +549,7 @@ function processUnit(unit, fileAttrs) {
422
549
  const trgDir = unit["@_trgDir"] ?? fileAttrs.trgDir;
423
550
  const translate = (unit["@_translate"] ?? "yes").toLowerCase();
424
551
  const dnt = translate === "no" || translate === "false";
552
+ const format = unitTypeToFormat(unit["@_type"]);
425
553
  const fileTranslate = (fileAttrs.translate ?? "yes").toLowerCase();
426
554
  const fileDnt = fileTranslate === "no" || fileTranslate === "false";
427
555
  const notes = [];
@@ -437,6 +565,7 @@ function processUnit(unit, fileAttrs) {
437
565
  }
438
566
  const segments = unit.segment ? Array.isArray(unit.segment) ? unit.segment : [unit.segment] : [];
439
567
  const pgsSwitch = unit["@_pgs:switch"];
568
+ const joinSegmentTexts = () => segments.map((seg) => extractSegmentText(seg)).join("");
440
569
  let value;
441
570
  if (pgsSwitch && segments.length > 0 && segments.every(
442
571
  (seg) => typeof seg["@_pgs:case"] === "string"
@@ -445,27 +574,16 @@ function processUnit(unit, fileAttrs) {
445
574
  caseAttr: seg["@_pgs:case"],
446
575
  body: extractSegmentText(seg)
447
576
  }));
448
- const rebuilt = pgsImportToSelectMessage(pgsSwitch, importSegments);
449
- if (rebuilt) {
450
- value = rebuilt;
451
- } else {
452
- const targetParts = [];
453
- for (const seg of segments) {
454
- targetParts.push(extractSegmentText(seg));
455
- }
456
- value = targetParts.join("");
457
- }
577
+ const rebuilt = format === "MF1" ? pgsImportToMf1Message(pgsSwitch, importSegments) : pgsImportToSelectMessage(pgsSwitch, importSegments);
578
+ value = rebuilt ?? joinSegmentTexts();
458
579
  } else {
459
- const targetParts = [];
460
- for (const seg of segments) {
461
- targetParts.push(extractSegmentText(seg));
462
- }
463
- value = targetParts.join("");
580
+ value = joinSegmentTexts();
464
581
  }
465
582
  const attributes = {};
466
583
  if (trgLang !== fileAttrs.trgLang) attributes.lang = trgLang || void 0;
467
584
  if (trgDir !== fileAttrs.trgDir) attributes.dir = trgDir || void 0;
468
585
  if (dnt !== fileDnt) attributes.dnt = dnt;
586
+ if (format) attributes.format = format;
469
587
  return {
470
588
  key: name,
471
589
  value,
@@ -525,7 +643,7 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
525
643
  }))
526
644
  };
527
645
  const proj = project;
528
- return import_msg.MsgResource.create(resourceData, proj);
646
+ return import_msg2.MsgResource.create(resourceData, proj);
529
647
  }
530
648
  async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
531
649
  let project;
@@ -5,8 +5,10 @@ import {
5
5
  parseXliffFilename,
6
6
  processXliffFile,
7
7
  writeTranslationFiles
8
- } from "../chunk-DIY2WO3R.mjs";
9
- import "../chunk-DPUF7YUH.mjs";
8
+ } from "../chunk-4Z65MYW7.mjs";
9
+ import "../chunk-Q775ZGC5.mjs";
10
+ import "../chunk-XID5J2F7.mjs";
11
+ import "../chunk-MGHC4AYZ.mjs";
10
12
  import "../chunk-LNCUPVEF.mjs";
11
13
  import {
12
14
  loadPackageJsonForMsg
@@ -28,6 +28,7 @@ __export(export_helpers_exports, {
28
28
  writeXliffFiles: () => writeXliffFiles
29
29
  });
30
30
  module.exports = __toCommonJS(export_helpers_exports);
31
+ var import_msg2 = require("@worldware/msg");
31
32
  var import_promises = require("fs/promises");
32
33
  var import_path = require("path");
33
34
  var import_url2 = require("url");
@@ -58,14 +59,42 @@ async function dynamicImportFromUrl(url) {
58
59
  }
59
60
  }
60
61
 
62
+ // src/lib/msg-format.ts
63
+ var import_msg = require("@worldware/msg");
64
+ var MSG_TYPE_PREFIX = "msg";
65
+ function formatToUnitType(format) {
66
+ return `${MSG_TYPE_PREFIX}:${format}`;
67
+ }
68
+ function resolveMessageFormat(messageFormat, resourceFormat, projectFormat) {
69
+ return messageFormat ?? resourceFormat ?? projectFormat ?? import_msg.MSG_DEFAULT_FORMAT;
70
+ }
71
+
72
+ // src/lib/pgs-mf1.ts
73
+ var import_parser = require("@messageformat/parser");
74
+ var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
75
+ var import_messageformat2 = require("messageformat");
76
+
61
77
  // src/lib/pgs-mf2.ts
62
78
  var import_messageformat = require("messageformat");
79
+ var PGS_SWITCH_ITEM = /^(plural|ordinal|gender|select):([a-zA-Z_][a-zA-Z0-9_]*)$/;
63
80
  var GENDER_LABELS = /* @__PURE__ */ new Set([
64
81
  "feminine",
65
82
  "masculine",
66
83
  "neuter",
67
84
  "other"
68
85
  ]);
86
+ function parsePgsSwitch(value) {
87
+ const trimmed = value.trim();
88
+ if (!trimmed) return null;
89
+ const parts = trimmed.split(/\s+/);
90
+ const out = [];
91
+ for (const p of parts) {
92
+ const m = p.match(PGS_SWITCH_ITEM);
93
+ if (!m) return null;
94
+ out.push({ kind: m[1], name: m[2] });
95
+ }
96
+ return out.length > 0 ? out : null;
97
+ }
69
98
  function findInputDeclaration(msg, varName) {
70
99
  for (const d of msg.declarations) {
71
100
  const decl = d;
@@ -78,10 +107,13 @@ function findInputDeclaration(msg, varName) {
78
107
  function getFunctionName(expr) {
79
108
  return expr.functionRef?.name;
80
109
  }
110
+ function getOption(opts, key) {
111
+ if (!opts) return void 0;
112
+ if (opts instanceof Map) return opts.get(key);
113
+ return opts[key];
114
+ }
81
115
  function getSelectOptionOrdinal(expr) {
82
- const opts = expr.functionRef?.options;
83
- if (!opts || !(opts instanceof Map)) return false;
84
- const sel = opts.get("select");
116
+ const sel = getOption(expr.functionRef?.options, "select");
85
117
  if (!sel || typeof sel !== "object" || sel === null) return false;
86
118
  if (sel.type !== "literal") return false;
87
119
  return sel.value === "ordinal";
@@ -149,13 +181,7 @@ function stringifyPattern(pattern) {
149
181
  wrap
150
182
  );
151
183
  }
152
- function selectMessageToPgsExport(source) {
153
- let msg;
154
- try {
155
- msg = (0, import_messageformat.parseMessage)(source);
156
- } catch {
157
- return null;
158
- }
184
+ function selectMessageDataToPgsExport(msg) {
159
185
  if (!(0, import_messageformat.isSelectMessage)(msg)) return null;
160
186
  const classification = classifySelectMessageForPgs(
161
187
  msg
@@ -170,9 +196,7 @@ function selectMessageToPgsExport(source) {
170
196
  for (let ki = 0; ki < classification.length; ki++) {
171
197
  const key = variant.keys[ki];
172
198
  if (!key) return null;
173
- caseParts.push(
174
- mf2KeyToPgsToken(key, classification[ki].kind)
175
- );
199
+ caseParts.push(mf2KeyToPgsToken(key, classification[ki].kind));
176
200
  }
177
201
  segments.push({
178
202
  caseAttr: caseParts.join(" "),
@@ -181,6 +205,79 @@ function selectMessageToPgsExport(source) {
181
205
  }
182
206
  return { switchAttr, segments };
183
207
  }
208
+ function selectMessageToPgsExport(source) {
209
+ let msg;
210
+ try {
211
+ msg = (0, import_messageformat.parseMessage)(source);
212
+ } catch {
213
+ return null;
214
+ }
215
+ return selectMessageDataToPgsExport(msg);
216
+ }
217
+
218
+ // src/lib/pgs-mf1.ts
219
+ function mf1MessageToPgsExport(source) {
220
+ try {
221
+ const data = (0, import_icu_messageformat_1.mf1ToMessageData)((0, import_parser.parse)(source));
222
+ const exp = selectMessageDataToPgsExport(data);
223
+ if (!exp) return null;
224
+ const parsedSwitch = parsePgsSwitch(exp.switchAttr);
225
+ if (!parsedSwitch) return null;
226
+ const hashVars = pluralVarNames(parsedSwitch);
227
+ return {
228
+ switchAttr: exp.switchAttr,
229
+ segments: exp.segments.map((seg) => ({
230
+ caseAttr: seg.caseAttr,
231
+ sourcePattern: segmentBodyToMf1(seg.sourcePattern, hashVars)
232
+ }))
233
+ };
234
+ } catch {
235
+ return null;
236
+ }
237
+ }
238
+ function pluralVarNames(parsedSwitch) {
239
+ const names = /* @__PURE__ */ new Set();
240
+ for (const { kind, name } of parsedSwitch) {
241
+ if (kind === "plural" || kind === "ordinal") names.add(name);
242
+ }
243
+ return names;
244
+ }
245
+ function segmentBodyToMf1(body, hashVars) {
246
+ const trimmed = body.trim();
247
+ if (!trimmed) return "";
248
+ try {
249
+ const msg = (0, import_messageformat2.parseMessage)(trimmed);
250
+ if (msg.type !== "message") {
251
+ return escapeIcuLiteral(trimmed);
252
+ }
253
+ return patternPartsToMf1(
254
+ msg.pattern,
255
+ hashVars
256
+ );
257
+ } catch {
258
+ return escapeIcuLiteral(trimmed);
259
+ }
260
+ }
261
+ function patternPartsToMf1(pattern, hashVars) {
262
+ let out = "";
263
+ for (const part of pattern) {
264
+ if (typeof part === "string") {
265
+ out += escapeIcuLiteral(part);
266
+ continue;
267
+ }
268
+ if (!part || typeof part !== "object") continue;
269
+ const expr = part;
270
+ if (expr.type === "expression" && expr.arg?.type === "variable" && expr.arg.name) {
271
+ const name = expr.arg.name;
272
+ out += hashVars.has(name) ? "#" : `{${name}}`;
273
+ continue;
274
+ }
275
+ }
276
+ return out;
277
+ }
278
+ function escapeIcuLiteral(s) {
279
+ return s.replace(/'/g, "''").replace(/([{}])/g, "'$1'");
280
+ }
184
281
 
185
282
  // src/lib/export-helpers.ts
186
283
  var MSG_PATTERN = /\.msg\.(ts|js)$/i;
@@ -271,6 +368,11 @@ function renderNotes(notes, idPrefix, indent = " ") {
271
368
  parts.push(`${indent}</notes>`);
272
369
  return parts;
273
370
  }
371
+ function pgsExportForFormat(format, value) {
372
+ if (format === "MF1") return mf1MessageToPgsExport(value);
373
+ if (format === "MF2") return selectMessageToPgsExport(value);
374
+ return null;
375
+ }
274
376
  function resourceGroupToXliff22(group) {
275
377
  const srcLang = group.resources[0]?.attributes?.lang ?? "en";
276
378
  const parts = [
@@ -283,6 +385,12 @@ function resourceGroupToXliff22(group) {
283
385
  fileIndex += 1;
284
386
  const fileId = `f${fileIndex}`;
285
387
  const attrs = resource.attributes ?? {};
388
+ const projectFormat = resource.getProject().format ?? import_msg2.MSG_DEFAULT_FORMAT;
389
+ const resourceFormat = resolveMessageFormat(
390
+ void 0,
391
+ attrs.format,
392
+ projectFormat
393
+ );
286
394
  const fileAttrs = [
287
395
  `id="${fileId}"`,
288
396
  `original="${escapeXml(orig)}"`
@@ -313,7 +421,13 @@ function resourceGroupToXliff22(group) {
313
421
  if (msgAttr?.dir) {
314
422
  msgAttrs.push(`srcDir="${escapeXml(msgAttr.dir)}"`);
315
423
  }
316
- const pgsExport = selectMessageToPgsExport(msg.value);
424
+ const msgFormat = resolveMessageFormat(
425
+ msgAttr?.format,
426
+ resourceFormat,
427
+ projectFormat
428
+ );
429
+ msgAttrs.push(`type="${escapeXml(formatToUnitType(msgFormat))}"`);
430
+ const pgsExport = pgsExportForFormat(msgFormat, msg.value);
317
431
  if (pgsExport) {
318
432
  msgAttrs.push(`pgs:switch="${escapeXml(pgsExport.switchAttr)}"`);
319
433
  }
@@ -5,8 +5,10 @@ import {
5
5
  importMsgResourcesFromPaths,
6
6
  serializeResourceGroupsToXliff,
7
7
  writeXliffFiles
8
- } from "../chunk-XHD7F45F.mjs";
9
- import "../chunk-DPUF7YUH.mjs";
8
+ } from "../chunk-6BLQESHW.mjs";
9
+ import "../chunk-Q775ZGC5.mjs";
10
+ import "../chunk-XID5J2F7.mjs";
11
+ import "../chunk-MGHC4AYZ.mjs";
10
12
  import "../chunk-LNCUPVEF.mjs";
11
13
  import "../chunk-F7XZRKP7.mjs";
12
14
  export {
@@ -31,7 +31,7 @@ __export(import_helpers_exports, {
31
31
  writeTranslationFiles: () => writeTranslationFiles
32
32
  });
33
33
  module.exports = __toCommonJS(import_helpers_exports);
34
- var import_msg = require("@worldware/msg");
34
+ var import_msg2 = require("@worldware/msg");
35
35
  var import_promises = require("fs/promises");
36
36
  var import_path = require("path");
37
37
  var import_url2 = require("url");
@@ -64,6 +64,29 @@ async function dynamicImportFromUrl(url) {
64
64
  }
65
65
  }
66
66
 
67
+ // src/lib/msg-format.ts
68
+ var import_msg = require("@worldware/msg");
69
+ var MSG_TYPE_PREFIX = "msg";
70
+ var FORMAT_VALUES = /* @__PURE__ */ new Set(["NONE", "MF1", "MF2"]);
71
+ function unitTypeToFormat(type) {
72
+ if (type == null || type === "") return void 0;
73
+ if (FORMAT_VALUES.has(type)) {
74
+ return type;
75
+ }
76
+ const prefixed = new RegExp(
77
+ `^${MSG_TYPE_PREFIX}:(NONE|MF1|MF2)$`
78
+ ).exec(type);
79
+ if (prefixed?.[1] && FORMAT_VALUES.has(prefixed[1])) {
80
+ return prefixed[1];
81
+ }
82
+ return void 0;
83
+ }
84
+
85
+ // src/lib/pgs-mf1.ts
86
+ var import_parser = require("@messageformat/parser");
87
+ var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
88
+ var import_messageformat2 = require("messageformat");
89
+
67
90
  // src/lib/pgs-mf2.ts
68
91
  var import_messageformat = require("messageformat");
69
92
  var PGS_SWITCH_ITEM = /^(plural|ordinal|gender|select):([a-zA-Z_][a-zA-Z0-9_]*)$/;
@@ -187,6 +210,110 @@ function pgsImportToSelectMessage(switchAttr, segments) {
187
210
  );
188
211
  }
189
212
 
213
+ // src/lib/pgs-mf1.ts
214
+ function kindToIcuType(kind) {
215
+ if (kind === "plural") return "plural";
216
+ if (kind === "ordinal") return "selectordinal";
217
+ return "select";
218
+ }
219
+ function pluralVarNames(parsedSwitch) {
220
+ const names = /* @__PURE__ */ new Set();
221
+ for (const { kind, name } of parsedSwitch) {
222
+ if (kind === "plural" || kind === "ordinal") names.add(name);
223
+ }
224
+ return names;
225
+ }
226
+ function segmentBodyToMf1(body, hashVars) {
227
+ const trimmed = body.trim();
228
+ if (!trimmed) return "";
229
+ try {
230
+ const msg = (0, import_messageformat2.parseMessage)(trimmed);
231
+ if (msg.type !== "message") {
232
+ return escapeIcuLiteral(trimmed);
233
+ }
234
+ return patternPartsToMf1(
235
+ msg.pattern,
236
+ hashVars
237
+ );
238
+ } catch {
239
+ return escapeIcuLiteral(trimmed);
240
+ }
241
+ }
242
+ function patternPartsToMf1(pattern, hashVars) {
243
+ let out = "";
244
+ for (const part of pattern) {
245
+ if (typeof part === "string") {
246
+ out += escapeIcuLiteral(part);
247
+ continue;
248
+ }
249
+ if (!part || typeof part !== "object") continue;
250
+ const expr = part;
251
+ if (expr.type === "expression" && expr.arg?.type === "variable" && expr.arg.name) {
252
+ const name = expr.arg.name;
253
+ out += hashVars.has(name) ? "#" : `{${name}}`;
254
+ continue;
255
+ }
256
+ }
257
+ return out;
258
+ }
259
+ function escapeIcuLiteral(s) {
260
+ return s.replace(/'/g, "''").replace(/([{}])/g, "'$1'");
261
+ }
262
+ function insertCase(tree, tokens, body, depth) {
263
+ if (tokens.length === 0) return false;
264
+ const token = tokens[depth];
265
+ if (token === void 0) return false;
266
+ if (depth === tokens.length - 1) {
267
+ tree.set(token, body);
268
+ return true;
269
+ }
270
+ let child = tree.get(token);
271
+ if (typeof child === "string") return false;
272
+ if (!child) {
273
+ child = /* @__PURE__ */ new Map();
274
+ tree.set(token, child);
275
+ }
276
+ return insertCase(child, tokens, body, depth + 1);
277
+ }
278
+ function serializeCaseTree(tree, parsedSwitch, depth, hashVars) {
279
+ const item = parsedSwitch[depth];
280
+ if (!item) return null;
281
+ const icuType = kindToIcuType(item.kind);
282
+ const parts = [];
283
+ for (const [key, child] of tree) {
284
+ let content;
285
+ if (typeof child === "string") {
286
+ content = segmentBodyToMf1(child, hashVars);
287
+ } else {
288
+ const nested = serializeCaseTree(
289
+ child,
290
+ parsedSwitch,
291
+ depth + 1,
292
+ hashVars
293
+ );
294
+ if (nested == null) return null;
295
+ content = nested;
296
+ }
297
+ parts.push(`${key} {${content}}`);
298
+ }
299
+ if (parts.length === 0) return null;
300
+ return `{${item.name}, ${icuType}, ${parts.join(" ")}}`;
301
+ }
302
+ function pgsImportToMf1Message(switchAttr, segments) {
303
+ const parsedSwitch = parsePgsSwitch(switchAttr);
304
+ if (!parsedSwitch || parsedSwitch.length === 0) return null;
305
+ const n = parsedSwitch.length;
306
+ if (segments.length === 0) return null;
307
+ const hashVars = pluralVarNames(parsedSwitch);
308
+ const tree = /* @__PURE__ */ new Map();
309
+ for (const seg of segments) {
310
+ const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
311
+ if (tokens.length !== n) return null;
312
+ if (!insertCase(tree, tokens, seg.body, 0)) return null;
313
+ }
314
+ return serializeCaseTree(tree, parsedSwitch, 0, hashVars);
315
+ }
316
+
190
317
  // src/lib/import-helpers.ts
191
318
  var XLIFF_EXTENSIONS = [".xliff", ".xlf"];
192
319
  var XLIFF_FILENAME_PATTERN = /^(.+?)(?:\.([a-zA-Z]{2,}(?:-[a-zA-Z0-9]+)*))?\.(?:xliff|xlf)$/i;
@@ -362,6 +489,7 @@ function processUnit(unit, fileAttrs) {
362
489
  const trgDir = unit["@_trgDir"] ?? fileAttrs.trgDir;
363
490
  const translate = (unit["@_translate"] ?? "yes").toLowerCase();
364
491
  const dnt = translate === "no" || translate === "false";
492
+ const format = unitTypeToFormat(unit["@_type"]);
365
493
  const fileTranslate = (fileAttrs.translate ?? "yes").toLowerCase();
366
494
  const fileDnt = fileTranslate === "no" || fileTranslate === "false";
367
495
  const notes = [];
@@ -377,6 +505,7 @@ function processUnit(unit, fileAttrs) {
377
505
  }
378
506
  const segments = unit.segment ? Array.isArray(unit.segment) ? unit.segment : [unit.segment] : [];
379
507
  const pgsSwitch = unit["@_pgs:switch"];
508
+ const joinSegmentTexts = () => segments.map((seg) => extractSegmentText(seg)).join("");
380
509
  let value;
381
510
  if (pgsSwitch && segments.length > 0 && segments.every(
382
511
  (seg) => typeof seg["@_pgs:case"] === "string"
@@ -385,27 +514,16 @@ function processUnit(unit, fileAttrs) {
385
514
  caseAttr: seg["@_pgs:case"],
386
515
  body: extractSegmentText(seg)
387
516
  }));
388
- const rebuilt = pgsImportToSelectMessage(pgsSwitch, importSegments);
389
- if (rebuilt) {
390
- value = rebuilt;
391
- } else {
392
- const targetParts = [];
393
- for (const seg of segments) {
394
- targetParts.push(extractSegmentText(seg));
395
- }
396
- value = targetParts.join("");
397
- }
517
+ const rebuilt = format === "MF1" ? pgsImportToMf1Message(pgsSwitch, importSegments) : pgsImportToSelectMessage(pgsSwitch, importSegments);
518
+ value = rebuilt ?? joinSegmentTexts();
398
519
  } else {
399
- const targetParts = [];
400
- for (const seg of segments) {
401
- targetParts.push(extractSegmentText(seg));
402
- }
403
- value = targetParts.join("");
520
+ value = joinSegmentTexts();
404
521
  }
405
522
  const attributes = {};
406
523
  if (trgLang !== fileAttrs.trgLang) attributes.lang = trgLang || void 0;
407
524
  if (trgDir !== fileAttrs.trgDir) attributes.dir = trgDir || void 0;
408
525
  if (dnt !== fileDnt) attributes.dnt = dnt;
526
+ if (format) attributes.format = format;
409
527
  return {
410
528
  key: name,
411
529
  value,
@@ -465,7 +583,7 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
465
583
  }))
466
584
  };
467
585
  const proj = project;
468
- return import_msg.MsgResource.create(resourceData, proj);
586
+ return import_msg2.MsgResource.create(resourceData, proj);
469
587
  }
470
588
  async function processXliffFile(xliffPath, projectsDir, projectName, locale) {
471
589
  let project;
@@ -8,8 +8,10 @@ import {
8
8
  parseXliffFilename,
9
9
  processXliffFile,
10
10
  writeTranslationFiles
11
- } from "../chunk-DIY2WO3R.mjs";
12
- import "../chunk-DPUF7YUH.mjs";
11
+ } from "../chunk-4Z65MYW7.mjs";
12
+ import "../chunk-Q775ZGC5.mjs";
13
+ import "../chunk-XID5J2F7.mjs";
14
+ import "../chunk-MGHC4AYZ.mjs";
13
15
  import "../chunk-LNCUPVEF.mjs";
14
16
  import "../chunk-F7XZRKP7.mjs";
15
17
  export {