@worldware/msg 0.11.1 → 0.12.0

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 CHANGED
@@ -159,6 +159,8 @@ Every message is formatted according to its resolved `format` attribute:
159
159
 
160
160
  The `format` is inheritable: a resource inherits its project's `format` unless it sets its own, and a message inherits its resource's `format` unless it sets its own. The default is `MF2`, so existing code keeps working unchanged. Use a TypeScript union (`'MF1' | 'MF2' | 'NONE'`) — there is no enum.
161
161
 
162
+ `lang`, `dir`, and `dnt` inherit the same way on messages: omitted fields (or omitted `attributes`) take the resource's values, and an explicit per-message value still wins. Compact translation JSON can therefore list only overrides. `create()`, `add()`, `translate()`, and `getTranslation()` all apply this merge.
163
+
162
164
  The following is a **separate illustration** of format inheritance and per-message overrides (not the CLI `Main` / `Messages` scaffold above):
163
165
 
164
166
  ```typescript
@@ -112,6 +112,9 @@ var MsgResource = class _MsgResource extends Map {
112
112
  /**
113
113
  * Adds a message to this resource, merging resource attributes with any overrides.
114
114
  *
115
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
116
+ * values on the message win.
117
+ *
115
118
  * @returns This resource, for chaining.
116
119
  */
117
120
  add(key, value, attributes, notes) {
@@ -129,7 +132,8 @@ var MsgResource = class _MsgResource extends Map {
129
132
  * Builds a translated copy of this resource from translation data.
130
133
  *
131
134
  * Messages present in the translation replace the source; missing keys keep
132
- * the source message. Notes are carried over from the source.
135
+ * the source message. Notes are carried over from the source. Unspecified
136
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
133
137
  *
134
138
  * @throws {TypeError} When the translation title does not match this resource.
135
139
  */
@@ -150,17 +154,13 @@ var MsgResource = class _MsgResource extends Map {
150
154
  });
151
155
  messages?.forEach((messageData) => {
152
156
  const { key, value, attributes: attributes2 } = messageData;
153
- const msg = MsgMessage.create({
157
+ const source = this.get(key);
158
+ translated.add(
154
159
  key,
155
160
  value,
156
- // preserve the source message's format unless the translation overrides it
157
- attributes: this.preserveFormat(attributes2, this.get(key)?.attributes.format)
158
- });
159
- const notes = this.get(key)?.notes || [];
160
- notes.forEach((note) => {
161
- msg.addNote(note.type, note.content);
162
- });
163
- translated.set(key, msg);
161
+ this.preserveFormat(attributes2, source?.attributes.format),
162
+ source?.notes
163
+ );
164
164
  });
165
165
  return translated;
166
166
  }
@@ -351,6 +351,9 @@ var MsgResource = class _MsgResource extends Map {
351
351
  /**
352
352
  * Adds a message to this resource, merging resource attributes with any overrides.
353
353
  *
354
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
355
+ * values on the message win.
356
+ *
354
357
  * @returns This resource, for chaining.
355
358
  */
356
359
  add(key, value, attributes, notes) {
@@ -368,7 +371,8 @@ var MsgResource = class _MsgResource extends Map {
368
371
  * Builds a translated copy of this resource from translation data.
369
372
  *
370
373
  * Messages present in the translation replace the source; missing keys keep
371
- * the source message. Notes are carried over from the source.
374
+ * the source message. Notes are carried over from the source. Unspecified
375
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
372
376
  *
373
377
  * @throws {TypeError} When the translation title does not match this resource.
374
378
  */
@@ -389,17 +393,13 @@ var MsgResource = class _MsgResource extends Map {
389
393
  });
390
394
  messages?.forEach((messageData) => {
391
395
  const { key, value, attributes: attributes2 } = messageData;
392
- const msg = MsgMessage.create({
396
+ const source = this.get(key);
397
+ translated.add(
393
398
  key,
394
399
  value,
395
- // preserve the source message's format unless the translation overrides it
396
- attributes: this.preserveFormat(attributes2, this.get(key)?.attributes.format)
397
- });
398
- const notes = this.get(key)?.notes || [];
399
- notes.forEach((note) => {
400
- msg.addNote(note.type, note.content);
401
- });
402
- translated.set(key, msg);
400
+ this.preserveFormat(attributes2, source?.attributes.format),
401
+ source?.notes
402
+ );
403
403
  });
404
404
  return translated;
405
405
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MsgResource
3
- } from "../../chunk-VDOVMTPF.mjs";
3
+ } from "../../chunk-CRT2A2HP.mjs";
4
4
  import "../../chunk-GHDKBE4P.mjs";
5
5
  import "../../chunk-RMZ42XIY.mjs";
6
6
  import "../../chunk-QU3HGZUN.mjs";
@@ -355,6 +355,9 @@ var MsgResource = class _MsgResource extends Map {
355
355
  /**
356
356
  * Adds a message to this resource, merging resource attributes with any overrides.
357
357
  *
358
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
359
+ * values on the message win.
360
+ *
358
361
  * @returns This resource, for chaining.
359
362
  */
360
363
  add(key, value, attributes, notes) {
@@ -372,7 +375,8 @@ var MsgResource = class _MsgResource extends Map {
372
375
  * Builds a translated copy of this resource from translation data.
373
376
  *
374
377
  * Messages present in the translation replace the source; missing keys keep
375
- * the source message. Notes are carried over from the source.
378
+ * the source message. Notes are carried over from the source. Unspecified
379
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
376
380
  *
377
381
  * @throws {TypeError} When the translation title does not match this resource.
378
382
  */
@@ -393,17 +397,13 @@ var MsgResource = class _MsgResource extends Map {
393
397
  });
394
398
  messages?.forEach((messageData) => {
395
399
  const { key, value, attributes: attributes2 } = messageData;
396
- const msg = MsgMessage.create({
400
+ const source = this.get(key);
401
+ translated.add(
397
402
  key,
398
403
  value,
399
- // preserve the source message's format unless the translation overrides it
400
- attributes: this.preserveFormat(attributes2, this.get(key)?.attributes.format)
401
- });
402
- const notes = this.get(key)?.notes || [];
403
- notes.forEach((note) => {
404
- msg.addNote(note.type, note.content);
405
- });
406
- translated.set(key, msg);
404
+ this.preserveFormat(attributes2, source?.attributes.format),
405
+ source?.notes
406
+ );
407
407
  });
408
408
  return translated;
409
409
  }
@@ -77,6 +77,9 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
77
77
  /**
78
78
  * Adds a message to this resource, merging resource attributes with any overrides.
79
79
  *
80
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
81
+ * values on the message win.
82
+ *
80
83
  * @returns This resource, for chaining.
81
84
  */
82
85
  add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
@@ -84,7 +87,8 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
84
87
  * Builds a translated copy of this resource from translation data.
85
88
  *
86
89
  * Messages present in the translation replace the source; missing keys keep
87
- * the source message. Notes are carried over from the source.
90
+ * the source message. Notes are carried over from the source. Unspecified
91
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
88
92
  *
89
93
  * @throws {TypeError} When the translation title does not match this resource.
90
94
  */
@@ -77,6 +77,9 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
77
77
  /**
78
78
  * Adds a message to this resource, merging resource attributes with any overrides.
79
79
  *
80
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
81
+ * values on the message win.
82
+ *
80
83
  * @returns This resource, for chaining.
81
84
  */
82
85
  add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
@@ -84,7 +87,8 @@ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterfac
84
87
  * Builds a translated copy of this resource from translation data.
85
88
  *
86
89
  * Messages present in the translation replace the source; missing keys keep
87
- * the source message. Notes are carried over from the source.
90
+ * the source message. Notes are carried over from the source. Unspecified
91
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
88
92
  *
89
93
  * @throws {TypeError} When the translation title does not match this resource.
90
94
  */
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-DJFPVXQ5.mjs";
5
5
  import {
6
6
  MsgResource
7
- } from "../chunk-VDOVMTPF.mjs";
7
+ } from "../chunk-CRT2A2HP.mjs";
8
8
  import "../chunk-GHDKBE4P.mjs";
9
9
  import {
10
10
  MsgMessage
package/dist/index.cjs CHANGED
@@ -361,6 +361,9 @@ var MsgResource = class _MsgResource extends Map {
361
361
  /**
362
362
  * Adds a message to this resource, merging resource attributes with any overrides.
363
363
  *
364
+ * Unspecified `lang`, `dir`, and `dnt` inherit from this resource; explicit
365
+ * values on the message win.
366
+ *
364
367
  * @returns This resource, for chaining.
365
368
  */
366
369
  add(key, value, attributes, notes) {
@@ -378,7 +381,8 @@ var MsgResource = class _MsgResource extends Map {
378
381
  * Builds a translated copy of this resource from translation data.
379
382
  *
380
383
  * Messages present in the translation replace the source; missing keys keep
381
- * the source message. Notes are carried over from the source.
384
+ * the source message. Notes are carried over from the source. Unspecified
385
+ * message `lang`, `dir`, and `dnt` inherit from the translated resource.
382
386
  *
383
387
  * @throws {TypeError} When the translation title does not match this resource.
384
388
  */
@@ -399,17 +403,13 @@ var MsgResource = class _MsgResource extends Map {
399
403
  });
400
404
  messages?.forEach((messageData) => {
401
405
  const { key, value, attributes: attributes2 } = messageData;
402
- const msg = MsgMessage.create({
406
+ const source = this.get(key);
407
+ translated.add(
403
408
  key,
404
409
  value,
405
- // preserve the source message's format unless the translation overrides it
406
- attributes: this.preserveFormat(attributes2, this.get(key)?.attributes.format)
407
- });
408
- const notes = this.get(key)?.notes || [];
409
- notes.forEach((note) => {
410
- msg.addNote(note.type, note.content);
411
- });
412
- translated.set(key, msg);
410
+ this.preserveFormat(attributes2, source?.attributes.format),
411
+ source?.notes
412
+ );
413
413
  });
414
414
  return translated;
415
415
  }
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-DJFPVXQ5.mjs";
5
5
  import {
6
6
  MsgResource
7
- } from "./chunk-VDOVMTPF.mjs";
7
+ } from "./chunk-CRT2A2HP.mjs";
8
8
  import "./chunk-KI3KVHLZ.mjs";
9
9
  import {
10
10
  getLang,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldware/msg",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "Message localization tooling",
5
5
  "license": "MIT",
6
6
  "author": "Joel Sahleen",