@worldware/msg 0.5.5 → 0.6.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.
Files changed (49) hide show
  1. package/README.md +4 -7
  2. package/dist/chunk-4SWDABOO.mjs +135 -0
  3. package/dist/chunk-GHRFKA7N.mjs +72 -0
  4. package/dist/chunk-OMRO6GAZ.mjs +10 -0
  5. package/dist/chunk-XS43NAP2.mjs +42 -0
  6. package/dist/chunk-ZKG5QRBZ.mjs +0 -0
  7. package/dist/classes/MsgInterface/MsgInterface.cjs +34 -0
  8. package/dist/classes/MsgInterface/MsgInterface.d.cts +17 -0
  9. package/dist/classes/MsgInterface/MsgInterface.d.ts +6 -6
  10. package/dist/classes/MsgInterface/MsgInterface.mjs +6 -0
  11. package/dist/classes/MsgMessage/MsgMessage.cjs +96 -0
  12. package/dist/classes/MsgMessage/MsgMessage.d.cts +36 -0
  13. package/dist/classes/MsgMessage/MsgMessage.d.ts +9 -9
  14. package/dist/classes/MsgMessage/MsgMessage.mjs +6 -0
  15. package/dist/classes/MsgProject/MsgProject.cjs +66 -0
  16. package/dist/classes/MsgProject/MsgProject.d.cts +63 -0
  17. package/dist/classes/MsgProject/MsgProject.d.ts +37 -6
  18. package/dist/classes/MsgProject/MsgProject.mjs +6 -0
  19. package/dist/classes/MsgResource/MsgResource.cjs +230 -0
  20. package/dist/classes/MsgResource/MsgResource.d.cts +4 -0
  21. package/dist/classes/MsgResource/MsgResource.d.ts +4 -31
  22. package/dist/classes/MsgResource/MsgResource.mjs +8 -0
  23. package/dist/classes/index.cjs +273 -0
  24. package/dist/classes/index.d.cts +4 -0
  25. package/dist/classes/index.d.ts +4 -4
  26. package/dist/classes/index.mjs +16 -0
  27. package/dist/index.cjs +273 -0
  28. package/dist/index.d.cts +4 -0
  29. package/dist/index.d.ts +4 -2
  30. package/dist/index.mjs +16 -0
  31. package/package.json +3 -2
  32. package/dist/classes/MsgInterface/MsgInterface.d.ts.map +0 -1
  33. package/dist/classes/MsgInterface/MsgInterface.js +0 -6
  34. package/dist/classes/MsgInterface/MsgInterface.js.map +0 -1
  35. package/dist/classes/MsgMessage/MsgMessage.d.ts.map +0 -1
  36. package/dist/classes/MsgMessage/MsgMessage.js +0 -76
  37. package/dist/classes/MsgMessage/MsgMessage.js.map +0 -1
  38. package/dist/classes/MsgProject/MsgProject.d.ts.map +0 -1
  39. package/dist/classes/MsgProject/MsgProject.js +0 -35
  40. package/dist/classes/MsgProject/MsgProject.js.map +0 -1
  41. package/dist/classes/MsgResource/MsgResource.d.ts.map +0 -1
  42. package/dist/classes/MsgResource/MsgResource.js +0 -126
  43. package/dist/classes/MsgResource/MsgResource.js.map +0 -1
  44. package/dist/classes/index.d.ts.map +0 -1
  45. package/dist/classes/index.js +0 -4
  46. package/dist/classes/index.js.map +0 -1
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js +0 -2
  49. package/dist/index.js.map +0 -1
