@worldware/msg 0.11.0 → 0.11.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.
- package/README.md +2 -2
- package/dist/chunk-QU3HGZUN.mjs +16 -0
- package/dist/{chunk-OKEV7FY7.mjs → chunk-RMZ42XIY.mjs} +4 -2
- package/dist/{chunk-K35ZABAI.mjs → chunk-VDOVMTPF.mjs} +6 -4
- package/dist/classes/MsgInterface/MsgInterface.d.cts +1 -1
- package/dist/classes/MsgInterface/MsgInterface.d.ts +1 -1
- package/dist/classes/MsgMessage/MsgMessage.cjs +10 -1
- package/dist/classes/MsgMessage/MsgMessage.mjs +2 -1
- package/dist/classes/MsgResource/MsgResource.cjs +12 -3
- package/dist/classes/MsgResource/MsgResource.mjs +3 -2
- package/dist/classes/index.cjs +14 -3
- package/dist/classes/index.mjs +6 -5
- package/dist/index.cjs +14 -3
- package/dist/index.mjs +6 -5
- package/dist/lib/apply-attributes.cjs +45 -0
- package/dist/lib/apply-attributes.d.cts +11 -0
- package/dist/lib/apply-attributes.d.ts +11 -0
- package/dist/lib/apply-attributes.mjs +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ const loader = async (project, title, language) => {
|
|
|
67
67
|
console.warn(`Translations for locale ${language} could not be loaded.`, error);
|
|
68
68
|
return {
|
|
69
69
|
title,
|
|
70
|
-
attributes: { lang: language, dir: '' },
|
|
70
|
+
attributes: { lang: language, dir: 'auto' },
|
|
71
71
|
notes: [],
|
|
72
72
|
messages: []
|
|
73
73
|
};
|
|
@@ -332,7 +332,7 @@ const data = resource.getData();
|
|
|
332
332
|
### Types
|
|
333
333
|
|
|
334
334
|
- `MsgFormat` - `'MF1' | 'MF2' | 'NONE'`; the formatting syntax for a message.
|
|
335
|
-
- `MsgAttributes` - `{ lang?: string; dir?: string; dnt?: boolean; format?: MsgFormat }`.
|
|
335
|
+
- `MsgAttributes` - `{ lang?: string; dir?: string; dnt?: boolean; format?: MsgFormat }`. Omitted or empty `dir` resolves to `'auto'`.
|
|
336
336
|
|
|
337
337
|
### Pseudo-localization helpers
|
|
338
338
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ATTRIBUTES
|
|
3
|
+
} from "./chunk-XQVALCKX.mjs";
|
|
4
|
+
|
|
5
|
+
// src/lib/apply-attributes.ts
|
|
6
|
+
function applyAttributes(attributes, extras) {
|
|
7
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
8
|
+
if (!merged.dir) {
|
|
9
|
+
merged.dir = "auto";
|
|
10
|
+
}
|
|
11
|
+
return merged;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
applyAttributes
|
|
16
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
applyAttributes
|
|
3
|
+
} from "./chunk-QU3HGZUN.mjs";
|
|
4
|
+
import {
|
|
3
5
|
MSG_DEFAULT_FORMAT
|
|
4
6
|
} from "./chunk-XQVALCKX.mjs";
|
|
5
7
|
|
|
@@ -18,7 +20,7 @@ var MsgMessage = class _MsgMessage {
|
|
|
18
20
|
constructor(key, value, attributes, notes) {
|
|
19
21
|
this._key = key;
|
|
20
22
|
this._value = value;
|
|
21
|
-
this._attributes = attributes
|
|
23
|
+
this._attributes = applyAttributes(attributes);
|
|
22
24
|
if (notes) {
|
|
23
25
|
notes.forEach((note) => this.setNote(note));
|
|
24
26
|
}
|
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
} from "./chunk-GHDKBE4P.mjs";
|
|
4
4
|
import {
|
|
5
5
|
MsgMessage
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RMZ42XIY.mjs";
|
|
7
|
+
import {
|
|
8
|
+
applyAttributes
|
|
9
|
+
} from "./chunk-QU3HGZUN.mjs";
|
|
7
10
|
import {
|
|
8
|
-
DEFAULT_ATTRIBUTES,
|
|
9
11
|
MSG_DEFAULT_FORMAT
|
|
10
12
|
} from "./chunk-XQVALCKX.mjs";
|
|
11
13
|
|
|
@@ -40,7 +42,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
40
42
|
constructor(title, attributes, project, notes) {
|
|
41
43
|
super();
|
|
42
44
|
this._title = title;
|
|
43
|
-
this._attributes = {
|
|
45
|
+
this._attributes = applyAttributes(attributes, { format: project.format });
|
|
44
46
|
this._project = project;
|
|
45
47
|
if (notes) {
|
|
46
48
|
notes.forEach((note) => this.setNote(note));
|
|
@@ -66,7 +68,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
66
68
|
}
|
|
67
69
|
/** Replaces the resource's locale and formatting metadata. */
|
|
68
70
|
set attributes(attributes) {
|
|
69
|
-
this._attributes = attributes;
|
|
71
|
+
this._attributes = applyAttributes(attributes);
|
|
70
72
|
}
|
|
71
73
|
/** Notes attached to this resource for translators and tooling. */
|
|
72
74
|
get notes() {
|
|
@@ -30,7 +30,7 @@ declare const MSG_DEFAULT_FORMAT: MsgFormat;
|
|
|
30
30
|
type MsgAttributes = {
|
|
31
31
|
/** BCP 47 language tag for the content (for example, `en` or `zh-Hans`). */
|
|
32
32
|
lang?: string;
|
|
33
|
-
/** Text direction: typically `ltr`, `rtl`, or `auto`. */
|
|
33
|
+
/** Text direction: typically `ltr`, `rtl`, or `auto`. Omitted or empty values resolve to `'auto'`. */
|
|
34
34
|
dir?: string;
|
|
35
35
|
/** When true, the content should not be translated (Do Not Translate). */
|
|
36
36
|
dnt?: boolean;
|
|
@@ -30,7 +30,7 @@ declare const MSG_DEFAULT_FORMAT: MsgFormat;
|
|
|
30
30
|
type MsgAttributes = {
|
|
31
31
|
/** BCP 47 language tag for the content (for example, `en` or `zh-Hans`). */
|
|
32
32
|
lang?: string;
|
|
33
|
-
/** Text direction: typically `ltr`, `rtl`, or `auto`. */
|
|
33
|
+
/** Text direction: typically `ltr`, `rtl`, or `auto`. Omitted or empty values resolve to `'auto'`. */
|
|
34
34
|
dir?: string;
|
|
35
35
|
/** When true, the content should not be translated (Do Not Translate). */
|
|
36
36
|
dnt?: boolean;
|
|
@@ -34,6 +34,15 @@ var DEFAULT_ATTRIBUTES = {
|
|
|
34
34
|
dnt: false
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// src/lib/apply-attributes.ts
|
|
38
|
+
function applyAttributes(attributes, extras) {
|
|
39
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
40
|
+
if (!merged.dir) {
|
|
41
|
+
merged.dir = "auto";
|
|
42
|
+
}
|
|
43
|
+
return merged;
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
// src/classes/MsgMessage/MsgMessage.ts
|
|
38
47
|
var MsgMessage = class _MsgMessage {
|
|
39
48
|
_key;
|
|
@@ -47,7 +56,7 @@ var MsgMessage = class _MsgMessage {
|
|
|
47
56
|
constructor(key, value, attributes, notes) {
|
|
48
57
|
this._key = key;
|
|
49
58
|
this._value = value;
|
|
50
|
-
this._attributes = attributes
|
|
59
|
+
this._attributes = applyAttributes(attributes);
|
|
51
60
|
if (notes) {
|
|
52
61
|
notes.forEach((note) => this.setNote(note));
|
|
53
62
|
}
|
|
@@ -36,6 +36,15 @@ var DEFAULT_ATTRIBUTES = {
|
|
|
36
36
|
dnt: false
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
// src/lib/apply-attributes.ts
|
|
40
|
+
function applyAttributes(attributes, extras) {
|
|
41
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
42
|
+
if (!merged.dir) {
|
|
43
|
+
merged.dir = "auto";
|
|
44
|
+
}
|
|
45
|
+
return merged;
|
|
46
|
+
}
|
|
47
|
+
|
|
39
48
|
// src/classes/MsgMessage/MsgMessage.ts
|
|
40
49
|
var MsgMessage = class _MsgMessage {
|
|
41
50
|
_key;
|
|
@@ -49,7 +58,7 @@ var MsgMessage = class _MsgMessage {
|
|
|
49
58
|
constructor(key, value, attributes, notes) {
|
|
50
59
|
this._key = key;
|
|
51
60
|
this._value = value;
|
|
52
|
-
this._attributes = attributes
|
|
61
|
+
this._attributes = applyAttributes(attributes);
|
|
53
62
|
if (notes) {
|
|
54
63
|
notes.forEach((note) => this.setNote(note));
|
|
55
64
|
}
|
|
@@ -272,7 +281,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
272
281
|
constructor(title, attributes, project, notes) {
|
|
273
282
|
super();
|
|
274
283
|
this._title = title;
|
|
275
|
-
this._attributes = {
|
|
284
|
+
this._attributes = applyAttributes(attributes, { format: project.format });
|
|
276
285
|
this._project = project;
|
|
277
286
|
if (notes) {
|
|
278
287
|
notes.forEach((note) => this.setNote(note));
|
|
@@ -298,7 +307,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
298
307
|
}
|
|
299
308
|
/** Replaces the resource's locale and formatting metadata. */
|
|
300
309
|
set attributes(attributes) {
|
|
301
|
-
this._attributes = attributes;
|
|
310
|
+
this._attributes = applyAttributes(attributes);
|
|
302
311
|
}
|
|
303
312
|
/** Notes attached to this resource for translators and tooling. */
|
|
304
313
|
get notes() {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MsgResource
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-VDOVMTPF.mjs";
|
|
4
4
|
import "../../chunk-GHDKBE4P.mjs";
|
|
5
|
-
import "../../chunk-
|
|
5
|
+
import "../../chunk-RMZ42XIY.mjs";
|
|
6
|
+
import "../../chunk-QU3HGZUN.mjs";
|
|
6
7
|
import "../../chunk-XQVALCKX.mjs";
|
|
7
8
|
export {
|
|
8
9
|
MsgResource
|
package/dist/classes/index.cjs
CHANGED
|
@@ -39,6 +39,17 @@ var DEFAULT_ATTRIBUTES = {
|
|
|
39
39
|
// src/classes/MsgMessage/MsgMessage.ts
|
|
40
40
|
var import_messageformat = require("messageformat");
|
|
41
41
|
var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
|
|
42
|
+
|
|
43
|
+
// src/lib/apply-attributes.ts
|
|
44
|
+
function applyAttributes(attributes, extras) {
|
|
45
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
46
|
+
if (!merged.dir) {
|
|
47
|
+
merged.dir = "auto";
|
|
48
|
+
}
|
|
49
|
+
return merged;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/classes/MsgMessage/MsgMessage.ts
|
|
42
53
|
var MsgMessage = class _MsgMessage {
|
|
43
54
|
_key;
|
|
44
55
|
_value;
|
|
@@ -51,7 +62,7 @@ var MsgMessage = class _MsgMessage {
|
|
|
51
62
|
constructor(key, value, attributes, notes) {
|
|
52
63
|
this._key = key;
|
|
53
64
|
this._value = value;
|
|
54
|
-
this._attributes = attributes
|
|
65
|
+
this._attributes = applyAttributes(attributes);
|
|
55
66
|
if (notes) {
|
|
56
67
|
notes.forEach((note) => this.setNote(note));
|
|
57
68
|
}
|
|
@@ -274,7 +285,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
274
285
|
constructor(title, attributes, project, notes) {
|
|
275
286
|
super();
|
|
276
287
|
this._title = title;
|
|
277
|
-
this._attributes = {
|
|
288
|
+
this._attributes = applyAttributes(attributes, { format: project.format });
|
|
278
289
|
this._project = project;
|
|
279
290
|
if (notes) {
|
|
280
291
|
notes.forEach((note) => this.setNote(note));
|
|
@@ -300,7 +311,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
300
311
|
}
|
|
301
312
|
/** Replaces the resource's locale and formatting metadata. */
|
|
302
313
|
set attributes(attributes) {
|
|
303
|
-
this._attributes = attributes;
|
|
314
|
+
this._attributes = applyAttributes(attributes);
|
|
304
315
|
}
|
|
305
316
|
/** Notes attached to this resource for translators and tooling. */
|
|
306
317
|
get notes() {
|
package/dist/classes/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import "../chunk-ORHP7HGX.mjs";
|
|
2
|
+
import {
|
|
3
|
+
MsgProject
|
|
4
|
+
} from "../chunk-DJFPVXQ5.mjs";
|
|
2
5
|
import {
|
|
3
6
|
MsgResource
|
|
4
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-VDOVMTPF.mjs";
|
|
5
8
|
import "../chunk-GHDKBE4P.mjs";
|
|
6
9
|
import {
|
|
7
10
|
MsgMessage
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import
|
|
10
|
-
MsgProject
|
|
11
|
-
} from "../chunk-DJFPVXQ5.mjs";
|
|
11
|
+
} from "../chunk-RMZ42XIY.mjs";
|
|
12
|
+
import "../chunk-QU3HGZUN.mjs";
|
|
12
13
|
import {
|
|
13
14
|
DEFAULT_ATTRIBUTES,
|
|
14
15
|
MSG_DEFAULT_FORMAT
|
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,17 @@ var DEFAULT_ATTRIBUTES = {
|
|
|
45
45
|
// src/classes/MsgMessage/MsgMessage.ts
|
|
46
46
|
var import_messageformat = require("messageformat");
|
|
47
47
|
var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
|
|
48
|
+
|
|
49
|
+
// src/lib/apply-attributes.ts
|
|
50
|
+
function applyAttributes(attributes, extras) {
|
|
51
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
52
|
+
if (!merged.dir) {
|
|
53
|
+
merged.dir = "auto";
|
|
54
|
+
}
|
|
55
|
+
return merged;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/classes/MsgMessage/MsgMessage.ts
|
|
48
59
|
var MsgMessage = class _MsgMessage {
|
|
49
60
|
_key;
|
|
50
61
|
_value;
|
|
@@ -57,7 +68,7 @@ var MsgMessage = class _MsgMessage {
|
|
|
57
68
|
constructor(key, value, attributes, notes) {
|
|
58
69
|
this._key = key;
|
|
59
70
|
this._value = value;
|
|
60
|
-
this._attributes = attributes
|
|
71
|
+
this._attributes = applyAttributes(attributes);
|
|
61
72
|
if (notes) {
|
|
62
73
|
notes.forEach((note) => this.setNote(note));
|
|
63
74
|
}
|
|
@@ -280,7 +291,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
280
291
|
constructor(title, attributes, project, notes) {
|
|
281
292
|
super();
|
|
282
293
|
this._title = title;
|
|
283
|
-
this._attributes = {
|
|
294
|
+
this._attributes = applyAttributes(attributes, { format: project.format });
|
|
284
295
|
this._project = project;
|
|
285
296
|
if (notes) {
|
|
286
297
|
notes.forEach((note) => this.setNote(note));
|
|
@@ -306,7 +317,7 @@ var MsgResource = class _MsgResource extends Map {
|
|
|
306
317
|
}
|
|
307
318
|
/** Replaces the resource's locale and formatting metadata. */
|
|
308
319
|
set attributes(attributes) {
|
|
309
|
-
this._attributes = attributes;
|
|
320
|
+
this._attributes = applyAttributes(attributes);
|
|
310
321
|
}
|
|
311
322
|
/** Notes attached to this resource for translators and tooling. */
|
|
312
323
|
get notes() {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import "./chunk-ORHP7HGX.mjs";
|
|
2
|
+
import {
|
|
3
|
+
MsgProject
|
|
4
|
+
} from "./chunk-DJFPVXQ5.mjs";
|
|
2
5
|
import {
|
|
3
6
|
MsgResource
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VDOVMTPF.mjs";
|
|
5
8
|
import "./chunk-KI3KVHLZ.mjs";
|
|
6
9
|
import {
|
|
7
10
|
getLang,
|
|
@@ -15,10 +18,8 @@ import {
|
|
|
15
18
|
} from "./chunk-GHDKBE4P.mjs";
|
|
16
19
|
import {
|
|
17
20
|
MsgMessage
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import
|
|
20
|
-
MsgProject
|
|
21
|
-
} from "./chunk-DJFPVXQ5.mjs";
|
|
21
|
+
} from "./chunk-RMZ42XIY.mjs";
|
|
22
|
+
import "./chunk-QU3HGZUN.mjs";
|
|
22
23
|
import {
|
|
23
24
|
DEFAULT_ATTRIBUTES,
|
|
24
25
|
MSG_DEFAULT_FORMAT
|
|
@@ -0,0 +1,45 @@
|
|
|
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/apply-attributes.ts
|
|
21
|
+
var apply_attributes_exports = {};
|
|
22
|
+
__export(apply_attributes_exports, {
|
|
23
|
+
applyAttributes: () => applyAttributes
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(apply_attributes_exports);
|
|
26
|
+
|
|
27
|
+
// src/classes/MsgInterface/MsgInterface.ts
|
|
28
|
+
var DEFAULT_ATTRIBUTES = {
|
|
29
|
+
lang: "und",
|
|
30
|
+
dir: "auto",
|
|
31
|
+
dnt: false
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/lib/apply-attributes.ts
|
|
35
|
+
function applyAttributes(attributes, extras) {
|
|
36
|
+
const merged = { ...DEFAULT_ATTRIBUTES, ...extras, ...attributes };
|
|
37
|
+
if (!merged.dir) {
|
|
38
|
+
merged.dir = "auto";
|
|
39
|
+
}
|
|
40
|
+
return merged;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
applyAttributes
|
|
45
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MsgAttributes } from '../classes/MsgInterface/MsgInterface.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges {@link DEFAULT_ATTRIBUTES} with optional extras and caller attributes.
|
|
5
|
+
*
|
|
6
|
+
* An empty-string `dir` is treated as unset and becomes `'auto'`. This helper
|
|
7
|
+
* is module-internal (not re-exported from the public API).
|
|
8
|
+
*/
|
|
9
|
+
declare function applyAttributes(attributes?: MsgAttributes, extras?: MsgAttributes): MsgAttributes;
|
|
10
|
+
|
|
11
|
+
export { applyAttributes };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MsgAttributes } from '../classes/MsgInterface/MsgInterface.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges {@link DEFAULT_ATTRIBUTES} with optional extras and caller attributes.
|
|
5
|
+
*
|
|
6
|
+
* An empty-string `dir` is treated as unset and becomes `'auto'`. This helper
|
|
7
|
+
* is module-internal (not re-exported from the public API).
|
|
8
|
+
*/
|
|
9
|
+
declare function applyAttributes(attributes?: MsgAttributes, extras?: MsgAttributes): MsgAttributes;
|
|
10
|
+
|
|
11
|
+
export { applyAttributes };
|