@discord/intl 0.10.0-rc.4 → 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/dist/format.js +6 -7
- package/package.json +2 -2
- package/src/format.ts +5 -6
package/dist/format.js
CHANGED
|
@@ -35,7 +35,7 @@ class FormatBuilder {
|
|
|
35
35
|
}
|
|
36
36
|
exports.FormatBuilder = FormatBuilder;
|
|
37
37
|
function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, formatConfig, values = {}, currentPluralValue, originalMessage) {
|
|
38
|
-
var _a
|
|
38
|
+
var _a;
|
|
39
39
|
// Hot path for static messages that are just parsed as a single string element.
|
|
40
40
|
if (nodes.length === 1 && typeof nodes[0] === 'string') {
|
|
41
41
|
builder.pushLiteralText(nodes[0]);
|
|
@@ -146,17 +146,16 @@ function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, format
|
|
|
146
146
|
break;
|
|
147
147
|
}
|
|
148
148
|
case intl_ast_1.FormatJsNodeType.Select: {
|
|
149
|
-
const
|
|
149
|
+
const requestedOption = value;
|
|
150
150
|
const options = node[2 /* AstNodeIndices.Options */];
|
|
151
|
-
const option =
|
|
151
|
+
const option = requestedOption in options ? options[requestedOption] : options.other;
|
|
152
152
|
if (option == null) {
|
|
153
|
-
throw `${
|
|
153
|
+
throw `${requestedOption} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
|
|
154
154
|
}
|
|
155
155
|
bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values);
|
|
156
156
|
break;
|
|
157
157
|
}
|
|
158
158
|
case intl_ast_1.FormatJsNodeType.Plural: {
|
|
159
|
-
const value = node[1 /* AstNodeIndices.Value */];
|
|
160
159
|
const options = node[2 /* AstNodeIndices.Options */];
|
|
161
160
|
const offset = node[3 /* AstNodeIndices.Offset */];
|
|
162
161
|
const pluralType = node[4 /* AstNodeIndices.PluralType */];
|
|
@@ -175,8 +174,8 @@ function bindFormatValuesWithBuilder(builder, nodes, locales, formatters, format
|
|
|
175
174
|
throw `${value} is not a known option for plural value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
|
|
176
175
|
}
|
|
177
176
|
bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values,
|
|
178
|
-
// @ts-expect-error assert this `as number` properly
|
|
179
|
-
value - (
|
|
177
|
+
// @ts-expect-error assert this `as number` properly
|
|
178
|
+
value - (offset !== null && offset !== void 0 ? offset : 0));
|
|
180
179
|
break;
|
|
181
180
|
}
|
|
182
181
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl",
|
|
3
|
-
"version": "0.10.0
|
|
3
|
+
"version": "0.10.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.10.0
|
|
22
|
+
"@discord/intl-ast": "0.10.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@swc/cli": "^0.3.12",
|
package/src/format.ts
CHANGED
|
@@ -192,18 +192,17 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
case FormatJsNodeType.Select: {
|
|
195
|
-
const
|
|
195
|
+
const requestedOption = value as string;
|
|
196
196
|
const options = node[AstNodeIndices.Options];
|
|
197
|
-
const option =
|
|
197
|
+
const option = requestedOption in options ? options[requestedOption] : options.other;
|
|
198
198
|
if (option == null) {
|
|
199
|
-
throw `${
|
|
199
|
+
throw `${requestedOption} is not a known option for select value ${variableName}. Valid options are ${Object.keys(options).join(', ')}`;
|
|
200
200
|
}
|
|
201
201
|
bindFormatValuesWithBuilder(builder, option, locales, formatters, formatConfig, values);
|
|
202
202
|
break;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
case FormatJsNodeType.Plural: {
|
|
206
|
-
const value = node[AstNodeIndices.Value];
|
|
207
206
|
const options = node[AstNodeIndices.Options];
|
|
208
207
|
const offset = node[AstNodeIndices.Offset];
|
|
209
208
|
const pluralType = node[AstNodeIndices.PluralType];
|
|
@@ -227,8 +226,8 @@ export function bindFormatValuesWithBuilder<T, Builder extends FormatBuilder<T>>
|
|
|
227
226
|
formatters,
|
|
228
227
|
formatConfig,
|
|
229
228
|
values,
|
|
230
|
-
// @ts-expect-error assert this `as number` properly
|
|
231
|
-
(value as number) - (
|
|
229
|
+
// @ts-expect-error assert this `as number` properly
|
|
230
|
+
(value as number) - (offset ?? 0),
|
|
232
231
|
);
|
|
233
232
|
break;
|
|
234
233
|
}
|