@worldware/msg 0.8.0 → 0.8.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/dist/chunk-HCR2UNSE.mjs +85 -0
- package/dist/chunk-NWJ7MVVV.mjs +54 -0
- package/dist/chunk-ORHP7HGX.mjs +0 -0
- package/dist/chunk-X6CRKSNU.mjs +207 -0
- package/dist/chunk-XQVALCKX.mjs +12 -0
- package/dist/classes/MsgInterface/MsgInterface.cjs +37 -0
- package/dist/classes/MsgInterface/MsgInterface.d.cts +31 -0
- package/dist/classes/MsgInterface/MsgInterface.d.ts +31 -0
- package/dist/classes/MsgInterface/MsgInterface.mjs +8 -0
- package/dist/classes/MsgMessage/MsgMessage.cjs +114 -0
- package/dist/classes/MsgMessage/MsgMessage.d.cts +41 -0
- package/dist/classes/MsgMessage/MsgMessage.d.ts +41 -0
- package/dist/classes/MsgMessage/MsgMessage.mjs +7 -0
- package/dist/classes/MsgProject/MsgProject.cjs +79 -0
- package/dist/classes/MsgProject/MsgProject.d.cts +4 -0
- package/dist/classes/MsgProject/MsgProject.d.ts +4 -0
- package/dist/classes/MsgProject/MsgProject.mjs +7 -0
- package/dist/classes/MsgResource/MsgResource.cjs +312 -0
- package/dist/classes/MsgResource/MsgResource.d.cts +79 -0
- package/dist/classes/MsgResource/MsgResource.d.ts +79 -0
- package/dist/classes/MsgResource/MsgResource.mjs +8 -0
- package/dist/classes/index.cjs +365 -0
- package/dist/classes/index.d.cts +4 -0
- package/dist/classes/index.d.ts +4 -0
- package/dist/classes/index.mjs +21 -0
- package/dist/index.cjs +365 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +21 -0
- package/package.json +2 -1
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
|
|
27
|
+
// src/classes/MsgInterface/MsgInterface.ts
|
|
28
|
+
var MSG_DEFAULT_FORMAT = "MF2";
|
|
29
|
+
|
|
30
|
+
// src/classes/MsgProject/MsgProject.ts
|
|
31
|
+
var defaultProjectSettings = {
|
|
32
|
+
name: "messages",
|
|
33
|
+
version: 1,
|
|
34
|
+
format: MSG_DEFAULT_FORMAT
|
|
35
|
+
};
|
|
36
|
+
var defaultLocalesSettings = {
|
|
37
|
+
sourceLocale: "en",
|
|
38
|
+
pseudoLocale: "en-XA",
|
|
39
|
+
targetLocales: {
|
|
40
|
+
en: ["en"]
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var MsgProject = class _MsgProject {
|
|
44
|
+
_project;
|
|
45
|
+
_locales;
|
|
46
|
+
_loader;
|
|
47
|
+
static create(data) {
|
|
48
|
+
const { project, locales, loader } = data;
|
|
49
|
+
return new _MsgProject(project, locales, loader);
|
|
50
|
+
}
|
|
51
|
+
constructor(projectSettings, localesSettings, loader) {
|
|
52
|
+
this._project = { ...defaultProjectSettings, ...projectSettings };
|
|
53
|
+
this._locales = { ...defaultLocalesSettings, ...localesSettings };
|
|
54
|
+
this._loader = loader;
|
|
55
|
+
}
|
|
56
|
+
get project() {
|
|
57
|
+
return this._project;
|
|
58
|
+
}
|
|
59
|
+
get locales() {
|
|
60
|
+
return this._locales;
|
|
61
|
+
}
|
|
62
|
+
get loader() {
|
|
63
|
+
return this._loader;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The project-wide default message format. Resources (and, through them,
|
|
67
|
+
* messages) inherit this value unless they specify their own.
|
|
68
|
+
*/
|
|
69
|
+
get format() {
|
|
70
|
+
return this._project.format ?? MSG_DEFAULT_FORMAT;
|
|
71
|
+
}
|
|
72
|
+
getTargetLocale(locale) {
|
|
73
|
+
return this._locales.targetLocales[locale];
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
MsgProject
|
|
79
|
+
});
|
|
@@ -0,0 +1,312 @@
|
|
|
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/MsgResource/MsgResource.ts
|
|
21
|
+
var MsgResource_exports = {};
|
|
22
|
+
__export(MsgResource_exports, {
|
|
23
|
+
MsgResource: () => MsgResource
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(MsgResource_exports);
|
|
26
|
+
var import_messageformat2 = require("messageformat");
|
|
27
|
+
var import_pseudo_localization = require("pseudo-localization");
|
|
28
|
+
|
|
29
|
+
// src/classes/MsgMessage/MsgMessage.ts
|
|
30
|
+
var import_messageformat = require("messageformat");
|
|
31
|
+
var import_icu_messageformat_1 = require("@messageformat/icu-messageformat-1");
|
|
32
|
+
|
|
33
|
+
// src/classes/MsgInterface/MsgInterface.ts
|
|
34
|
+
var MSG_DEFAULT_FORMAT = "MF2";
|
|
35
|
+
var DEFAULT_ATTRIBUTES = {
|
|
36
|
+
lang: "und",
|
|
37
|
+
dir: "auto",
|
|
38
|
+
dnt: false
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/classes/MsgMessage/MsgMessage.ts
|
|
42
|
+
var MsgMessage = class _MsgMessage {
|
|
43
|
+
_key;
|
|
44
|
+
_value;
|
|
45
|
+
_mf;
|
|
46
|
+
_attributes;
|
|
47
|
+
_notes = [];
|
|
48
|
+
constructor(key, value, attributes, notes) {
|
|
49
|
+
this._key = key;
|
|
50
|
+
this._value = value;
|
|
51
|
+
this._attributes = attributes ? { ...DEFAULT_ATTRIBUTES, ...attributes } : {};
|
|
52
|
+
if (notes) {
|
|
53
|
+
notes.forEach((note) => this.addNote(note));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
static create(data) {
|
|
57
|
+
const { key, value, attributes, notes } = data;
|
|
58
|
+
const message = new _MsgMessage(key, value, attributes, notes);
|
|
59
|
+
return message;
|
|
60
|
+
}
|
|
61
|
+
get key() {
|
|
62
|
+
return this._key;
|
|
63
|
+
}
|
|
64
|
+
get value() {
|
|
65
|
+
return this._value;
|
|
66
|
+
}
|
|
67
|
+
get attributes() {
|
|
68
|
+
return this._attributes;
|
|
69
|
+
}
|
|
70
|
+
get notes() {
|
|
71
|
+
return this._notes;
|
|
72
|
+
}
|
|
73
|
+
addNote(note) {
|
|
74
|
+
this.notes.push(note);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The message's resolved format, defaulting to MF2 when not set or inherited.
|
|
78
|
+
*/
|
|
79
|
+
resolveFormat() {
|
|
80
|
+
return this.attributes.format ?? MSG_DEFAULT_FORMAT;
|
|
81
|
+
}
|
|
82
|
+
getFormatter(options) {
|
|
83
|
+
if (!this._mf) {
|
|
84
|
+
this._mf = this.resolveFormat() === "MF1" ? (0, import_icu_messageformat_1.mf1ToMessage)(this.attributes.lang, this.value, options) : new import_messageformat.MessageFormat(this.attributes.lang, this.value, options);
|
|
85
|
+
}
|
|
86
|
+
return this._mf;
|
|
87
|
+
}
|
|
88
|
+
format(data, options) {
|
|
89
|
+
if (this.resolveFormat() === "NONE") {
|
|
90
|
+
return this.value;
|
|
91
|
+
}
|
|
92
|
+
return this.getFormatter(options).format(data);
|
|
93
|
+
}
|
|
94
|
+
formatToParts(data, options) {
|
|
95
|
+
if (this.resolveFormat() === "NONE") {
|
|
96
|
+
return [{ type: "text", value: this.value }];
|
|
97
|
+
}
|
|
98
|
+
return this.getFormatter(options).formatToParts(data);
|
|
99
|
+
}
|
|
100
|
+
getData(stripNotes = false) {
|
|
101
|
+
return {
|
|
102
|
+
key: this.key,
|
|
103
|
+
value: this.value,
|
|
104
|
+
attributes: this.attributes,
|
|
105
|
+
notes: !stripNotes && this.notes.length > 0 ? this.notes : void 0
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
toString() {
|
|
109
|
+
return this.value;
|
|
110
|
+
}
|
|
111
|
+
toJSON(stripNotes = false) {
|
|
112
|
+
return JSON.stringify(this.getData(stripNotes), null, 2);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/classes/MsgResource/MsgResource.ts
|
|
117
|
+
var MsgResource = class _MsgResource extends Map {
|
|
118
|
+
_attributes = {};
|
|
119
|
+
_notes = [];
|
|
120
|
+
_title;
|
|
121
|
+
_project;
|
|
122
|
+
static create(data, project) {
|
|
123
|
+
const { title, attributes, notes, messages } = data;
|
|
124
|
+
const res = new _MsgResource(title, attributes, project, notes);
|
|
125
|
+
if (messages) {
|
|
126
|
+
messages.forEach((messageData) => {
|
|
127
|
+
const { key, value, attributes: attributes2, notes: notes2 } = messageData;
|
|
128
|
+
res.add(key, value, attributes2, notes2);
|
|
129
|
+
});
|
|
130
|
+
} else {
|
|
131
|
+
res.clear();
|
|
132
|
+
}
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
135
|
+
constructor(title, attributes, project, notes) {
|
|
136
|
+
super();
|
|
137
|
+
this._title = title;
|
|
138
|
+
this._attributes = { ...DEFAULT_ATTRIBUTES, format: project.format, ...attributes };
|
|
139
|
+
this._project = project;
|
|
140
|
+
if (notes) {
|
|
141
|
+
notes.forEach((note) => this.addNote(note));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
hasMatchingAttributes(message) {
|
|
145
|
+
const res = this.attributes;
|
|
146
|
+
const msg = message.attributes;
|
|
147
|
+
return res.lang === msg.lang && res.dir === msg.dir && res.dnt === msg.dnt && this.resolveFormat(res) === this.resolveFormat(msg);
|
|
148
|
+
}
|
|
149
|
+
resolveFormat(attributes) {
|
|
150
|
+
return attributes.format ?? MSG_DEFAULT_FORMAT;
|
|
151
|
+
}
|
|
152
|
+
pseudoLocalizeMF2(source, options) {
|
|
153
|
+
const msg = (0, import_messageformat2.parseMessage)(source);
|
|
154
|
+
(0, import_messageformat2.visit)(msg, {
|
|
155
|
+
pattern: (pattern) => {
|
|
156
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
157
|
+
const part = pattern[i];
|
|
158
|
+
if (typeof part === "string") {
|
|
159
|
+
pattern[i] = (0, import_pseudo_localization.localize)(part, options);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return (0, import_messageformat2.stringifyMessage)(msg);
|
|
165
|
+
}
|
|
166
|
+
get attributes() {
|
|
167
|
+
return this._attributes;
|
|
168
|
+
}
|
|
169
|
+
set attributes(attributes) {
|
|
170
|
+
this._attributes = attributes;
|
|
171
|
+
}
|
|
172
|
+
get notes() {
|
|
173
|
+
return this._notes;
|
|
174
|
+
}
|
|
175
|
+
set notes(notes) {
|
|
176
|
+
this._notes = notes;
|
|
177
|
+
}
|
|
178
|
+
addNote(note) {
|
|
179
|
+
this.notes.push(note);
|
|
180
|
+
}
|
|
181
|
+
get title() {
|
|
182
|
+
return this._title;
|
|
183
|
+
}
|
|
184
|
+
set title(title) {
|
|
185
|
+
this._title = title;
|
|
186
|
+
}
|
|
187
|
+
getProject() {
|
|
188
|
+
return this._project;
|
|
189
|
+
}
|
|
190
|
+
add(key, value, attributes, notes) {
|
|
191
|
+
const merged = { ...this.attributes, ...attributes };
|
|
192
|
+
const msg = MsgMessage.create({
|
|
193
|
+
key,
|
|
194
|
+
value,
|
|
195
|
+
attributes: merged,
|
|
196
|
+
notes
|
|
197
|
+
});
|
|
198
|
+
this.set(key, msg);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
translate(data) {
|
|
202
|
+
const { title, attributes, messages } = data;
|
|
203
|
+
if (title !== this.title) {
|
|
204
|
+
throw new TypeError("Title of resource and translations do not match.");
|
|
205
|
+
}
|
|
206
|
+
const translated = _MsgResource.create({
|
|
207
|
+
title,
|
|
208
|
+
// preserve the source resource's format unless the translation overrides it
|
|
209
|
+
attributes: this.preserveFormat(attributes, this.attributes.format),
|
|
210
|
+
notes: this.notes
|
|
211
|
+
// transfer the notes
|
|
212
|
+
}, this._project);
|
|
213
|
+
this.forEach((msg) => {
|
|
214
|
+
translated.set(msg.key, msg);
|
|
215
|
+
});
|
|
216
|
+
messages?.forEach((messageData) => {
|
|
217
|
+
const { key, value, attributes: attributes2 } = messageData;
|
|
218
|
+
const msg = MsgMessage.create({
|
|
219
|
+
key,
|
|
220
|
+
value,
|
|
221
|
+
// preserve the source message's format unless the translation overrides it
|
|
222
|
+
attributes: this.preserveFormat(attributes2, this.get(key)?.attributes.format)
|
|
223
|
+
});
|
|
224
|
+
const notes = this.get(key)?.notes || [];
|
|
225
|
+
notes.forEach((note) => {
|
|
226
|
+
msg.addNote(note);
|
|
227
|
+
});
|
|
228
|
+
translated.set(key, msg);
|
|
229
|
+
});
|
|
230
|
+
return translated;
|
|
231
|
+
}
|
|
232
|
+
preserveFormat(attributes, format) {
|
|
233
|
+
if (format === void 0 || attributes?.format !== void 0) {
|
|
234
|
+
return attributes;
|
|
235
|
+
}
|
|
236
|
+
return { ...attributes, format };
|
|
237
|
+
}
|
|
238
|
+
async getTranslation(lang) {
|
|
239
|
+
const project = this._project;
|
|
240
|
+
const pseudoLocale = project.locales.pseudoLocale;
|
|
241
|
+
if (lang === pseudoLocale) {
|
|
242
|
+
const pseudolocalizedData = {
|
|
243
|
+
title: this.title,
|
|
244
|
+
attributes: { ...this.attributes, lang: pseudoLocale },
|
|
245
|
+
notes: this.notes.length > 0 ? this.notes : void 0,
|
|
246
|
+
messages: []
|
|
247
|
+
};
|
|
248
|
+
this.forEach((msg) => {
|
|
249
|
+
pseudolocalizedData.messages.push({
|
|
250
|
+
key: msg.key,
|
|
251
|
+
value: this.pseudoLocalizeMF2(msg.value),
|
|
252
|
+
attributes: { ...this.attributes, lang: pseudoLocale }
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
return this.translate(pseudolocalizedData);
|
|
256
|
+
}
|
|
257
|
+
const languageChain = project.getTargetLocale(lang);
|
|
258
|
+
if (!languageChain) {
|
|
259
|
+
throw new Error("Unsupported locale for resource.");
|
|
260
|
+
}
|
|
261
|
+
if (languageChain.length == 0) {
|
|
262
|
+
throw new Error(`Empty language chain for locale: ${lang}`);
|
|
263
|
+
}
|
|
264
|
+
let translated = this;
|
|
265
|
+
for (let i = 0; i < languageChain.length; i++) {
|
|
266
|
+
const lang2 = languageChain[i];
|
|
267
|
+
if (lang2 && project._locales.targetLocales[lang2]) {
|
|
268
|
+
translated = await translated._project._loader(project.project.name, translated.title, lang2).then((data) => translated.translate(data));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return translated;
|
|
272
|
+
}
|
|
273
|
+
getData(stripNotes = false) {
|
|
274
|
+
const resourceFormat = this.resolveFormat(this.attributes);
|
|
275
|
+
const projectFormat = this._project.format;
|
|
276
|
+
const messages = [];
|
|
277
|
+
this.forEach((msg) => {
|
|
278
|
+
if (this.hasMatchingAttributes(msg)) {
|
|
279
|
+
const data = {
|
|
280
|
+
key: msg.key,
|
|
281
|
+
value: msg.value,
|
|
282
|
+
notes: !stripNotes && msg.notes.length > 0 ? msg.notes : void 0
|
|
283
|
+
};
|
|
284
|
+
messages.push(data);
|
|
285
|
+
} else {
|
|
286
|
+
const data = msg.getData(stripNotes);
|
|
287
|
+
if (data.attributes && this.resolveFormat(data.attributes) === resourceFormat) {
|
|
288
|
+
const { format, ...rest } = data.attributes;
|
|
289
|
+
data.attributes = rest;
|
|
290
|
+
}
|
|
291
|
+
messages.push(data);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
const attributes = { ...this.attributes };
|
|
295
|
+
if (this.resolveFormat(attributes) === projectFormat) {
|
|
296
|
+
delete attributes.format;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
title: this.title,
|
|
300
|
+
attributes,
|
|
301
|
+
notes: !stripNotes && this.notes.length > 0 ? this.notes : void 0,
|
|
302
|
+
messages
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
toJSON(stripNotes = false) {
|
|
306
|
+
return JSON.stringify(this.getData(stripNotes), null, 2);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
310
|
+
0 && (module.exports = {
|
|
311
|
+
MsgResource
|
|
312
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MsgAttributes, MsgNote, MsgInterface, MsgFormat } from '../MsgInterface/MsgInterface.cjs';
|
|
2
|
+
import { MsgMessageData, MsgMessage } from '../MsgMessage/MsgMessage.cjs';
|
|
3
|
+
import 'messageformat';
|
|
4
|
+
|
|
5
|
+
type MsgResourceData = {
|
|
6
|
+
title: string;
|
|
7
|
+
attributes: MsgAttributes;
|
|
8
|
+
notes?: MsgNote[];
|
|
9
|
+
messages?: MsgMessageData[];
|
|
10
|
+
};
|
|
11
|
+
declare class MsgResource extends Map<string, MsgMessage> implements MsgInterface {
|
|
12
|
+
private _attributes;
|
|
13
|
+
private _notes;
|
|
14
|
+
private _title;
|
|
15
|
+
private _project;
|
|
16
|
+
static create(data: MsgResourceData, project: MsgProject): MsgResource;
|
|
17
|
+
private constructor();
|
|
18
|
+
private hasMatchingAttributes;
|
|
19
|
+
private resolveFormat;
|
|
20
|
+
private pseudoLocalizeMF2;
|
|
21
|
+
get attributes(): MsgAttributes;
|
|
22
|
+
set attributes(attributes: MsgAttributes);
|
|
23
|
+
get notes(): MsgNote[];
|
|
24
|
+
set notes(notes: MsgNote[]);
|
|
25
|
+
addNote(note: MsgNote): void;
|
|
26
|
+
get title(): string;
|
|
27
|
+
set title(title: string);
|
|
28
|
+
getProject(): MsgProject;
|
|
29
|
+
add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
|
|
30
|
+
translate(data: MsgResourceData): MsgResource;
|
|
31
|
+
/**
|
|
32
|
+
* Merge a `format` into an attribute set unless one is already present,
|
|
33
|
+
* so translations inherit the source's format without overriding an
|
|
34
|
+
* explicitly translated one. Returns the input unchanged when there is
|
|
35
|
+
* no format to preserve.
|
|
36
|
+
*/
|
|
37
|
+
private preserveFormat;
|
|
38
|
+
getTranslation(lang: string): Promise<MsgResource>;
|
|
39
|
+
getData(stripNotes?: boolean): MsgResourceData;
|
|
40
|
+
toJSON(stripNotes?: boolean): string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type MsgProjectSettings = {
|
|
44
|
+
name: string;
|
|
45
|
+
version?: number;
|
|
46
|
+
format?: MsgFormat;
|
|
47
|
+
};
|
|
48
|
+
type MsgTargetLocalesSettings = {
|
|
49
|
+
[key: string]: string[];
|
|
50
|
+
};
|
|
51
|
+
type MsgLocalesSettings = {
|
|
52
|
+
sourceLocale: string;
|
|
53
|
+
pseudoLocale: string;
|
|
54
|
+
targetLocales: MsgTargetLocalesSettings;
|
|
55
|
+
};
|
|
56
|
+
type MsgTranslationLoader = (project: string, title: string, lang: string) => Promise<MsgResourceData>;
|
|
57
|
+
type MsgProjectData = {
|
|
58
|
+
project: MsgProjectSettings;
|
|
59
|
+
locales: MsgLocalesSettings;
|
|
60
|
+
loader: MsgTranslationLoader;
|
|
61
|
+
};
|
|
62
|
+
declare class MsgProject {
|
|
63
|
+
_project: MsgProjectSettings;
|
|
64
|
+
_locales: MsgLocalesSettings;
|
|
65
|
+
_loader: MsgTranslationLoader;
|
|
66
|
+
static create(data: MsgProjectData): MsgProject;
|
|
67
|
+
private constructor();
|
|
68
|
+
get project(): MsgProjectSettings;
|
|
69
|
+
get locales(): MsgLocalesSettings;
|
|
70
|
+
get loader(): MsgTranslationLoader;
|
|
71
|
+
/**
|
|
72
|
+
* The project-wide default message format. Resources (and, through them,
|
|
73
|
+
* messages) inherit this value unless they specify their own.
|
|
74
|
+
*/
|
|
75
|
+
get format(): MsgFormat;
|
|
76
|
+
getTargetLocale(locale: string): string[] | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { MsgProject as M, MsgResource, type MsgResourceData, type MsgProjectData as a, type MsgTranslationLoader as b };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { MsgAttributes, MsgNote, MsgInterface, MsgFormat } from '../MsgInterface/MsgInterface.js';
|
|
2
|
+
import { MsgMessageData, MsgMessage } from '../MsgMessage/MsgMessage.js';
|
|
3
|
+
import 'messageformat';
|
|
4
|
+
|
|
5
|
+
type MsgResourceData = {
|
|
6
|
+
title: string;
|
|
7
|
+
attributes: MsgAttributes;
|
|
8
|
+
notes?: MsgNote[];
|
|
9
|
+
messages?: MsgMessageData[];
|
|
10
|
+
};
|
|
11
|
+
declare class MsgResource extends Map<string, MsgMessage> implements MsgInterface {
|
|
12
|
+
private _attributes;
|
|
13
|
+
private _notes;
|
|
14
|
+
private _title;
|
|
15
|
+
private _project;
|
|
16
|
+
static create(data: MsgResourceData, project: MsgProject): MsgResource;
|
|
17
|
+
private constructor();
|
|
18
|
+
private hasMatchingAttributes;
|
|
19
|
+
private resolveFormat;
|
|
20
|
+
private pseudoLocalizeMF2;
|
|
21
|
+
get attributes(): MsgAttributes;
|
|
22
|
+
set attributes(attributes: MsgAttributes);
|
|
23
|
+
get notes(): MsgNote[];
|
|
24
|
+
set notes(notes: MsgNote[]);
|
|
25
|
+
addNote(note: MsgNote): void;
|
|
26
|
+
get title(): string;
|
|
27
|
+
set title(title: string);
|
|
28
|
+
getProject(): MsgProject;
|
|
29
|
+
add(key: string, value: string, attributes?: MsgAttributes, notes?: MsgNote[]): this;
|
|
30
|
+
translate(data: MsgResourceData): MsgResource;
|
|
31
|
+
/**
|
|
32
|
+
* Merge a `format` into an attribute set unless one is already present,
|
|
33
|
+
* so translations inherit the source's format without overriding an
|
|
34
|
+
* explicitly translated one. Returns the input unchanged when there is
|
|
35
|
+
* no format to preserve.
|
|
36
|
+
*/
|
|
37
|
+
private preserveFormat;
|
|
38
|
+
getTranslation(lang: string): Promise<MsgResource>;
|
|
39
|
+
getData(stripNotes?: boolean): MsgResourceData;
|
|
40
|
+
toJSON(stripNotes?: boolean): string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type MsgProjectSettings = {
|
|
44
|
+
name: string;
|
|
45
|
+
version?: number;
|
|
46
|
+
format?: MsgFormat;
|
|
47
|
+
};
|
|
48
|
+
type MsgTargetLocalesSettings = {
|
|
49
|
+
[key: string]: string[];
|
|
50
|
+
};
|
|
51
|
+
type MsgLocalesSettings = {
|
|
52
|
+
sourceLocale: string;
|
|
53
|
+
pseudoLocale: string;
|
|
54
|
+
targetLocales: MsgTargetLocalesSettings;
|
|
55
|
+
};
|
|
56
|
+
type MsgTranslationLoader = (project: string, title: string, lang: string) => Promise<MsgResourceData>;
|
|
57
|
+
type MsgProjectData = {
|
|
58
|
+
project: MsgProjectSettings;
|
|
59
|
+
locales: MsgLocalesSettings;
|
|
60
|
+
loader: MsgTranslationLoader;
|
|
61
|
+
};
|
|
62
|
+
declare class MsgProject {
|
|
63
|
+
_project: MsgProjectSettings;
|
|
64
|
+
_locales: MsgLocalesSettings;
|
|
65
|
+
_loader: MsgTranslationLoader;
|
|
66
|
+
static create(data: MsgProjectData): MsgProject;
|
|
67
|
+
private constructor();
|
|
68
|
+
get project(): MsgProjectSettings;
|
|
69
|
+
get locales(): MsgLocalesSettings;
|
|
70
|
+
get loader(): MsgTranslationLoader;
|
|
71
|
+
/**
|
|
72
|
+
* The project-wide default message format. Resources (and, through them,
|
|
73
|
+
* messages) inherit this value unless they specify their own.
|
|
74
|
+
*/
|
|
75
|
+
get format(): MsgFormat;
|
|
76
|
+
getTargetLocale(locale: string): string[] | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { MsgProject as M, MsgResource, type MsgResourceData, type MsgProjectData as a, type MsgTranslationLoader as b };
|