@worldware/msg 0.9.0 → 0.10.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
@@ -267,6 +267,7 @@ const data = resource.getData();
267
267
 
268
268
  **Methods:**
269
269
  - `add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): MsgResource` - Add a message
270
+ - `addNote(type: NoteTypes, content: string): MsgResource` - Add a note (returns `this` for chaining)
270
271
  - `translate(data: MsgResourceData): MsgResource` - Create a translated version
271
272
  - `getTranslation(lang: string): Promise<MsgResource>` - Load and apply translations. When `lang` matches the project's `pseudoLocale`, returns a resource with pseudolocalized message values instead of loading from the loader.
272
273
  - `getProject(): MsgProject` - Returns the project instance associated with the resource
@@ -286,7 +287,7 @@ const data = resource.getData();
286
287
  **Methods:**
287
288
  - `format(data: Record<string, any>, options?: MessageFormatOptions): string` - Format the message according to its resolved `format`: `MF2` uses MessageFormat 2, `MF1` compiles via `@messageformat/icu-messageformat-1`, and `NONE` returns the raw value
288
289
  - `formatToParts(data: Record<string, any>, options?: MessageFormatOptions): MessagePart[]` - Format to parts (for `NONE`, a single `{ type: 'text', value }` part)
289
- - `addNote(note: MsgNote): void` - Add a note
290
+ - `addNote(type: NoteTypes, content: string): MsgMessage` - Add a note (returns `this` for chaining)
290
291
  - `getData(stripNotes?: boolean): MsgMessageData` - Get message data
291
292
  - `toJSON(stripNotes?: boolean): string` - Serialize to JSON
292
293
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MsgMessage
3
- } from "./chunk-F3VAAZJZ.mjs";
3
+ } from "./chunk-OKEV7FY7.mjs";
4
4
  import {
5
5
  DEFAULT_ATTRIBUTES,
6
6
  MSG_DEFAULT_FORMAT
@@ -42,7 +42,7 @@ var MsgResource = class _MsgResource extends Map {
42
42
  this._attributes = { ...DEFAULT_ATTRIBUTES, format: project.format, ...attributes };
43
43
  this._project = project;
44
44
  if (notes) {
45
- notes.forEach((note) => this.addNote(note));
45
+ notes.forEach((note) => this.setNote(note));
46
46
  }
47
47
  }
48
48
  /**
@@ -94,9 +94,20 @@ var MsgResource = class _MsgResource extends Map {
94
94
  }
95
95
  /**
96
96
  * Appends a note to this resource.
97
+ *
98
+ * @returns This resource, for chaining.
99
+ */
100
+ addNote(type, content) {
101
+ return this.setNote({ type, content });
102
+ }
103
+ /**
104
+ * Appends a full note object to this resource.
105
+ *
106
+ * @returns This resource, for chaining.
97
107
  */
98
- addNote(note) {
108
+ setNote(note) {
99
109
  this.notes.push(note);
110
+ return this;
100
111
  }
101
112
  /** Title that identifies this resource within a project. */
102
113
  get title() {
@@ -161,7 +172,7 @@ var MsgResource = class _MsgResource extends Map {
161
172
  });
162
173
  const notes = this.get(key)?.notes || [];
163
174
  notes.forEach((note) => {
164
- msg.addNote(note);
175
+ msg.addNote(note.type, note.content);
165
176
  });
166
177
  translated.set(key, msg);
167
178
  });
File without changes
@@ -20,7 +20,7 @@ var MsgMessage = class _MsgMessage {
20
20
  this._value = value;
21
21
  this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
22
22
  if (notes) {
23
- notes.forEach((note) => this.addNote(note));
23
+ notes.forEach((note) => this.setNote(note));
24
24
  }
25
25
  }
26
26
  /**
@@ -49,9 +49,20 @@ var MsgMessage = class _MsgMessage {
49
49
  }
50
50
  /**
51
51
  * Appends a note to this message.
52
+ *
53
+ * @returns This message, for chaining.
54
+ */
55
+ addNote(type, content) {
56
+ return this.setNote({ type, content });
57
+ }
58
+ /**
59
+ * Appends a full note object to this message.
60
+ *
61
+ * @returns This message, for chaining.
52
62
  */
