@discord/intl 0.5.2 → 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.
- package/dist/format.d.ts +3 -3
- package/dist/format.js +76 -107
- package/dist/formatters/ast.js +30 -77
- package/dist/formatters/markdown.js +18 -65
- package/dist/formatters/react.js +26 -72
- package/dist/formatters/string.js +15 -58
- package/dist/hash.js +11 -11
- package/dist/intl-manager.js +38 -89
- package/dist/message-loader.d.ts +8 -2
- package/dist/message-loader.js +93 -225
- package/dist/message.d.ts +3 -3
- package/dist/message.js +76 -135
- package/package.json +3 -2
- package/src/format.ts +39 -30
- package/src/intl-manager.ts +4 -2
- package/src/message-loader.ts +8 -2
- package/src/message.ts +48 -39
- package/dist/keyless-json.d.ts +0 -68
- package/dist/keyless-json.js +0 -107
- package/src/keyless-json.ts +0 -161
package/dist/formatters/react.js
CHANGED
|
@@ -1,63 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
3
|
exports.reactFormatter = exports.DEFAULT_REACT_RICH_TEXT_ELEMENTS = void 0;
|
|
44
4
|
exports.formatReact = formatReact;
|
|
45
5
|
exports.makeReactFormatter = makeReactFormatter;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
6
|
+
const React = require("react");
|
|
7
|
+
const format_1 = require("../format");
|
|
8
|
+
const h = React.createElement;
|
|
49
9
|
exports.DEFAULT_REACT_RICH_TEXT_ELEMENTS = {
|
|
50
|
-
$_:
|
|
51
|
-
$b:
|
|
52
|
-
$i:
|
|
53
|
-
$del:
|
|
54
|
-
$code:
|
|
10
|
+
$_: () => '',
|
|
11
|
+
$b: (content, key) => h('strong', { key }, content),
|
|
12
|
+
$i: (content, key) => h('em', { key }, content),
|
|
13
|
+
$del: (content, key) => h('del', { key }, content),
|
|
14
|
+
$code: (content, key) => h('code', { key }, content),
|
|
55
15
|
// $link will always be [href, <empty>, ...content]
|
|
56
|
-
$link:
|
|
57
|
-
|
|
58
|
-
return h('a', { href: href, key: key }, content);
|
|
59
|
-
},
|
|
60
|
-
$p: function (content, key) { return h('p', { key: key }, content); },
|
|
16
|
+
$link: ([href, ...content], key) => h('a', { href, key }, content),
|
|
17
|
+
$p: (content, key) => h('p', { key }, content),
|
|
61
18
|
};
|
|
62
19
|
/**
|
|
63
20
|
* Creates a new `FormatBuilder` class that constructs a React element tree
|
|
@@ -67,36 +24,33 @@ exports.DEFAULT_REACT_RICH_TEXT_ELEMENTS = {
|
|
|
67
24
|
* @param richTextElements
|
|
68
25
|
*/
|
|
69
26
|
function createReactBuilder(richTextElements) {
|
|
70
|
-
return
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_this.result = [];
|
|
76
|
-
return _this;
|
|
27
|
+
return class extends format_1.FormatBuilder {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this._nodeKey = 0;
|
|
31
|
+
this.result = [];
|
|
77
32
|
}
|
|
78
|
-
|
|
79
|
-
this.result.push(richTextElements[tag](children,
|
|
80
|
-
}
|
|
81
|
-
|
|
33
|
+
pushRichTextTag(tag, children) {
|
|
34
|
+
this.result.push(richTextElements[tag](children, `${this._nodeKey++}`));
|
|
35
|
+
}
|
|
36
|
+
pushLiteralText(text) {
|
|
82
37
|
this.result.push(text);
|
|
83
|
-
}
|
|
84
|
-
|
|
38
|
+
}
|
|
39
|
+
pushObject(value) {
|
|
85
40
|
// @ts-expect-error this is technically invalid, but we'll just assume that if a format returns
|
|
86
41
|
// an object, it'll be acting as some form of ReactNode.
|
|
87
42
|
this.result.push(value);
|
|
88
|
-
}
|
|
89
|
-
|
|
43
|
+
}
|
|
44
|
+
finish() {
|
|
90
45
|
return this.result;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}(format_1.FormatBuilder));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
94
48
|
}
|
|
95
49
|
function formatReact(message, values, Builder) {
|
|
96
50
|
if (typeof message === 'string') {
|
|
97
51
|
return [message];
|
|
98
52
|
}
|
|
99
|
-
|
|
53
|
+
const parts = this.bindFormatValues(Builder, message, values);
|
|
100
54
|
return parts;
|
|
101
55
|
}
|
|
102
56
|
/**
|
|
@@ -1,56 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
3
|
exports.stringFormatter = exports.StringBuilder = void 0;
|
|
44
4
|
exports.formatToPlainString = formatToPlainString;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
_this.result = '';
|
|
51
|
-
return _this;
|
|
5
|
+
const format_1 = require("../format");
|
|
6
|
+
class StringBuilder extends format_1.FormatBuilder {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.result = '';
|
|
52
10
|
}
|
|
53
|
-
|
|
11
|
+
pushRichTextTag(tag, children) {
|
|
54
12
|
// Plain string formatting ignores rich text tags and just takes the
|
|
55
13
|
// visible content from the children. This means the `target` element
|
|
56
14
|
// of a link is ignored, otherwise all the children are just joined
|
|
@@ -60,27 +18,26 @@ var StringBuilder = /** @class */ (function (_super) {
|
|
|
60
18
|
return;
|
|
61
19
|
}
|
|
62
20
|
this.result += children.join('');
|
|
63
|
-
}
|
|
64
|
-
|
|
21
|
+
}
|
|
22
|
+
pushLiteralText(text) {
|
|
65
23
|
this.result += text;
|
|
66
|
-
}
|
|
67
|
-
|
|
24
|
+
}
|
|
25
|
+
pushObject(value) {
|
|
68
26
|
// Objects are only included in the result if they specify a toString value directly.
|
|
69
27
|
// Otherwise, they would be rendered as `[object Object]`, which is never helpful.
|
|
70
28
|
if (value != null && 'toString' in value) {
|
|
71
29
|
this.result += value.toString();
|
|
72
30
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
31
|
+
}
|
|
32
|
+
finish() {
|
|
75
33
|
return [this.result];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}(format_1.FormatBuilder));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
79
36
|
exports.StringBuilder = StringBuilder;
|
|
80
37
|
function formatToPlainString(message, values) {
|
|
81
38
|
if (typeof message === 'string')
|
|
82
39
|
return message;
|
|
83
|
-
|
|
40
|
+
const result = this.bindFormatValues(StringBuilder, message, values);
|
|
84
41
|
// StringBuilder always creates a single element array with the string value.
|
|
85
42
|
return result[0];
|
|
86
43
|
}
|
package/dist/hash.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runtimeHashMessageKey = runtimeHashMessageKey;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const xxhash64_1 = require("@intrnl/xxhash64");
|
|
5
|
+
const BASE64_TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
|
|
6
|
+
const IS_BIG_ENDIAN = (() => {
|
|
7
|
+
const array = new Uint8Array(4);
|
|
8
|
+
const view = new Uint32Array(array.buffer);
|
|
9
9
|
return !((view[0] = 1) & array[0]);
|
|
10
10
|
})();
|
|
11
11
|
function numberToBytes(number) {
|
|
12
12
|
number = BigInt(number);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
for (
|
|
13
|
+
const array = [];
|
|
14
|
+
const byteCount = Math.ceil(Math.floor(Math.log2(Number(number)) + 1) / 8);
|
|
15
|
+
for (let i = 0; i < byteCount; i++) {
|
|
16
16
|
array.unshift(Number((number >> BigInt(8 * i)) & BigInt(255)));
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
const bytes = new Uint8Array(array);
|
|
19
19
|
// The native `hashToMessageKey` always works in Big/Network Endian bytes, so this array
|
|
20
20
|
// needs to be converted to the same endianness to get the same base64 result.
|
|
21
21
|
return IS_BIG_ENDIAN ? bytes : bytes.reverse();
|
|
@@ -28,8 +28,8 @@ function numberToBytes(number) {
|
|
|
28
28
|
* `@discord/intl-loader-core`, to be able to hash names at runtime.
|
|
29
29
|
*/
|
|
30
30
|
function runtimeHashMessageKey(key) {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const hash = (0, xxhash64_1.hash)(key, 0);
|
|
32
|
+
const bytes = numberToBytes(hash);
|
|
33
33
|
return [
|
|
34
34
|
BASE64_TABLE[bytes[0] >> 2],
|
|
35
35
|
BASE64_TABLE[((bytes[0] & 0x03) << 4) | (bytes[1] >> 4)],
|
package/dist/intl-manager.js
CHANGED
|
@@ -1,58 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
3
|
exports.IntlManager = exports.DEFAULT_LOCALE = void 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
4
|
+
const intl_ast_1 = require("@discord/intl-ast");
|
|
5
|
+
const intl_1 = require("@formatjs/intl");
|
|
6
|
+
const format_1 = require("./format");
|
|
7
|
+
const format_config_1 = require("./format-config");
|
|
34
8
|
/**
|
|
35
9
|
* Fallback locale used for all internationalization when an operation in the
|
|
36
10
|
* requested locale is not possible.
|
|
37
11
|
*/
|
|
38
12
|
exports.DEFAULT_LOCALE = 'en-US';
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (defaultLocale === void 0) { defaultLocale = exports.DEFAULT_LOCALE; }
|
|
42
|
-
var _this = this;
|
|
13
|
+
class IntlManager {
|
|
14
|
+
constructor(defaultLocale = exports.DEFAULT_LOCALE) {
|
|
43
15
|
/**
|
|
44
16
|
* Subscribe to changes in the current locale for this manager.
|
|
45
17
|
*/
|
|
46
|
-
this.onLocaleChange =
|
|
47
|
-
|
|
48
|
-
return
|
|
18
|
+
this.onLocaleChange = (callback) => {
|
|
19
|
+
this._localeSubscriptions.add(callback);
|
|
20
|
+
return () => this._localeSubscriptions.delete(callback);
|
|
49
21
|
};
|
|
50
22
|
this.defaultLocale = defaultLocale;
|
|
51
23
|
this.currentLocale = defaultLocale;
|
|
52
24
|
this.formatConfig = format_config_1.DEFAULT_FORMAT_CONFIG;
|
|
53
25
|
this.intl = (0, intl_1.createIntl)({
|
|
54
26
|
formats: format_config_1.DEFAULT_FORMAT_CONFIG,
|
|
55
|
-
defaultLocale
|
|
27
|
+
defaultLocale,
|
|
56
28
|
locale: defaultLocale,
|
|
57
29
|
});
|
|
58
30
|
this._localeSubscriptions = new Set();
|
|
@@ -61,74 +33,52 @@ var IntlManager = /** @class */ (function () {
|
|
|
61
33
|
* Add a set of formatter implementations to this manager, making each available as a direct
|
|
62
34
|
* property
|
|
63
35
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (var _b = __values(Object.entries(formatters)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
68
|
-
var _d = __read(_c.value, 2), name = _d[0], formatter = _d[1];
|
|
69
|
-
this[name] = this.makeFormatFunction(formatter);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
73
|
-
finally {
|
|
74
|
-
try {
|
|
75
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
76
|
-
}
|
|
77
|
-
finally { if (e_1) throw e_1.error; }
|
|
36
|
+
withFormatters(formatters) {
|
|
37
|
+
for (const [name, formatter] of Object.entries(formatters)) {
|
|
38
|
+
this[name] = this.makeFormatFunction(formatter);
|
|
78
39
|
}
|
|
79
40
|
return this;
|
|
80
|
-
}
|
|
41
|
+
}
|
|
81
42
|
/**
|
|
82
43
|
* Return a new function bound to this manager that uses the given `FormatterImplementation` to
|
|
83
44
|
* format a message after it has been resolved for the current locale and potentially processed in
|
|
84
45
|
* other ways by the manager.
|
|
85
46
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return function (message, values) {
|
|
91
|
-
return formatter(message(_this.currentLocale), values, builder);
|
|
47
|
+
makeFormatFunction({ format, builder, }) {
|
|
48
|
+
const formatter = format.bind(this);
|
|
49
|
+
return (message, values) => {
|
|
50
|
+
return formatter(message(this.currentLocale), values, builder);
|
|
92
51
|
};
|
|
93
|
-
}
|
|
52
|
+
}
|
|
94
53
|
/**
|
|
95
54
|
* Set the locale for this package to use. This is a global change, and all
|
|
96
55
|
* methods on this object will use this locale for formatting.
|
|
97
56
|
*/
|
|
98
|
-
|
|
57
|
+
setLocale(locale) {
|
|
99
58
|
this.currentLocale = locale;
|
|
100
|
-
this.intl = (0, intl_1.createIntl)({ defaultLocale: this.defaultLocale, locale
|
|
59
|
+
this.intl = (0, intl_1.createIntl)({ defaultLocale: this.defaultLocale, locale });
|
|
101
60
|
this.emitLocaleChange(locale);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
for (var _b = __values(this._localeSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
107
|
-
var callback = _c.value;
|
|
108
|
-
callback(locale);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
112
|
-
finally {
|
|
113
|
-
try {
|
|
114
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
115
|
-
}
|
|
116
|
-
finally { if (e_2) throw e_2.error; }
|
|
61
|
+
}
|
|
62
|
+
emitLocaleChange(locale) {
|
|
63
|
+
for (const callback of this._localeSubscriptions) {
|
|
64
|
+
callback(locale);
|
|
117
65
|
}
|
|
118
|
-
}
|
|
66
|
+
}
|
|
119
67
|
/**
|
|
120
68
|
* For static messages with no rich text and no dynamic placeholders, use this method to
|
|
121
69
|
* immediately return the plain string value of the message in the current locale.
|
|
122
70
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
71
|
+
string(message) {
|
|
72
|
+
const resolved = message(this.currentLocale);
|
|
125
73
|
if (resolved == null || resolved.ast.length === 0)
|
|
126
74
|
return '';
|
|
127
75
|
// TODO: Figure out how to make this typing exact. This currently relies on
|
|
128
76
|
// the generic typing being sound enough to know that the message can only
|
|
129
77
|
// contain a single static text node and no placeholders or rich text.
|
|
130
|
-
|
|
131
|
-
|
|
78
|
+
// As it stands, this is _technically_ typed as string | undefined, even though
|
|
79
|
+
// TypeScript doesn't actually complain about it.
|
|
80
|
+
return resolved.ast[0][intl_ast_1.AstNodeIndices.Value];
|
|
81
|
+
}
|
|
132
82
|
/**
|
|
133
83
|
* Return a raw string representing the syntax of the original message, as
|
|
134
84
|
* authored, with no values replaced. The result of this function could be
|
|
@@ -138,15 +88,14 @@ var IntlManager = /** @class */ (function () {
|
|
|
138
88
|
* This should rarely be necessary outside of sending raw messages to other
|
|
139
89
|
* applications that do their own message parsing.
|
|
140
90
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
91
|
+
reserialize(message) {
|
|
92
|
+
const resolved = message(this.currentLocale);
|
|
143
93
|
if (typeof resolved === 'string')
|
|
144
94
|
return resolved;
|
|
145
95
|
return resolved.reserialize();
|
|
146
|
-
}
|
|
147
|
-
|
|
96
|
+
}
|
|
97
|
+
bindFormatValues(Builder, message, values) {
|
|
148
98
|
return (0, format_1.bindFormatValues)(Builder, message.ast, [this.currentLocale, this.defaultLocale], this.intl.formatters, this.formatConfig, values);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
152
101
|
exports.IntlManager = IntlManager;
|
package/dist/message-loader.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AstNode, FullFormatJsNode } from '@discord/intl-ast';
|
|
2
2
|
import { InternalIntlMessage } from './message';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Type representing the serialized content of a translations file, which is a record of hashed
|
|
5
|
+
* message keys to their AST structure. This type represents both compressed, keyless AstNodes as
|
|
6
|
+
* well as fully-typed, object FullFormatJsNodes as the message content, since either can be given
|
|
7
|
+
* depending on the configuration of the bundler/compiler.
|
|
8
|
+
*/
|
|
9
|
+
type MessagesData = Record<string, AstNode[] | FullFormatJsNode[]>;
|
|
4
10
|
export interface IntlMessageGetterAdditions {
|
|
5
11
|
onChange(callback: () => void): () => void;
|
|
6
12
|
}
|