package/README.md CHANGED
@@ -145,9 +145,9 @@ resource.add('complex-message', 'This is a complex message', {
145
145
 
146
146
  // Access attributes
147
147
  const message = resource.get('complex-message');
148
- console.log(message?.lang); // 'en'
149
- console.log(message?.dir); // 'ltr'
150
- console.log(message?.dnt); // false
148
+ console.log(message?.attributes.lang); // 'en'
149
+ console.log(message?.attributes.dir); // 'ltr'
150
+ console.log(message?.attributes.dnt); // false
151
151
  ```
152
152
 
153
153
  ### Serialization
@@ -210,10 +210,7 @@ const data = resource.getData();
210
210
  **Properties:**
211
211
  - `key: string` - Message key
212
212
  - `value: string` - Message value
213
- - `attributes: MsgAttributes` - Message attributes
214
- - `lang: string` - Language code
215
- - `dir: string` - Text direction
216
- - `dnt: boolean` - Do-not-translate flag
213
+ - `attributes: MsgAttributes` - Message attributes (lang, dir, dnt)
217
214
  - `notes: MsgNote[]` - Message notes
218
215
 
219
216
  ## Development
@@ -0,0 +1,135 @@
1
+ import {
2
+ DEFAULT_ATTRIBUTES
3
+ } from "./chunk-OMRO6GAZ.mjs";
4
+ import {
5
+ MsgMessage
6
+ } from "./chunk-GHRFKA7N.mjs";
7
+
8
+ // src/classes/MsgResource/MsgResource.ts
9
+ var MsgResource = class _MsgResource extends Map {
10
+ _attributes = DEFAULT_ATTRIBUTES;
11
+ _notes = [];
12
+ _title;
13
+ _project;
14
+ static create(data, project) {
15
+ const { title, attributes, notes, messages } = data;
16
+ const res = new _MsgResource(title, attributes, project, notes);
17
+ if (messages) {
18
+ messages.forEach((messageData) => {
19
+ const { key, value, attributes: attributes2, notes: notes2 } = messageData;
20
+ res.add(key, value, attributes2, notes2);
21
+ });
22
+ } else {
23
+ res.clear();
24
+ }
25
+ return res;
26
+ }
27
+ constructor(title, attributes, project, notes) {
28
+ super();
29
+ this._title = title;
30
+ this._attributes = { ...this._attributes, ...attributes };
31
+ this._project = project;
32
+ if (notes) {
33
+ notes.forEach((note) => this.addNote(note));
34
+ }
35
+ }
36
+ get attributes() {
37
+ return this._attributes;
38
+ }
39
+ set attributes(attributes) {
40
+ this._attributes = attributes;
41
+ }
42
+ get notes() {
43
+ return this._notes;
44
+ }
45
+ set notes(notes) {
46
+ this._notes = notes;
47
+ }
48
+ addNote(note) {
49
+ this.notes.push(note);
50
+ }
51
+ get title() {
52
+ return this._title;
53
+ }
54
+ set title(title) {
55
+ this._title = title;
56
+ }
57
+ getProject() {
58
+ return this._project;
59
+ }
60
+ add(key, value, attributes, notes) {
61
+ const merged = { ...this.attributes, ...attributes };
62
+ const msg = MsgMessage.create({
63
+ key,
64
+ value,
65
+ attributes: merged,
66
+ notes
67
+ });
68
+ this.set(key, msg);
69
+ return this;
70
+ }
71
+ translate(data) {
72
+ const { title, attributes, messages } = data;
73
+ if (title !== this.title) {
74
+ throw new TypeError("Title of resource and translations do not match.");
75
+ }
76
+ const translated = _MsgResource.create({
77
+ title,
78
+ attributes,
79
+ notes: this.notes
80
+ // transfer the notes
81
+ }, this._project);
82
+ this.forEach((msg) => {
83
+ translated.set(msg.key, msg);
84
+ });
85
+ messages?.forEach((messageData) => {
86
+ const { key, value, attributes: attributes2 } = messageData;
87
+ const msg = MsgMessage.create({
88
+ key,
89
+ value,
90
+ attributes: attributes2
91
+ });
92
+ const notes = this.get(key)?.notes || [];
93
+ notes.forEach((note) => {
94
+ msg.addNote(note);
95
+ });
96
+ translated.set(key, msg);
97
+ });
98
+ return translated;
99
+ }
100
+ async getTranslation(lang) {
101
+ const project = this._project;
102
+ const languageChain = project.getTargetLocale(lang);
103
+ if (!languageChain) {
104
+ throw new Error("Unsupported locale for resource.");
105
+ }
106
+ if (languageChain.length == 0) {
107
+ throw new Error(`Empty language chain for locale: ${lang}`);
108
+ }
109
+ let translated = this;
110
+ for (let i = 0; i < languageChain.length; i++) {
111
+ const lang2 = languageChain[i];
112
+ if (lang2 && project._locales.targetLocales[lang2]) {
113
+ translated = await translated._project._loader(project.project.name, translated.title, lang2).then((data) => translated.translate(data));
114
+ }
115
+ }
116
+ return translated;
117
+ }
118
+ getData(stripNotes = false) {
119
+ const messages = [];
120
+ this.forEach((msg) => messages.push(msg.getData(stripNotes)));
121
+ return {
122
+ title: this.title,
123
+ attributes: this.attributes,
124
+ notes: !stripNotes && this.notes.length > 0 ? this.notes : void 0,
125
+ messages
126
+ };
127
+ }
128
+ toJSON(stripNotes = false) {
129
+ return JSON.stringify(this.getData(stripNotes), null, 2);
130
+ }
131
+ };
132
+
133
+ export {
134
+ MsgResource
135
+ };
@@ -0,0 +1,72 @@
1
+ // src/classes/MsgMessage/MsgMessage.ts
2
+ import { MessageFormat } from "messageformat";
3
+ var DEFAULT_ATTRIBUTES = {
4
+ lang: "",
5
+ dir: "",
6
+ dnt: false
7
+ };
8
+ var MsgMessage = class _MsgMessage {
9
+ _key;
10
+ _value;
11
+ _mf;
12
+ _attributes = DEFAULT_ATTRIBUTES;
13
+ _notes = [];
14
+ constructor(key, value, attributes, notes) {
15
+ this._key = key;
16
+ this._value = value;
17
+ this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
18
+ if (notes) {
19
+ notes.forEach((note) => this.addNote(note));
20
+ }
21
+ }
22
+ static create(data) {
23
+ const { key, value, attributes, notes } = data;
24
+ const message = new _MsgMessage(key, value, attributes, notes);
25
+ return message;
26
+ }
27
+ get key() {
28
+ return this._key;
29
+ }
30
+ get value() {
31
+ return this._value;
32
+ }
33
+ get attributes() {
34
+ return this._attributes;
35
+ }
36
+ get notes() {
37
+ return this._notes;
38
+ }
39
+ addNote(note) {
40
+ this.notes.push(note);
41
+ }
42
+ format(data, options) {
43
+ if (!this._mf) {
44
+ this._mf = new MessageFormat(this.attributes.lang, this.value, options);
45
+ }
46
+ return this._mf.format(data);
47
+ }
48
+ formatToParts(data, options) {
49
+ if (!this._mf) {
50
+ this._mf = new MessageFormat(this.attributes.lang, this.value, options);
51
+ }
52
+ return this._mf?.formatToParts(data);
53
+ }
54
+ getData(stripNotes = false) {
55
+ return {
56
+ key: this.key,
57
+ value: this.value,
58
+ attributes: this.attributes,
59
+ notes: !stripNotes && this.notes.length > 0 ? this.notes : void 0
60
+ };
61
+ }
62
+ toString() {
63
+ return this.value;
64
+ }
65
+ toJSON(stripNotes = false) {
66
+ return JSON.stringify(this.getData(stripNotes), null, 2);
67
+ }
68
+ };
69
+
70
+ export {
71
+ MsgMessage
72
+ };
@@ -0,0 +1,10 @@
1
+ // src/classes/MsgInterface/MsgInterface.ts
2
+ var DEFAULT_ATTRIBUTES = {
3
+ lang: "",
4
+ dir: "",
5
+ dnt: false
6
+ };
7
+
8
+ export {
9
+ DEFAULT_ATTRIBUTES
10
+ };
@@ -0,0 +1,42 @@
1
+ // src/classes/MsgProject/MsgProject.ts
2
+ var defaultProjectSettings = {
3
+ name: "messages",
4
+ version: 1
5
+ };
6
+ var defaultLocalesSettings = {
7
+ sourceLocale: "en",
8
+ pseudoLocale: "en-XA",
9
+ targetLocales: {
10
+ en: ["en"]
11
+ }
12
+ };
13
+ var MsgProject = class _MsgProject {
14
+ _project;
15
+ _locales;
16
+ _loader;
17
+ static create(data) {
18
+ const { project, locales, loader } = data;
19
+ return new _MsgProject(project, locales, loader);
20
+ }
21
+ constructor(projectSettings, localesSettings, loader) {
22
+ this._project = { ...defaultProjectSettings, ...projectSettings };
23
+ this._locales = { ...defaultLocalesSettings, ...localesSettings };
24
+ this._loader = loader;
25
+ }
26
+ get project() {
27
+ return this._project;
28
+ }
29
+ get locales() {
30
+ return this._locales;
31
+ }
32
+ get loader() {
33
+ return this._loader;
34
+ }
35
+ getTargetLocale(locale) {
36
+ return this._locales.targetLocales[locale];
37
+ }
38
+ };
39
+
40
+ export {
41
+ MsgProject
42
+ };
File without changes
@@ -0,0 +1,34 @@
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/classes/MsgInterface/MsgInterface.ts
21
+ var MsgInterface_exports = {};
22
+ __export(MsgInterface_exports, {
23
+ DEFAULT_ATTRIBUTES: () => DEFAULT_ATTRIBUTES
24
+ });
25
+ module.exports = __toCommonJS(MsgInterface_exports);
26
+ var DEFAULT_ATTRIBUTES = {
27
+ lang: "",
28
+ dir: "",
29
+ dnt: false
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ DEFAULT_ATTRIBUTES
34
+ });
@@ -0,0 +1,17 @@
1
+ type NoteTypes = 'DESCRIPTION' | 'AUTHORSHIP' | 'PARAMETERS' | 'CONTEXT' | 'COMMENT';
2
+ type MsgNote = {
3
+ type: NoteTypes;
4
+ content: string;
5
+ };
6
+ type MsgAttributes = {
7
+ lang?: string;
8
+ dir?: string;
9
+ dnt?: boolean;
10
+ };
11
+ declare const DEFAULT_ATTRIBUTES: MsgAttributes;
12
+ interface MsgInterface {
13
+ attributes: MsgAttributes;
14
+ notes: MsgNote[];
15
+ }
16
+
17
+ export { DEFAULT_ATTRIBUTES, type MsgAttributes, type MsgInterface, type MsgNote };
@@ -1,17 +1,17 @@
1
1
  type NoteTypes = 'DESCRIPTION' | 'AUTHORSHIP' | 'PARAMETERS' | 'CONTEXT' | 'COMMENT';
2
- export type MsgNote = {
2
+ type MsgNote = {
3
3
  type: NoteTypes;
4
4
  content: string;
5
5
  };
6
- export type MsgAttributes = {
6
+ type MsgAttributes = {
7
7
  lang?: string;
8
8
  dir?: string;
9
9
  dnt?: boolean;
10
10
  };
11
- export declare const DEFAULT_ATTRIBUTES: MsgAttributes;
12
- export interface MsgInterface {
11
+ declare const DEFAULT_ATTRIBUTES: MsgAttributes;
12
+ interface MsgInterface {
13
13
  attributes: MsgAttributes;
14
14
  notes: MsgNote[];
15
15
  }
16
- export {};
17
- //# sourceMappingURL=MsgInterface.d.ts.map
16
+
17
+ export { DEFAULT_ATTRIBUTES, type MsgAttributes, type MsgInterface, type MsgNote };
@@ -0,0 +1,6 @@
1
+ import {
2
+ DEFAULT_ATTRIBUTES
3
+ } from "../../chunk-OMRO6GAZ.mjs";
4
+ export {
5
+ DEFAULT_ATTRIBUTES
6
+ };
@@ -0,0 +1,96 @@
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/classes/MsgMessage/MsgMessage.ts
21
+ var MsgMessage_exports = {};
22
+ __export(MsgMessage_exports, {
23
+ MsgMessage: () => MsgMessage
24
+ });
25
+ module.exports = __toCommonJS(MsgMessage_exports);
26
+ var import_messageformat = require("messageformat");
27
+ var DEFAULT_ATTRIBUTES = {
28
+ lang: "",
29
+ dir: "",
30
+ dnt: false
31
+ };
32
+ var MsgMessage = class _MsgMessage {
33
+ _key;
34
+ _value;
35
+ _mf;
36
+ _attributes = DEFAULT_ATTRIBUTES;
37
+ _notes = [];
38
+ constructor(key, value, attributes, notes) {
39
+ this._key = key;
40
+ this._value = value;
41
+ this._attributes = attributes ? { ...this._attributes, ...attributes } : this._attributes;
42
+ if (notes) {
43
+ notes.forEach((note) => this.addNote(note));
44
+ }
45
+ }
46
+ static create(data) {
47
+ const { key, value, attributes, notes } = data;
48
+ const message = new _MsgMessage(key, value, attributes, notes);
49
+ return message;
50
+ }
51
+ get key() {
52
+ return this._key;
53
+ }
54
+ get value() {
55
+ return this._value;
56
+ }
57
+ get attributes() {
58
+ return this._attributes;
59
+ }
60
+ get notes() {
61
+ return this._notes;
62
+ }
63
+ addNote(note) {
64
+ this.notes.push(note);
65
+ }
66
+ format(data, options) {
67
+ if (!this._mf) {
68
+ this._mf = new import_messageformat.MessageFormat(this.attributes.lang, this.value, options);
69
+ }
70
+ return this._mf.format(data);
71
+ }
72
+ formatToParts(data, options) {
73
+ if (!this._mf) {
74
+ this._mf = new import_messageformat.MessageFormat(this.attributes.lang, this.value, options);
75
+ }
76
+ return this._mf?.formatToParts(data);
77
+ }
78
+ getData(stripNotes = false) {
79
+ return {
80
+ key: this.key,
81
+ value: this.value,
82
+ attributes: this.attributes,
83
+ notes: !stripNotes && this.notes.length > 0 ? this.notes : void 0
84
+ };
85
+ }
86
+ toString() {
87
+ return this.value;
88
+ }
89
+ toJSON(stripNotes = false) {
90
+ return JSON.stringify(this.getData(stripNotes), null, 2);
91
+ }
92
+ };
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ MsgMessage
96
+ });
@@ -0,0 +1,36 @@
1
+ import * as messageformat from 'messageformat';
2
+ import { MessageFormatOptions } from 'messageformat';
3
+ import { MsgAttributes, MsgNote, MsgInterface } from '../MsgInterface/MsgInterface.cjs';
4
+
5
+ type MsgMessageData = {
6
+ key: string;
7
+ value: string;
8
+ attributes?: MsgAttributes;
9
+ notes?: MsgNote[];
10
+ };
11
+ declare class MsgMessage implements MsgInterface {
12
+ private _key;
13
+ private _value;
14
+ private _mf?;
15
+ private _attributes;
16
+ private _notes;
17
+ private constructor();
18
+ static create(data: MsgMessageData): MsgMessage;
19
+ get key(): string;
20
+ get value(): string;
21
+ get attributes(): MsgAttributes;
22
+ get notes(): MsgNote[];
23
+ addNote(note: MsgNote): void;
24
+ format(data: Record<string, any>, options?: MessageFormatOptions): string;
25
+ formatToParts(data: Record<string, any>, options?: MessageFormatOptions): messageformat.MessagePart<never>[];
26
+ getData(stripNotes?: boolean): {
27
+ key: string;
28
+ value: string;
29
+ attributes: MsgAttributes;
30
+ notes: MsgNote[] | undefined;
31
+ };
32
+ toString(): string;
33
+ toJSON(stripNotes?: boolean): string;
34
+ }
35
+
36
+ export { MsgMessage, type MsgMessageData };
@@ -1,12 +1,14 @@
1
- import { type MessageFormatOptions } from "messageformat";
2
- import { MsgInterface, type MsgAttributes, type MsgNote } from "../MsgInterface/MsgInterface.js";
3
- export type MsgMessageData = {
1
+ import * as messageformat from 'messageformat';
2
+ import { MessageFormatOptions } from 'messageformat';
3
+ import { MsgAttributes, MsgNote, MsgInterface } from '../MsgInterface/MsgInterface.js';
4
+
5
+ type MsgMessageData = {
4
6
  key: string;
5
7
  value: string;
6
8
  attributes?: MsgAttributes;
7
9
  notes?: MsgNote[];
8
10
  };
9
- export declare class MsgMessage implements MsgInterface {
11
+ declare class MsgMessage implements MsgInterface {
10
12
  private _key;
11
13
  private _value;
12
14
  private _mf?;
@@ -17,13 +19,10 @@ export declare class MsgMessage implements MsgInterface {
17
19
  get key(): string;
18
20
  get value(): string;
19
21
  get attributes(): MsgAttributes;
20
- get lang(): string | undefined;
21
- get dir(): string | undefined;
22
- get dnt(): boolean | undefined;
23
22
  get notes(): MsgNote[];
24
23
  addNote(note: MsgNote): void;
25
24
  format(data: Record<string, any>, options?: MessageFormatOptions): string;
26
- formatToParts(data: Record<string, any>, options?: MessageFormatOptions): import("messageformat").MessagePart<never>[];
25
+ formatToParts(data: Record<string, any>, options?: MessageFormatOptions): messageformat.MessagePart<never>[];
27
26
  getData(stripNotes?: boolean): {
28
27
  key: string;
29
28
  value: string;
@@ -33,4 +32,5 @@ export declare class MsgMessage implements MsgInterface {
33
32
  toString(): string;
34
33
  toJSON(stripNotes?: boolean): string;
35
34
  }
36
- //# sourceMappingURL=MsgMessage.d.ts.map
35
+
36
+ export { MsgMessage, type MsgMessageData };
@@ -0,0 +1,6 @@
1
+ import {
2
+ MsgMessage
3
+ } from "../../chunk-GHRFKA7N.mjs";
4
+ export {
5
+ MsgMessage
6
+ };
@@ -0,0 +1,66 @@
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/classes/MsgProject/MsgProject.ts
21
+ var MsgProject_exports = {};
22
+ __export(MsgProject_exports, {
23
+ MsgProject: () => MsgProject
24
+ });
25
+ module.exports = __toCommonJS(MsgProject_exports);
26
+ var defaultProjectSettings = {
27
+ name: "messages",
28
+ version: 1
29
+ };
30
+ var defaultLocalesSettings = {
31
+ sourceLocale: "en",
32
+ pseudoLocale: "en-XA",
33
+ targetLocales: {
34
+ en: ["en"]
35
+ }
36
+ };
37
+ var MsgProject = class _MsgProject {
38
+ _project;
39
+ _locales;
40
+ _loader;
41
+ static create(data) {
42
+ const { project, locales, loader } = data;
43
+ return new _MsgProject(project, locales, loader);
44
+ }
45
+ constructor(projectSettings, localesSettings, loader) {
46
+ this._project = { ...defaultProjectSettings, ...projectSettings };
47
+ this._locales = { ...defaultLocalesSettings, ...localesSettings };
48
+ this._loader = loader;
49
+ }
50
+ get project() {
51
+ return this._project;
52
+ }
53
+ get locales() {
54
+ return this._locales;
55
+ }
56
+ get loader() {
57
+ return this._loader;
58
+ }
59
+ getTargetLocale(locale) {
60
+ return this._locales.targetLocales[locale];
61
+ }
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ MsgProject
66
+ });
@@ -0,0 +1,63 @@
1
+ import { MsgMessageData, MsgMessage } from '../MsgMessage/MsgMessage.cjs';
2
+ import { MsgAttributes, MsgNote, MsgInterface } from '../MsgInterface/MsgInterface.cjs';
3
+ import 'messageformat';
4
+
5
+ type MsgProjectSettings = {
6
+ name: string;
7
+ version?: number;
8
+ };
9
+ type MsgTargetLocalesSettings = {
10
+ [key: string]: string[];
11
+ };
12
+ type MsgLocalesSettings = {
13
+ sourceLocale: string;
14
+ pseudoLocale: string;
15
+ targetLocales: MsgTargetLocalesSettings;
16
+ };
17
+ type MsgTranslationLoader = (project: string, title: string, lang: string) => Promise<MsgResourceData>;
18
+ type MsgProjectData = {
19
+ project: MsgProjectSettings;
20
+ locales: MsgLocalesSettings;
21
+ loader: MsgTranslationLoader;
22
+ };
23
+ declare class MsgProject {
24
+ _project: MsgProjectSettings;
25
+ _locales: MsgLocalesSettings;
26
+ _loader: MsgTranslationLoader;
27
+ static create(data: MsgProjectData): MsgProject;
28
+ private constructor();
29
+ get project(): MsgProjectSettings;
30
+ get locales(): MsgLocalesSettings;
31
+ get loader(): MsgTranslationLoader;
32
+ getTargetLocale(locale: string): string[] | undefined;
33
+ }
34
+
35
+ type MsgResourceData = {
36
+ title: string;
37
+ attributes: MsgAttributes;
38
+ notes?: MsgNote[];
39
+ messages?: MsgMessageData[];
40
+ };
41
+ declare class MsgResource extends Map<string, MsgMessage> implements MsgInterface {
42
+ private _attributes;
43
+ private _notes;
44
+ private _title;
45
+ private _project;
46
+ static create(data: MsgResourceData, project: MsgProject): MsgResource;
47
+ private constructor();
48
+ get attributes(): MsgAttributes;
49
+ set attributes(attributes: MsgAttributes);
50
+ get notes(): MsgNote[];
51
+ set notes(notes: MsgNote[]);
52
+ addNote(note: MsgNote): void;
53
+ get title(): string;
54
+ set title(title: string);
55
+ getProject(): MsgProject;
56
+ add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
57
+ translate(data: MsgResourceData): MsgResource;
58
+ getTranslation(lang: string): Promise<MsgResource>;
59
+ getData(stripNotes?: boolean): MsgResourceData;
60
+ toJSON(stripNotes?: boolean): string;
61
+ }
62
+
63
+ export { type MsgResourceData as M, MsgProject, type MsgProjectData, type MsgTranslationLoader, MsgResource as a };