@worldware/msg-cli 0.5.0 → 0.5.2
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 +4 -4
- package/dist/{chunk-MGHC4AYZ.mjs → chunk-HH6ZOHO4.mjs} +11 -14
- package/dist/{chunk-LPZ6YNLY.mjs → chunk-NJKP7C5U.mjs} +3 -3
- package/dist/{chunk-XID5J2F7.mjs → chunk-PQJA3H4Z.mjs} +1 -1
- package/dist/{chunk-XMMVPJHX.mjs → chunk-ZAU52MSA.mjs} +4 -4
- package/dist/commands/create/project.cjs +2 -2
- package/dist/commands/create/project.mjs +2 -2
- package/dist/commands/export.cjs +2 -2
- package/dist/commands/export.mjs +3 -3
- package/dist/commands/import.cjs +12 -15
- package/dist/commands/import.mjs +3 -3
- package/dist/lib/export-helpers.cjs +2 -2
- package/dist/lib/export-helpers.mjs +3 -3
- package/dist/lib/import-helpers.cjs +12 -15
- package/dist/lib/import-helpers.mjs +3 -3
- package/dist/lib/pgs-mf1.mjs +2 -2
- package/dist/lib/pgs-mf2.cjs +11 -14
- package/dist/lib/pgs-mf2.d.mts +3 -0
- package/dist/lib/pgs-mf2.d.ts +3 -0
- package/dist/lib/pgs-mf2.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -232,9 +232,9 @@ msg export -p myApp
|
|
|
232
232
|
|
|
233
233
|
- **Message keys** — Stored as unit `id` (sanitized for XML) and `name` (original key).
|
|
234
234
|
- **Resource notes** — Emitted as file-level `<notes>` with category (e.g. `description`, `comment`).
|
|
235
|
-
- **Resource attributes** — `dir` → file `srcDir`; `dnt` → file `translate="no"`.
|
|
235
|
+
- **Resource attributes** — `dir` → file `srcDir` when it is not the default `"auto"`; `dnt` → file `translate="no"`.
|
|
236
236
|
- **Message notes** — Emitted as unit-level `<notes>` with category (e.g. `description`, `context`, `parameters`).
|
|
237
|
-
- **Message attributes** — `dnt` → unit `translate="no"`; message `dir` is serialized as the unit’s `srcDir`
|
|
237
|
+
- **Message attributes** — `dnt` → unit `translate="no"`; message `dir` is serialized as the unit’s `srcDir` unless it is `"auto"`.
|
|
238
238
|
- **Message format** — Resolved `format` (`NONE` / `MF1` / `MF2`, including inheritance from resource/project) is written as the unit `type` attribute using the XLIFF custom form `msg:NONE`, `msg:MF1`, or `msg:MF2`.
|
|
239
239
|
|
|
240
240
|
**Plural, gender, select (PGS):** Classifiable plural/select messages are exported to the [XLIFF 2.2 Plural, Gender, and Select module](https://docs.oasis-open.org/xliff/xliff-core/v2.2/xliff-extended-v2.2-part2.html) (`xmlns:pgs="urn:oasis:names:tc:xliff:pgs:1.0"`): `pgs:switch` on the `<unit>`, and one `<segment>` per variant with `pgs:case`.
|
|
@@ -354,14 +354,14 @@ msg import
|
|
|
354
354
|
# or: msg import --project myApp --language fr
|
|
355
355
|
```
|
|
356
356
|
|
|
357
|
-
**5. Resulting French translation file** — `l10n/translations/myApp/fr/messages.json` (notes omitted; `attributes.dir` is
|
|
357
|
+
**5. Resulting French translation file** — `l10n/translations/myApp/fr/messages.json` (notes omitted; `attributes.dir` is `"auto"` unless the XLIFF `<file>` carries `trgDir`):
|
|
358
358
|
|
|
359
359
|
```json
|
|
360
360
|
{
|
|
361
361
|
"title": "messages",
|
|
362
362
|
"attributes": {
|
|
363
363
|
"lang": "fr",
|
|
364
|
-
"dir": "",
|
|
364
|
+
"dir": "auto",
|
|
365
365
|
"dnt": false
|
|
366
366
|
},
|
|
367
367
|
"messages": [
|
|
@@ -154,17 +154,6 @@ function selectMessageToPgsExport(source) {
|
|
|
154
154
|
}
|
|
155
155
|
return selectMessageDataToPgsExport(msg);
|
|
156
156
|
}
|
|
157
|
-
function parsePatternFromSegmentBody(body) {
|
|
158
|
-
const trimmed = body.trim();
|
|
159
|
-
if (!trimmed) return [];
|
|
160
|
-
try {
|
|
161
|
-
const m = parseMessage(trimmed);
|
|
162
|
-
if (m.type !== "message") return [];
|
|
163
|
-
return m.pattern;
|
|
164
|
-
} catch {
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
157
|
function ensureFallbackVariant(keysCount, variants) {
|
|
169
158
|
const hasAllStars = variants.some(
|
|
170
159
|
(v) => v.keys.length === keysCount && v.keys.every((k) => isCatchallKey(k))
|
|
@@ -226,11 +215,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
226
215
|
const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
|
|
227
216
|
if (tokens.length !== n) return null;
|
|
228
217
|
const keys = tokens.map(
|
|
229
|
-
(t,
|
|
218
|
+
(t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
|
|
230
219
|
);
|
|
231
220
|
variants.push({
|
|
232
221
|
keys,
|
|
233
|
-
|
|
222
|
+
// Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
|
|
223
|
+
// body so `\t` / `\n` / `\{` are not dropped or double-escaped.
|
|
224
|
+
value: []
|
|
234
225
|
});
|
|
235
226
|
}
|
|
236
227
|
if (variants.length === 0) return null;
|
|
@@ -248,9 +239,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
248
239
|
} catch {
|
|
249
240
|
return null;
|
|
250
241
|
}
|
|
251
|
-
|
|
242
|
+
const bodies = segments.map((seg) => seg.body);
|
|
243
|
+
while (bodies.length < msg.variants.length) {
|
|
244
|
+
bodies.push(segments[segments.length - 1]?.body ?? "");
|
|
245
|
+
}
|
|
246
|
+
const skeleton = stringifyMessage(
|
|
252
247
|
msg
|
|
253
248
|
);
|
|
249
|
+
let i = 0;
|
|
250
|
+
return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
|
|
254
251
|
}
|
|
255
252
|
function messagesStructurallyEqual(a, b) {
|
|
256
253
|
try {
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-Q775ZGC5.mjs";
|
|
4
4
|
import {
|
|
5
5
|
pgsImportToMf1Message
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PQJA3H4Z.mjs";
|
|
7
7
|
import {
|
|
8
8
|
pgsImportToSelectMessage
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-HH6ZOHO4.mjs";
|
|
10
10
|
import {
|
|
11
11
|
dynamicImportFromUrl
|
|
12
12
|
} from "./chunk-PO2Z7EWJ.mjs";
|
|
@@ -245,7 +245,7 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
245
245
|
const dnt = translate === "no" || translate === "false";
|
|
246
246
|
const attributes = {
|
|
247
247
|
lang: trgLang,
|
|
248
|
-
dir: trgDir ?? "",
|
|
248
|
+
dir: trgDir ?? "auto",
|
|
249
249
|
dnt
|
|
250
250
|
};
|
|
251
251
|
const notes = [];
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-Q775ZGC5.mjs";
|
|
5
5
|
import {
|
|
6
6
|
mf1MessageToPgsExport
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-PQJA3H4Z.mjs";
|
|
8
8
|
import {
|
|
9
9
|
selectMessageToPgsExport
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-HH6ZOHO4.mjs";
|
|
11
11
|
import {
|
|
12
12
|
dynamicImportFromUrl
|
|
13
13
|
} from "./chunk-PO2Z7EWJ.mjs";
|
|
@@ -144,7 +144,7 @@ function resourceGroupToXliff22(group) {
|
|
|
144
144
|
`id="${fileId}"`,
|
|
145
145
|
`original="${escapeXml(orig)}"`
|
|
146
146
|
];
|
|
147
|
-
if (attrs.dir) {
|
|
147
|
+
if (attrs.dir && attrs.dir !== "auto") {
|
|
148
148
|
fileAttrs.push(`srcDir="${escapeXml(attrs.dir)}"`);
|
|
149
149
|
}
|
|
150
150
|
if (attrs.dnt === true) {
|
|
@@ -167,7 +167,7 @@ function resourceGroupToXliff22(group) {
|
|
|
167
167
|
if (msgAttr?.dnt === true) {
|
|
168
168
|
msgAttrs.push('translate="no"');
|
|
169
169
|
}
|
|
170
|
-
if (msgAttr?.dir) {
|
|
170
|
+
if (msgAttr?.dir && msgAttr.dir !== "auto") {
|
|
171
171
|
msgAttrs.push(`srcDir="${escapeXml(msgAttr.dir)}"`);
|
|
172
172
|
}
|
|
173
173
|
const msgFormat = resolveMessageFormat(
|
|
@@ -273,7 +273,7 @@ var CreateProject = class _CreateProject extends import_core.Command {
|
|
|
273
273
|
}
|
|
274
274
|
const format = resolveCreateProjectFormat(flags.format, baseProject);
|
|
275
275
|
const loaderPathLine = "const path = `${TRANSLATION_IMPORT_PATH}/${project}/${language}/${title}.json`;";
|
|
276
|
-
const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded
|
|
276
|
+
const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded.`);";
|
|
277
277
|
const loaderBody = `${loaderPathLine}
|
|
278
278
|
try {
|
|
279
279
|
const module = await import(path, { with: { type: 'json' } });
|
|
@@ -282,7 +282,7 @@ var CreateProject = class _CreateProject extends import_core.Command {
|
|
|
282
282
|
${loaderWarnLine}
|
|
283
283
|
return {
|
|
284
284
|
title,
|
|
285
|
-
attributes: { lang: language, dir: '' },
|
|
285
|
+
attributes: { lang: language, dir: 'auto' },
|
|
286
286
|
notes: [],
|
|
287
287
|
messages: []
|
|
288
288
|
};
|
|
@@ -123,7 +123,7 @@ var CreateProject = class _CreateProject extends Command {
|
|
|
123
123
|
}
|
|
124
124
|
const format = resolveCreateProjectFormat(flags.format, baseProject);
|
|
125
125
|
const loaderPathLine = "const path = `${TRANSLATION_IMPORT_PATH}/${project}/${language}/${title}.json`;";
|
|
126
|
-
const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded
|
|
126
|
+
const loaderWarnLine = "console.warn(`Translations for locale ${language} could not be loaded.`);";
|
|
127
127
|
const loaderBody = `${loaderPathLine}
|
|
128
128
|
try {
|
|
129
129
|
const module = await import(path, { with: { type: 'json' } });
|
|
@@ -132,7 +132,7 @@ var CreateProject = class _CreateProject extends Command {
|
|
|
132
132
|
${loaderWarnLine}
|
|
133
133
|
return {
|
|
134
134
|
title,
|
|
135
|
-
attributes: { lang: language, dir: '' },
|
|
135
|
+
attributes: { lang: language, dir: 'auto' },
|
|
136
136
|
notes: [],
|
|
137
137
|
messages: []
|
|
138
138
|
};
|
package/dist/commands/export.cjs
CHANGED
|
@@ -470,7 +470,7 @@ function resourceGroupToXliff22(group) {
|
|
|
470
470
|
`id="${fileId}"`,
|
|
471
471
|
`original="${escapeXml(orig)}"`
|
|
472
472
|
];
|
|
473
|
-
if (attrs.dir) {
|
|
473
|
+
if (attrs.dir && attrs.dir !== "auto") {
|
|
474
474
|
fileAttrs.push(`srcDir="${escapeXml(attrs.dir)}"`);
|
|
475
475
|
}
|
|
476
476
|
if (attrs.dnt === true) {
|
|
@@ -493,7 +493,7 @@ function resourceGroupToXliff22(group) {
|
|
|
493
493
|
if (msgAttr?.dnt === true) {
|
|
494
494
|
msgAttrs.push('translate="no"');
|
|
495
495
|
}
|
|
496
|
-
if (msgAttr?.dir) {
|
|
496
|
+
if (msgAttr?.dir && msgAttr.dir !== "auto") {
|
|
497
497
|
msgAttrs.push(`srcDir="${escapeXml(msgAttr.dir)}"`);
|
|
498
498
|
}
|
|
499
499
|
const msgFormat = resolveMessageFormat(
|
package/dist/commands/export.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
importMsgResourcesFromPaths,
|
|
6
6
|
serializeResourceGroupsToXliff,
|
|
7
7
|
writeXliffFiles
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-ZAU52MSA.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-PQJA3H4Z.mjs";
|
|
11
|
+
import "../chunk-HH6ZOHO4.mjs";
|
|
12
12
|
import "../chunk-PO2Z7EWJ.mjs";
|
|
13
13
|
import {
|
|
14
14
|
loadPackageJsonForMsg
|
package/dist/commands/import.cjs
CHANGED
|
@@ -171,17 +171,6 @@ function pgsTokenToMf2Key(token, kind) {
|
|
|
171
171
|
}
|
|
172
172
|
return { type: "literal", value: token };
|
|
173
173
|
}
|
|
174
|
-
function parsePatternFromSegmentBody(body) {
|
|
175
|
-
const trimmed = body.trim();
|
|
176
|
-
if (!trimmed) return [];
|
|
177
|
-
try {
|
|
178
|
-
const m = (0, import_messageformat.parseMessage)(trimmed);
|
|
179
|
-
if (m.type !== "message") return [];
|
|
180
|
-
return m.pattern;
|
|
181
|
-
} catch {
|
|
182
|
-
return [];
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
174
|
function ensureFallbackVariant(keysCount, variants) {
|
|
186
175
|
const hasAllStars = variants.some(
|
|
187
176
|
(v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
|
|
@@ -243,11 +232,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
243
232
|
const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
|
|
244
233
|
if (tokens.length !== n) return null;
|
|
245
234
|
const keys = tokens.map(
|
|
246
|
-
(t,
|
|
235
|
+
(t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
|
|
247
236
|
);
|
|
248
237
|
variants.push({
|
|
249
238
|
keys,
|
|
250
|
-
|
|
239
|
+
// Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
|
|
240
|
+
// body so `\t` / `\n` / `\{` are not dropped or double-escaped.
|
|
241
|
+
value: []
|
|
251
242
|
});
|
|
252
243
|
}
|
|
253
244
|
if (variants.length === 0) return null;
|
|
@@ -265,9 +256,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
265
256
|
} catch {
|
|
266
257
|
return null;
|
|
267
258
|
}
|
|
268
|
-
|
|
259
|
+
const bodies = segments.map((seg) => seg.body);
|
|
260
|
+
while (bodies.length < msg.variants.length) {
|
|
261
|
+
bodies.push(segments[segments.length - 1]?.body ?? "");
|
|
262
|
+
}
|
|
263
|
+
const skeleton = (0, import_messageformat.stringifyMessage)(
|
|
269
264
|
msg
|
|
270
265
|
);
|
|
266
|
+
let i = 0;
|
|
267
|
+
return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
|
|
271
268
|
}
|
|
272
269
|
|
|
273
270
|
// src/lib/pgs-mf1.ts
|
|
@@ -602,7 +599,7 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
602
599
|
const dnt = translate === "no" || translate === "false";
|
|
603
600
|
const attributes = {
|
|
604
601
|
lang: trgLang,
|
|
605
|
-
dir: trgDir ?? "",
|
|
602
|
+
dir: trgDir ?? "auto",
|
|
606
603
|
dnt
|
|
607
604
|
};
|
|
608
605
|
const notes = [];
|
package/dist/commands/import.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
parseXliffFilename,
|
|
6
6
|
processXliffFile,
|
|
7
7
|
writeTranslationFiles
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-NJKP7C5U.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-PQJA3H4Z.mjs";
|
|
11
|
+
import "../chunk-HH6ZOHO4.mjs";
|
|
12
12
|
import "../chunk-PO2Z7EWJ.mjs";
|
|
13
13
|
import {
|
|
14
14
|
loadPackageJsonForMsg
|
|
@@ -407,7 +407,7 @@ function resourceGroupToXliff22(group) {
|
|
|
407
407
|
`id="${fileId}"`,
|
|
408
408
|
`original="${escapeXml(orig)}"`
|
|
409
409
|
];
|
|
410
|
-
if (attrs.dir) {
|
|
410
|
+
if (attrs.dir && attrs.dir !== "auto") {
|
|
411
411
|
fileAttrs.push(`srcDir="${escapeXml(attrs.dir)}"`);
|
|
412
412
|
}
|
|
413
413
|
if (attrs.dnt === true) {
|
|
@@ -430,7 +430,7 @@ function resourceGroupToXliff22(group) {
|
|
|
430
430
|
if (msgAttr?.dnt === true) {
|
|
431
431
|
msgAttrs.push('translate="no"');
|
|
432
432
|
}
|
|
433
|
-
if (msgAttr?.dir) {
|
|
433
|
+
if (msgAttr?.dir && msgAttr.dir !== "auto") {
|
|
434
434
|
msgAttrs.push(`srcDir="${escapeXml(msgAttr.dir)}"`);
|
|
435
435
|
}
|
|
436
436
|
const msgFormat = resolveMessageFormat(
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
importMsgResourcesFromPaths,
|
|
6
6
|
serializeResourceGroupsToXliff,
|
|
7
7
|
writeXliffFiles
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-ZAU52MSA.mjs";
|
|
9
9
|
import "../chunk-Q775ZGC5.mjs";
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-PQJA3H4Z.mjs";
|
|
11
|
+
import "../chunk-HH6ZOHO4.mjs";
|
|
12
12
|
import "../chunk-PO2Z7EWJ.mjs";
|
|
13
13
|
import "../chunk-F7XZRKP7.mjs";
|
|
14
14
|
export {
|
|
@@ -111,17 +111,6 @@ function pgsTokenToMf2Key(token, kind) {
|
|
|
111
111
|
}
|
|
112
112
|
return { type: "literal", value: token };
|
|
113
113
|
}
|
|
114
|
-
function parsePatternFromSegmentBody(body) {
|
|
115
|
-
const trimmed = body.trim();
|
|
116
|
-
if (!trimmed) return [];
|
|
117
|
-
try {
|
|
118
|
-
const m = (0, import_messageformat.parseMessage)(trimmed);
|
|
119
|
-
if (m.type !== "message") return [];
|
|
120
|
-
return m.pattern;
|
|
121
|
-
} catch {
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
114
|
function ensureFallbackVariant(keysCount, variants) {
|
|
126
115
|
const hasAllStars = variants.some(
|
|
127
116
|
(v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
|
|
@@ -183,11 +172,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
183
172
|
const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
|
|
184
173
|
if (tokens.length !== n) return null;
|
|
185
174
|
const keys = tokens.map(
|
|
186
|
-
(t,
|
|
175
|
+
(t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
|
|
187
176
|
);
|
|
188
177
|
variants.push({
|
|
189
178
|
keys,
|
|
190
|
-
|
|
179
|
+
// Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
|
|
180
|
+
// body so `\t` / `\n` / `\{` are not dropped or double-escaped.
|
|
181
|
+
value: []
|
|
191
182
|
});
|
|
192
183
|
}
|
|
193
184
|
if (variants.length === 0) return null;
|
|
@@ -205,9 +196,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
205
196
|
} catch {
|
|
206
197
|
return null;
|
|
207
198
|
}
|
|
208
|
-
|
|
199
|
+
const bodies = segments.map((seg) => seg.body);
|
|
200
|
+
while (bodies.length < msg.variants.length) {
|
|
201
|
+
bodies.push(segments[segments.length - 1]?.body ?? "");
|
|
202
|
+
}
|
|
203
|
+
const skeleton = (0, import_messageformat.stringifyMessage)(
|
|
209
204
|
msg
|
|
210
205
|
);
|
|
206
|
+
let i = 0;
|
|
207
|
+
return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
|
|
211
208
|
}
|
|
212
209
|
|
|
213
210
|
// src/lib/pgs-mf1.ts
|
|
@@ -542,7 +539,7 @@ function extractResourceFromXliffFile(fileEl, xliffTrgLang, project, targetLocal
|
|
|
542
539
|
const dnt = translate === "no" || translate === "false";
|
|
543
540
|
const attributes = {
|
|
544
541
|
lang: trgLang,
|
|
545
|
-
dir: trgDir ?? "",
|
|
542
|
+
dir: trgDir ?? "auto",
|
|
546
543
|
dnt
|
|
547
544
|
};
|
|
548
545
|
const notes = [];
|
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
parseXliffFilename,
|
|
9
9
|
processXliffFile,
|
|
10
10
|
writeTranslationFiles
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-NJKP7C5U.mjs";
|
|
12
12
|
import "../chunk-Q775ZGC5.mjs";
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-PQJA3H4Z.mjs";
|
|
14
|
+
import "../chunk-HH6ZOHO4.mjs";
|
|
15
15
|
import "../chunk-PO2Z7EWJ.mjs";
|
|
16
16
|
import "../chunk-F7XZRKP7.mjs";
|
|
17
17
|
export {
|
package/dist/lib/pgs-mf1.mjs
CHANGED
package/dist/lib/pgs-mf2.cjs
CHANGED
|
@@ -178,17 +178,6 @@ function selectMessageToPgsExport(source) {
|
|
|
178
178
|
}
|
|
179
179
|
return selectMessageDataToPgsExport(msg);
|
|
180
180
|
}
|
|
181
|
-
function parsePatternFromSegmentBody(body) {
|
|
182
|
-
const trimmed = body.trim();
|
|
183
|
-
if (!trimmed) return [];
|
|
184
|
-
try {
|
|
185
|
-
const m = (0, import_messageformat.parseMessage)(trimmed);
|
|
186
|
-
if (m.type !== "message") return [];
|
|
187
|
-
return m.pattern;
|
|
188
|
-
} catch {
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
181
|
function ensureFallbackVariant(keysCount, variants) {
|
|
193
182
|
const hasAllStars = variants.some(
|
|
194
183
|
(v) => v.keys.length === keysCount && v.keys.every((k) => (0, import_messageformat.isCatchallKey)(k))
|
|
@@ -250,11 +239,13 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
250
239
|
const tokens = seg.caseAttr.trim().split(/\s+/).filter(Boolean);
|
|
251
240
|
if (tokens.length !== n) return null;
|
|
252
241
|
const keys = tokens.map(
|
|
253
|
-
(t,
|
|
242
|
+
(t, i2) => pgsTokenToMf2Key(t, parsedSwitch[i2].kind)
|
|
254
243
|
);
|
|
255
244
|
variants.push({
|
|
256
245
|
keys,
|
|
257
|
-
|
|
246
|
+
// Empty pattern: stringify emits `{{}}`, then we splice the raw XLIFF
|
|
247
|
+
// body so `\t` / `\n` / `\{` are not dropped or double-escaped.
|
|
248
|
+
value: []
|
|
258
249
|
});
|
|
259
250
|
}
|
|
260
251
|
if (variants.length === 0) return null;
|
|
@@ -272,9 +263,15 @@ function pgsImportToSelectMessage(switchAttr, segments) {
|
|
|
272
263
|
} catch {
|
|
273
264
|
return null;
|
|
274
265
|
}
|
|
275
|
-
|
|
266
|
+
const bodies = segments.map((seg) => seg.body);
|
|
267
|
+
while (bodies.length < msg.variants.length) {
|
|
268
|
+
bodies.push(segments[segments.length - 1]?.body ?? "");
|
|
269
|
+
}
|
|
270
|
+
const skeleton = (0, import_messageformat.stringifyMessage)(
|
|
276
271
|
msg
|
|
277
272
|
);
|
|
273
|
+
let i = 0;
|
|
274
|
+
return skeleton.replace(/\{\{\}\}/g, () => `{{${bodies[i++] ?? ""}}}`);
|
|
278
275
|
}
|
|
279
276
|
function messagesStructurallyEqual(a, b) {
|
|
280
277
|
try {
|
package/dist/lib/pgs-mf2.d.mts
CHANGED
|
@@ -73,6 +73,9 @@ interface PgsSegmentImport {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Builds MF2 source string from PGS `pgs:switch` and segment bodies.
|
|
76
|
+
*
|
|
77
|
+
* Segment bodies are spliced into quoted patterns as-is so XLIFF `\` sequences
|
|
78
|
+
* are not dropped (`\t`/`\n` are invalid MF2 escapes) or double-escaped.
|
|
76
79
|
*/
|
|
77
80
|
declare function pgsImportToSelectMessage(switchAttr: string, segments: PgsSegmentImport[]): string | null;
|
|
78
81
|
/** Compare two MF2 strings by parsing and re-stringifying both (for tests). */
|
package/dist/lib/pgs-mf2.d.ts
CHANGED
|
@@ -73,6 +73,9 @@ interface PgsSegmentImport {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Builds MF2 source string from PGS `pgs:switch` and segment bodies.
|
|
76
|
+
*
|
|
77
|
+
* Segment bodies are spliced into quoted patterns as-is so XLIFF `\` sequences
|
|
78
|
+
* are not dropped (`\t`/`\n` are invalid MF2 escapes) or double-escaped.
|
|
76
79
|
*/
|
|
77
80
|
declare function pgsImportToSelectMessage(switchAttr: string, segments: PgsSegmentImport[]): string | null;
|
|
78
81
|
/** Compare two MF2 strings by parsing and re-stringifying both (for tests). */
|
package/dist/lib/pgs-mf2.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worldware/msg-cli",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "CLI for msg library",
|
|
5
5
|
"main": "dist/commands/init.cjs",
|
|
6
6
|
"module": "dist/commands/init.mjs",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"@messageformat/icu-messageformat-1": "^0.12.0",
|
|
40
40
|
"@messageformat/parser": "^5.1.1",
|
|
41
41
|
"@oclif/core": "^3.21.2",
|
|
42
|
-
"@worldware/msg": "^0.
|
|
42
|
+
"@worldware/msg": "^0.12.0",
|
|
43
43
|
"fast-xml-parser": "^5.3.4",
|
|
44
44
|
"messageformat": "^4.0.0-10"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^22.0.0",
|
|
48
48
|
"@vitest/coverage-v8": "^4.0.18",
|
|
49
|
-
"semantic-release": "^25.0.
|
|
49
|
+
"semantic-release": "^25.0.9",
|
|
50
50
|
"ts-node": "^10.9.2",
|
|
51
51
|
"tsup": "^8.5.1",
|
|
52
52
|
"typedoc": "^0.28.20",
|