53
- addNote(note) {
63
+ setNote(note) {
54
64
  this.notes.push(note);
65
+ return this;
55
66
  }
56
67
  /**
57
68
  * The message's resolved format, defaulting to MF2 when not set or inherited.
@@ -49,7 +49,7 @@ var MsgMessage = class _MsgMessage {
49
49
  this._value = value;
50
50
  this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
51
51
  if (notes) {
52
- notes.forEach((note) => this.addNote(note));
52
+ notes.forEach((note) => this.setNote(note));
53
53
  }
54
54
  }
55
55
  /**
@@ -78,9 +78,20 @@ var MsgMessage = class _MsgMessage {
78
78
  }
79
79
  /**
80
80
  * Appends a note to this message.
81
+ *
82
+ * @returns This message, for chaining.
83
+ */
84
+ addNote(type, content) {
85
+ return this.setNote({ type, content });
86
+ }
87
+ /**
88
+ * Appends a full note object to this message.
89
+ *
90
+ * @returns This message, for chaining.
81
91
  */
82
- addNote(note) {
92
+ setNote(note) {
83
93
  this.notes.push(note);
94
+ return this;
84
95
  }
85
96
  /**
86
97
  * The message's resolved format, defaulting to MF2 when not set or inherited.
@@ -1,6 +1,6 @@
1
1
  import * as messageformat from 'messageformat';
2
2
  import { MessageFormatOptions } from 'messageformat';
3
- import { MsgInterface, MsgAttributes, MsgNote } from '../MsgInterface/MsgInterface.cjs';
3
+ import { MsgInterface, MsgAttributes, MsgNote, NoteTypes } from '../MsgInterface/MsgInterface.cjs';
4
4
 
5
5
  /**
6
6
  * Plain data used to create a {@link MsgMessage}.
@@ -44,8 +44,16 @@ declare class MsgMessage implements MsgInterface {
44
44
  get notes(): MsgNote[];
45
45
  /**
46
46
  * Appends a note to this message.
47
+ *
48
+ * @returns This message, for chaining.
49
+ */
50
+ addNote(type: NoteTypes, content: string): this;
51
+ /**
52
+ * Appends a full note object to this message.
53
+ *
54
+ * @returns This message, for chaining.
47
55
  */
48
- addNote(note: MsgNote): void;
56
+ private setNote;
49
57
  /**
50
58
  * The message's resolved format, defaulting to MF2 when not set or inherited.
51
59
  */
@@ -1,6 +1,6 @@
1
1
  import * as messageformat from 'messageformat';
2
2
  import { MessageFormatOptions } from 'messageformat';
3
- import { MsgInterface, MsgAttributes, MsgNote } from '../MsgInterface/MsgInterface.js';
3
+ import { MsgInterface, MsgAttributes, MsgNote, NoteTypes } from '../MsgInterface/MsgInterface.js';
4
4
 
5
5
  /**
6
6
  * Plain data used to create a {@link MsgMessage}.
@@ -44,8 +44,16 @@ declare class MsgMessage implements MsgInterface {
44
44
  get notes(): MsgNote[];
45
45
  /**
46
46
  * Appends a note to this message.
47
+ *
48
+ * @returns This message, for chaining.
49
+ */
50
+ addNote(type: NoteTypes, content: string): this;
51
+ /**
52
+ * Appends a full note object to this message.
53
+ *
54
+ * @returns This message, for chaining.
47
55
  */
48
- addNote(note: MsgNote): void;
56
+ private setNote;
49
57
  /**
50
58
  * The message's resolved format, defaulting to MF2 when not set or inherited.
51
59
  */
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MsgMessage
3
- } from "../../chunk-F3VAAZJZ.mjs";
3
+ } from "../../chunk-OKEV7FY7.mjs";
4
4
  import "../../chunk-XQVALCKX.mjs";
