@discord/intl 0.7.1-rc.0 → 0.8.0-rc.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.js +5 -5
- package/dist/formatters/react.js +7 -1
- package/dist/intl-manager.js +8 -10
- package/package.json +2 -2
- package/src/format.ts +5 -5
- package/src/formatters/react.ts +6 -1
- package/src/intl-manager.ts +10 -13
package/dist/format.js
CHANGED
|
@@ -37,16 +37,16 @@ exports.FormatBuilder = FormatBuilder;
|
|
|
37
37
|
function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, formatConfig, values = {}, currentPluralValue, originalMessage) {
|
|
38
38
|
var _a, _b;
|
|
39
39
|
// Hot path for static messages that are just parsed as a single string element.
|
|
40
|
-
if (nodes.length === 1 && typeof nodes[0]
|
|
41
|
-
builder.pushLiteralText(nodes[0]
|
|
40
|
+
if (nodes.length === 1 && typeof nodes[0] === 'string') {
|
|
41
|
+
builder.pushLiteralText(nodes[0]);
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
for (const node of nodes) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
builder.pushLiteralText(nodeType);
|
|
45
|
+
if (typeof node === 'string') {
|
|
46
|
+
builder.pushLiteralText(node);
|
|
48
47
|
continue;
|
|
49
48
|
}
|
|
49
|
+
const nodeType = node[intl_ast_1.AstNodeIndices.Type];
|
|
50
50
|
switch (nodeType) {
|
|
51
51
|
case intl_ast_1.FormatJsNodeType.Pound:
|
|
52
52
|
// Replace `#` in plural rules with the actual numeric value. Only
|
package/dist/formatters/react.js
CHANGED
|
@@ -34,7 +34,13 @@ function createReactBuilder(richTextElements) {
|
|
|
34
34
|
this.result.push(richTextElements[tag](children, `${this._nodeKey++}`));
|
|
35
35
|
}
|
|
36
36
|
pushLiteralText(text) {
|
|
37
|
-
this.result.
|
|
37
|
+
const last = this.result[this.result.length - 1];
|
|
38
|
+
if (typeof last === 'string') {
|
|
39
|
+
this.result[this.result.length - 1] += text;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.result.push(text);
|
|
43
|
+
}
|
|
38
44
|
}
|
|
39
45
|
pushObject(value) {
|
|
40
46
|
// @ts-expect-error this is technically invalid, but we'll just assume that if a format returns
|
package/dist/intl-manager.js
CHANGED
|
@@ -71,17 +71,15 @@ class IntlManager {
|
|
|
71
71
|
const resolved = message(this.currentLocale);
|
|
72
72
|
if (resolved == null || resolved.ast.length === 0)
|
|
73
73
|
return '';
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
let result = '';
|
|
75
|
+
for (const element of resolved.ast) {
|
|
76
|
+
if (typeof element !== 'string') {
|
|
77
|
+
throw new Error('Attempted to call `string` formatting on a non-literal message: ' +
|
|
78
|
+
JSON.stringify(resolved));
|
|
79
|
+
}
|
|
80
|
+
result += element;
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
// the generic typing being sound enough to know that the message can only
|
|
81
|
-
// contain a single static text node and no placeholders or rich text.
|
|
82
|
-
// As it stands, this is _technically_ typed as string | undefined, even though
|
|
83
|
-
// TypeScript doesn't actually complain about it.
|
|
84
|
-
return value;
|
|
82
|
+
return result;
|
|
85
83
|
}
|
|
86
84
|
/**
|
|
87
85
|
* Return a raw string representing the syntax of the original message, as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Client runtime for managing messages and translations in a React project.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@formatjs/intl": "^2.10.1",
|
|
20
20
|
"@intrnl/xxhash64": "^0.1.2",
|
|
21
21
|
"intl-messageformat": "^10.5.11",
|
|
22
|
-
"@discord/intl-ast": "0.
|
|
22
|
+
"@discord/intl-ast": "0.8.0-rc.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@swc/cli": "^0.3.12",
|
package/src/format.ts
CHANGED
|
@@ -56,17 +56,17 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
|
|
|
56
56
|
originalMessage?: string,
|
|
57
57
|
) {
|
|
58
58
|
// Hot path for static messages that are just parsed as a single string element.
|
|
59
|
-
if (nodes.length === 1 && typeof nodes[0]
|
|
60
|
-
builder.pushLiteralText(nodes[0]
|
|
59
|
+
if (nodes.length === 1 && typeof nodes[0] === 'string') {
|
|
60
|
+
builder.pushLiteralText(nodes[0]);
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
for (const node of nodes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
builder.pushLiteralText(nodeType);
|
|
65
|
+
if (typeof node === 'string') {
|
|
66
|
+
builder.pushLiteralText(node);
|
|
68
67
|
continue;
|
|
69
68
|
}
|
|
69
|
+
const nodeType = node[AstNodeIndices.Type];
|
|
70
70
|
switch (nodeType) {
|
|
71
71
|
case FormatJsNodeType.Pound:
|
|
72
72
|
// Replace `#` in plural rules with the actual numeric value. Only
|
package/src/formatters/react.ts
CHANGED
|
@@ -56,7 +56,12 @@ function createReactBuilder(richTextElements: RichTextFormattingMap<ReactFunctio
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
pushLiteralText(text: string) {
|
|
59
|
-
this.result.
|
|
59
|
+
const last = this.result[this.result.length - 1];
|
|
60
|
+
if (typeof last === 'string') {
|
|
61
|
+
this.result[this.result.length - 1] += text;
|
|
62
|
+
} else {
|
|
63
|
+
this.result.push(text);
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
pushObject(value: object) {
|
package/src/intl-manager.ts
CHANGED
|
@@ -120,20 +120,17 @@ export class IntlManager {
|
|
|
120
120
|
const resolved = message(this.currentLocale);
|
|
121
121
|
if (resolved == null || resolved.ast.length === 0) return '';
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
let result = '';
|
|
124
|
+
for (const element of resolved.ast) {
|
|
125
|
+
if (typeof element !== 'string') {
|
|
126
|
+
throw new Error(
|
|
127
|
+
'Attempted to call `string` formatting on a non-literal message: ' +
|
|
128
|
+
JSON.stringify(resolved),
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
result += element;
|
|
129
132
|
}
|
|
130
|
-
|
|
131
|
-
// TODO: Figure out how to make this typing exact. This currently relies on
|
|
132
|
-
// the generic typing being sound enough to know that the message can only
|
|
133
|
-
// contain a single static text node and no placeholders or rich text.
|
|
134
|
-
// As it stands, this is _technically_ typed as string | undefined, even though
|
|
135
|
-
// TypeScript doesn't actually complain about it.
|
|
136
|
-
return value;
|
|
133
|
+
return result;
|
|
137
134
|
}
|
|
138
135
|
|
|
139
136
|
/**
|