5
5
  export {
6
6
  MsgMessage
@@ -1,4 +1,4 @@
1
- export { M as MsgLocalesSettings, a as MsgProject, b as MsgProjectData, c as MsgProjectSettings, d as MsgTargetLocalesSettings, e as MsgTranslationLoader } from '../MsgResource/MsgResource.cjs';
1
+ export { MsgLocalesSettings, MsgProject, MsgProjectData, MsgProjectSettings, MsgTargetLocalesSettings, MsgTranslationLoader } from '../index.cjs';
2
2
  import '../MsgInterface/MsgInterface.cjs';
3
3
  import '../MsgMessage/MsgMessage.cjs';
4
4
  import 'messageformat';
@@ -1,4 +1,4 @@
1
- export { M as MsgLocalesSettings, a as MsgProject, b as MsgProjectData, c as MsgProjectSettings, d as MsgTargetLocalesSettings, e as MsgTranslationLoader } from '../MsgResource/MsgResource.js';
1
+ export { MsgLocalesSettings, MsgProject, MsgProjectData, MsgProjectSettings, MsgTargetLocalesSettings, MsgTranslationLoader } from '../index.js';
2
2
  import '../MsgInterface/MsgInterface.js';
3
3
  import '../MsgMessage/MsgMessage.js';
4
4
  import 'messageformat';
@@ -53,7 +53,7 @@ var MsgMessage = class _MsgMessage {
53
53
  this._value = value;
54
54
  this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
55
55
  if (notes) {
56
- notes.forEach((note) => this.addNote(note));
56
+ notes.forEach((note) => this.setNote(note));
57
57
  }
58
58
  }
59
59
  /**
@@ -82,9 +82,20 @@ var MsgMessage = class _MsgMessage {
82
82
  }
83
83
  /**
84
84
  * Appends a note to this message.
85
+ *
86
+ * @returns This message, for chaining.
85
87
  */
86
- addNote(note) {
88
+ addNote(type, content) {
89
+ return this.setNote({ type, content });
90
+ }
91
+ /**
92
+ * Appends a full note object to this message.
93
+ *
94
+ * @returns This message, for chaining.
95
+ */
96
+ setNote(note) {
87
97
  this.notes.push(note);
98
+ return this;
88
99
  }
89
100
  /**
90
101
  * The message's resolved format, defaulting to MF2 when not set or inherited.
@@ -186,7 +197,7 @@ var MsgResource = class _MsgResource extends Map {
186
197
  this._attributes = { ...DEFAULT_ATTRIBUTES, format: project.format, ...attributes };
187
198
  this._project = project;
188
199
  if (notes) {
189
- notes.forEach((note) => this.addNote(note));
200
+ notes.forEach((note) => this.setNote(note));
190
201
  }
191
202
  }
192
203
  /**
@@ -238,9 +249,20 @@ var MsgResource = class _MsgResource extends Map {
238
249
  }
239
250
  /**
240
251
  * Appends a note to this resource.
252
+ *
253
+ * @returns This resource, for chaining.
241
254
  */
242
- addNote(note) {
255
+ addNote(type, content) {
256
+ return this.setNote({ type, content });
257
+ }
258
+ /**
259
+ * Appends a full note object to this resource.
260
+ *
261
+ * @returns This resource, for chaining.
262
+ */
263
+ setNote(note) {
243
264
  this.notes.push(note);
265
+ return this;
244
266
  }
245
267
  /** Title that identifies this resource within a project. */
246
268
  get title() {
@@ -305,7 +327,7 @@ var MsgResource = class _MsgResource extends Map {
305
327
  });
306
328
  const notes = this.get(key)?.notes || [];
307
329
  notes.forEach((note) => {
308
- msg.addNote(note);
330
+ msg.addNote(note.type, note.content);
309
331
  });
310
332
  translated.set(key, msg);
311
333
  });
@@ -1,201 +1,4 @@
1
- import { MsgAttributes, MsgNote, MsgInterface, MsgFormat } from '../MsgInterface/MsgInterface.cjs';
2
- import { MsgMessageData, MsgMessage } from '../MsgMessage/MsgMessage.cjs';
1
+ import '../MsgMessage/MsgMessage.cjs';
2
+ import '../MsgInterface/MsgInterface.cjs';
3
+ export { MsgResource, MsgResourceData } from '../index.cjs';
3
4
  import 'messageformat';
4
-
5
- /**
6
- * Plain data used to create or describe a {@link MsgResource}.
7
- */
8
- type MsgResourceData = {
9
- /** Title that identifies this resource within a project. */
10
- title: string;
11
- /** Locale and formatting metadata for the resource. */
12
- attributes: MsgAttributes;
13
- /** Optional notes for translators and tooling. */
14
- notes?: MsgNote[];
15
- /** Optional list of messages in this resource. */
16
- messages?: MsgMessageData[];
17
- };
18
- /**
19
- * A named collection of messages belonging to a {@link MsgProject}.
20
- *
21
- * Resources inherit format defaults from their project, support translation
22
- * loading (including pseudo-localization), and can serialize to plain data.
23
- */
24
- declare class MsgResource extends Map<string, MsgMessage> implements MsgInterface {
25
- private _attributes;
26
- private _notes;
27
- private _title;
28
- private _project;
29
- /**
30
- * Builds a resource from {@link MsgResourceData} and an owning project.
31
- *
32
- * When `messages` is provided, each entry is added to the resource.
33
- * When omitted, the resource starts empty.
34
- */
35
- static create(data: MsgResourceData, project: MsgProject): MsgResource;
36
- /**
37
- * Creates a resource bound to a project. Prefer {@link MsgResource.create}.
38
- */
39
- private constructor();
40
- /**
41
- * Returns true when the message's attributes match this resource's attributes.
42
- */
43
- private hasMatchingAttributes;
44
- /**
45
- * Resolves a format from attributes, falling back to the library default.
46
- */
47
- private resolveFormat;
48
- /**
49
- * Pseudo-localizes an MF2 message by localizing only literal text parts.
50
- */
51
- private pseudoLocalizeMF2;
52
- /** Locale and formatting metadata for this resource. */
53
- get attributes(): MsgAttributes;
54
- /** Replaces the resource's locale and formatting metadata. */
55
- set attributes(attributes: MsgAttributes);
56
- /** Notes attached to this resource for translators and tooling. */
57
- get notes(): MsgNote[];
58
- /** Replaces the notes attached to this resource. */
59
- set notes(notes: MsgNote[]);
60
- /**
61
- * Appends a note to this resource.
62
- */
63
- addNote(note: MsgNote): void;
64
- /** Title that identifies this resource within a project. */
65
- get title(): string;
66
- /** Sets the title that identifies this resource within a project. */
67
- set title(title: string);
68
- /**
69
- * Returns the project this resource belongs to.
70
- */
71
- getProject(): MsgProject;
72
- /**
73
- * Adds a message to this resource, merging resource attributes with any overrides.
74
- *
75
- * @returns This resource, for chaining.
76
- */
77
- add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
78
- /**
79
- * Builds a translated copy of this resource from translation data.
80
- *
81
- * Messages present in the translation replace the source; missing keys keep
82
- * the source message. Notes are carried over from the source.
83
- *
84
- * @throws {TypeError} When the translation title does not match this resource.
85
- */
86
- translate(data: MsgResourceData): MsgResource;
87
- /**
88
- * Merge a `format` into an attribute set unless one is already present,
89
- * so translations inherit the source's format without overriding an
90
- * explicitly translated one. Returns the input unchanged when there is
91
- * no format to preserve.
92
- */
93
- private preserveFormat;
94
- /**
95
- * Loads and applies translations for a locale via the project loader.
96
- *
97
- * When `lang` is the project's pseudo-locale, returns a pseudo-localized
98
- * copy without calling the loader.
99
- *
100
- * @throws {Error} When the locale is unsupported or its language chain is empty.
101
- */
102
- getTranslation(lang?: string): Promise<MsgResource>;
103
- /**
104
- * Returns a plain data object for this resource and its messages.
105
- *
106
- * Attributes that match the resource or project defaults are omitted where
107
- * possible to keep the output compact.
108
- *
109
- * @param stripNotes - When true, notes are omitted from the result.
110
- */
111
- getData(stripNotes?: boolean): MsgResourceData;
112
- /**
113
- * Serializes this resource to a formatted JSON string.
114
- *
115
- * @param stripNotes - When true, notes are omitted from the serialized data.
116
- */
117
- toJSON(stripNotes?: boolean): string;
118
- }
119
-
120
- /**
121
- * Project-level settings such as name, version, and default message format.
122
- */
123
- type MsgProjectSettings = {
124
- /** Display name of the localization project. */
125
- name: string;
126
- /** Optional project version number. */
127
- version?: number;
128
- /** Default message format inherited by resources and messages. */
129
- format?: MsgFormat;
130
- };
131
- /**
132
- * Map of a requested locale to the chain of locales used to load translations.
133
- */
134
- type MsgTargetLocalesSettings = {
135
- [key: string]: string[];
136
- };
137
- /**
138
- * Locale configuration for a project: source, pseudo, and target locales.
139
- */
140
- type MsgLocalesSettings = {
141
- /** Locale of the source (authoring) strings. */
142
- sourceLocale: string;
143
- /** Locale used for pseudo-localization during development. */
144
- pseudoLocale: string;
145
- /** Target locales and their fallback load chains. */
146
- targetLocales: MsgTargetLocalesSettings;
147
- };
148
- /**
149
- * Async function that loads translated resource data for a project, title, and language.
150
- */
151
- type MsgTranslationLoader = (project: string, title: string, lang: string) => Promise<MsgResourceData>;
152
- /**
153
- * Plain data used to create a {@link MsgProject}.
154
- */
155
- type MsgProjectData = {
156
- /** Project name, version, and default format. */
157
- project: MsgProjectSettings;
158
- /** Source, pseudo, and target locale settings. */
159
- locales: MsgLocalesSettings;
160
- /** Function used to load translations for a locale. */
161
- loader: MsgTranslationLoader;
162
- };
163
- /**
164
- * A localization project that holds settings, locales, and a translation loader.
165
- *
166
- * Resources are created against a project so they can inherit format defaults
167
- * and load translations through the project's loader.
168
- */
169
- declare class MsgProject {
170
- /** Project name, version, and default format. */
171
- _project: MsgProjectSettings;
172
- /** Source, pseudo, and target locale settings. */
173
- _locales: MsgLocalesSettings;
174
- /** Function used to load translations for a locale. */
175
- _loader: MsgTranslationLoader;
176
- /**
177
- * Builds a project from {@link MsgProjectData}.
178
- */
179
- static create(data: MsgProjectData): MsgProject;
180
- /**
181
- * Creates a project from its settings and loader. Prefer {@link MsgProject.create}.
182
- */
183
- private constructor();
184
- /** Project name, version, and default format. */
185
- get project(): MsgProjectSettings;
186
- /** Source, pseudo, and target locale settings. */
187
- get locales(): MsgLocalesSettings;
188
- /** Function used to load translations for a locale. */
189
- get loader(): MsgTranslationLoader;
190
- /**
191
- * The project-wide default message format. Resources (and, through them,
192
- * messages) inherit this value unless they specify their own.
193
- */
194
- get format(): MsgFormat;
195
- /**
196
- * Returns the translation load chain for a locale, or `undefined` if unsupported.
197
- */
198
- getTargetLocale(locale: string): string[] | undefined;
199
- }
200
-
201
- export { type MsgLocalesSettings as M, MsgResource, type MsgResourceData, MsgProject as a, type MsgProjectData as b, type MsgProjectSettings as c, type MsgTargetLocalesSettings as d, type MsgTranslationLoader as e };
@@ -1,201 +1,4 @@
1
- import { MsgAttributes, MsgNote, MsgInterface, MsgFormat } from '../MsgInterface/MsgInterface.js';
2
- import { MsgMessageData, MsgMessage } from '../MsgMessage/MsgMessage.js';
1
+ import '../MsgMessage/MsgMessage.js';
2
+ import '../MsgInterface/MsgInterface.js';
3
+ export { MsgResource, MsgResourceData } from '../index.js';
3
4
  import 'messageformat';
4
-
5
- /**
6
- * Plain data used to create or describe a {@link MsgResource}.
7
- */
8
- type MsgResourceData = {
9
- /** Title that identifies this resource within a project. */
10
- title: string;
11
- /** Locale and formatting metadata for the resource. */
12
- attributes: MsgAttributes;
13
- /** Optional notes for translators and tooling. */
14
- notes?: MsgNote[];
15
- /** Optional list of messages in this resource. */
16
- messages?: MsgMessageData[];
17
- };
18
- /**
19
- * A named collection of messages belonging to a {@link MsgProject}.
20
- *
21
- * Resources inherit format defaults from their project, support translation
22
- * loading (including pseudo-localization), and can serialize to plain data.
23
- */
24
- declare class MsgResource extends Map<string, MsgMessage> implements MsgInterface {
25
- private _attributes;
26
- private _notes;
27
- private _title;
28
- private _project;
29
- /**
30
- * Builds a resource from {@link MsgResourceData} and an owning project.
31
- *
32
- * When `messages` is provided, each entry is added to the resource.
33
- * When omitted, the resource starts empty.
34
- */
35
- static create(data: MsgResourceData, project: MsgProject): MsgResource;
36
- /**
37
- * Creates a resource bound to a project. Prefer {@link MsgResource.create}.
38
- */
39
- private constructor();
40
- /**
41
- * Returns true when the message's attributes match this resource's attributes.
42
- */
43
- private hasMatchingAttributes;
44
- /**
45
- * Resolves a format from attributes, falling back to the library default.
46
- */
47
- private resolveFormat;
48
- /**
49
- * Pseudo-localizes an MF2 message by localizing only literal text parts.
50
- */
51
- private pseudoLocalizeMF2;
52
- /** Locale and formatting metadata for this resource. */
53
- get attributes(): MsgAttributes;
54
- /** Replaces the resource's locale and formatting metadata. */
55
- set attributes(attributes: MsgAttributes);
56
- /** Notes attached to this resource for translators and tooling. */
57
- get notes(): MsgNote[];
58
- /** Replaces the notes attached to this resource. */
59
- set notes(notes: MsgNote[]);
60
- /**
61
- * Appends a note to this resource.
62
- */
63
- addNote(note: MsgNote): void;
64
- /** Title that identifies this resource within a project. */
65
- get title(): string;
66
- /** Sets the title that identifies this resource within a project. */
67
- set title(title: string);
68
- /**
69
- * Returns the project this resource belongs to.
70
- */
71
- getProject(): MsgProject;
72
- /**
73
- * Adds a message to this resource, merging resource attributes with any overrides.
74
- *
75
- * @returns This resource, for chaining.
76
- */
77
- add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
78
- /**
79
- * Builds a translated copy of this resource from translation data.
80
- *
81
- * Messages present in the translation replace the source; missing keys keep
82
- * the source message. Notes are carried over from the source.
83
- *
84
- * @throws {TypeError} When the translation title does not match this resource.
85
- */
86
- translate(data: MsgResourceData): MsgResource;
87
- /**
88
- * Merge a `format` into an attribute set unless one is already present,
89
- * so translations inherit the source's format without overriding an
90
- * explicitly translated one. Returns the input unchanged when there is
91
- * no format to preserve.
92
- */
93
- private preserveFormat;
94
- /**
95
- * Loads and applies translations for a locale via the project loader.
96
- *
97
- * When `lang` is the project's pseudo-locale, returns a pseudo-localized
98
- * copy without calling the loader.
99
- *
100
- * @throws {Error} When the locale is unsupported or its language chain is empty.
101
- */
102
- getTranslation(lang?: string): Promise<MsgResource>;
103
- /**
104
- * Returns a plain data object for this resource and its messages.
105
- *
106
- * Attributes that match the resource or project defaults are omitted where
107
- * possible to keep the output compact.
108
- *
109
- * @param stripNotes - When true, notes are omitted from the result.
110
- */
111
- getData(stripNotes?: boolean): MsgResourceData;
112
- /**
113
- * Serializes this resource to a formatted JSON string.
114
- *
115
- * @param stripNotes - When true, notes are omitted from the serialized data.
116
- */
117
- toJSON(stripNotes?: boolean): string;
118
- }
119
-
120
- /**
121
- * Project-level settings such as name, version, and default message format.
122
- */
123
- type MsgProjectSettings = {
124
- /** Display name of the localization project. */
125
- name: string;
126
- /** Optional project version number. */
127
- version?: number;
128
- /** Default message format inherited by resources and messages. */
129
- format?: MsgFormat;
130
- };
131
- /**
132
- * Map of a requested locale to the chain of locales used to load translations.
133
- */
134
- type MsgTargetLocalesSettings = {
135
- [key: string]: string[];
136
- };
137
- /**
138
- * Locale configuration for a project: source, pseudo, and target locales.
139
- */
140
- type MsgLocalesSettings = {
141
- /** Locale of the source (authoring) strings. */
142
- sourceLocale: string;
143
- /** Locale used for pseudo-localization during development. */
144
- pseudoLocale: string;
145
- /** Target locales and their fallback load chains. */
146
- targetLocales: MsgTargetLocalesSettings;
147
- };
148
- /**
149
- * Async function that loads translated resource data for a project, title, and language.
150
- */
151
- type MsgTranslationLoader = (project: string, title: string, lang: string) => Promise<MsgResourceData>;
152
- /**
153
- * Plain data used to create a {@link MsgProject}.
154
- */
155
- type MsgProjectData = {
156
- /** Project name, version, and default format. */
157
- project: MsgProjectSettings;
158
- /** Source, pseudo, and target locale settings. */
159
- locales: MsgLocalesSettings;
160
- /** Function used to load translations for a locale. */
161
- loader: MsgTranslationLoader;
162
- };
163
- /**
164
- * A localization project that holds settings, locales, and a translation loader.
165
- *
166
- * Resources are created against a project so they can inherit format defaults
167
- * and load translations through the project's loader.
168
- */
169
- declare class MsgProject {
170
- /** Project name, version, and default format. */
171
- _project: MsgProjectSettings;
172
- /** Source, pseudo, and target locale settings. */
173
- _locales: MsgLocalesSettings;
174
- /** Function used to load translations for a locale. */
175
- _loader: MsgTranslationLoader;
176
- /**
177
- * Builds a project from {@link MsgProjectData}.
178
- */
179
- static create(data: MsgProjectData): MsgProject;
180
- /**
181
- * Creates a project from its settings and loader. Prefer {@link MsgProject.create}.
182
- */
183
- private constructor();
184
- /** Project name, version, and default format. */
185
- get project(): MsgProjectSettings;
186
- /** Source, pseudo, and target locale settings. */
187
- get locales(): MsgLocalesSettings;
188
- /** Function used to load translations for a locale. */
189
- get loader(): MsgTranslationLoader;
190
- /**
191
- * The project-wide default message format. Resources (and, through them,
192
- * messages) inherit this value unless they specify their own.
193
- */
194
- get format(): MsgFormat;
195
- /**
196
- * Returns the translation load chain for a locale, or `undefined` if unsupported.
197
- */
198
- getTargetLocale(locale: string): string[] | undefined;
199
- }
200
-
201
- export { type MsgLocalesSettings as M, MsgResource, type MsgResourceData, MsgProject as a, type MsgProjectData as b, type MsgProjectSettings as c, type MsgTargetLocalesSettings as d, type MsgTranslationLoader as e };