intl-messageformat 9.12.0 → 9.13.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/intl-messageformat.esm.js +1419 -5
- package/intl-messageformat.iife.js +1418 -5
- package/lib/src/core.d.ts +2 -0
- package/lib/src/core.d.ts.map +1 -1
- package/lib/src/core.js +12 -3
- package/package.json +2 -2
- package/src/core.d.ts +2 -0
- package/src/core.d.ts.map +1 -1
- package/src/core.js +12 -3
package/lib/src/core.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface Options {
|
|
|
13
13
|
export declare class IntlMessageFormat {
|
|
14
14
|
private readonly ast;
|
|
15
15
|
private readonly locales;
|
|
16
|
+
private readonly resolvedLocale;
|
|
16
17
|
private readonly formatters;
|
|
17
18
|
private readonly formats;
|
|
18
19
|
private readonly message;
|
|
@@ -26,6 +27,7 @@ export declare class IntlMessageFormat {
|
|
|
26
27
|
getAst: () => MessageFormatElement[];
|
|
27
28
|
private static memoizedDefaultLocale;
|
|
28
29
|
static get defaultLocale(): string;
|
|
30
|
+
static resolveLocale: (locales: string | string[]) => Intl.Locale;
|
|
29
31
|
static __parse: typeof parse | undefined;
|
|
30
32
|
static formats: Formats;
|
|
31
33
|
}
|
package/lib/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../../../packages/intl-messageformat/src/core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAA;AAsCrB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAwCD,qBAAa,iBAAiB;IAC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EAAoC,EAC5D,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,CAAC,EAAE,OAAO;IAkChB,MAAM,yJAyBL;IACD,aAAa,6IAWV;IACH,eAAe;;MAEb;IACF,MAAM,+BAAiB;IACvB,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAsB;IAE1D,MAAM,KAAK,aAAa,WAOvB;IACD,MAAM,CAAC,aAAa,YAAa,MAAM,GAAG,MAAM,EAAE,KAAG,KAAK,MAAM,CAO/D;IACD,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAQ;IAIhD,MAAM,CAAC,OAAO,EAAE,OAAO,CAmEtB;CACF"}
|
package/lib/src/core.js
CHANGED
|
@@ -117,9 +117,12 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
117
117
|
return formatToParts(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
118
118
|
};
|
|
119
119
|
this.resolvedOptions = function () { return ({
|
|
120
|
-
locale:
|
|
120
|
+
locale: _this.resolvedLocale.toString(),
|
|
121
121
|
}); };
|
|
122
122
|
this.getAst = function () { return _this.ast; };
|
|
123
|
+
// Defined first because it's used to build the format pattern.
|
|
124
|
+
this.locales = locales;
|
|
125
|
+
this.resolvedLocale = IntlMessageFormat.resolveLocale(locales);
|
|
123
126
|
if (typeof message === 'string') {
|
|
124
127
|
this.message = message;
|
|
125
128
|
if (!IntlMessageFormat.__parse) {
|
|
@@ -128,6 +131,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
128
131
|
// Parse string messages into an AST.
|
|
129
132
|
this.ast = IntlMessageFormat.__parse(message, {
|
|
130
133
|
ignoreTag: opts === null || opts === void 0 ? void 0 : opts.ignoreTag,
|
|
134
|
+
locale: this.resolvedLocale,
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
137
|
else {
|
|
@@ -139,8 +143,6 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
139
143
|
// Creates a new object with the specified `formats` merged with the default
|
|
140
144
|
// formats.
|
|
141
145
|
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
142
|
-
// Defined first because it's used to build the format pattern.
|
|
143
|
-
this.locales = locales;
|
|
144
146
|
this.formatters =
|
|
145
147
|
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
|
|
146
148
|
}
|
|
@@ -156,6 +158,13 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
156
158
|
configurable: true
|
|
157
159
|
});
|
|
158
160
|
IntlMessageFormat.memoizedDefaultLocale = null;
|
|
161
|
+
IntlMessageFormat.resolveLocale = function (locales) {
|
|
162
|
+
var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
163
|
+
if (supportedLocales.length > 0) {
|
|
164
|
+
return new Intl.Locale(supportedLocales[0]);
|
|
165
|
+
}
|
|
166
|
+
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
167
|
+
};
|
|
159
168
|
IntlMessageFormat.__parse = parse;
|
|
160
169
|
// Default format options used as the prototype of the `formats` provided to the
|
|
161
170
|
// constructor. These are used when constructing the internal Intl.NumberFormat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intl-messageformat",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.13.0",
|
|
4
4
|
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@formatjs/ecma402-abstract": "1.11.4",
|
|
35
35
|
"@formatjs/fast-memoize": "1.2.1",
|
|
36
|
-
"@formatjs/icu-messageformat-parser": "2.0
|
|
36
|
+
"@formatjs/icu-messageformat-parser": "2.1.0",
|
|
37
37
|
"tslib": "^2.1.0"
|
|
38
38
|
},
|
|
39
39
|
"sideEffects": false,
|
package/src/core.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface Options {
|
|
|
13
13
|
export declare class IntlMessageFormat {
|
|
14
14
|
private readonly ast;
|
|
15
15
|
private readonly locales;
|
|
16
|
+
private readonly resolvedLocale;
|
|
16
17
|
private readonly formatters;
|
|
17
18
|
private readonly formats;
|
|
18
19
|
private readonly message;
|
|
@@ -26,6 +27,7 @@ export declare class IntlMessageFormat {
|
|
|
26
27
|
getAst: () => MessageFormatElement[];
|
|
27
28
|
private static memoizedDefaultLocale;
|
|
28
29
|
static get defaultLocale(): string;
|
|
30
|
+
static resolveLocale: (locales: string | string[]) => Intl.Locale;
|
|
29
31
|
static __parse: typeof parse | undefined;
|
|
30
32
|
static formats: Formats;
|
|
31
33
|
}
|
package/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../../../packages/intl-messageformat/src/core.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,oBAAoB,EAAC,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EAElB,MAAM,cAAc,CAAA;AAsCrB,MAAM,WAAW,OAAO;IACtB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAwCD,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAwB;IAC5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAI9B;gBAEC,OAAO,EAAE,MAAM,GAAG,oBAAoB,EAAE,EACxC,OAAO,GAAE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,CAAC,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAQ;IAIhD,MAAM,CAAC,OAAO,EAAE,OAAO,CAmEtB;CACF"}
|
package/src/core.js
CHANGED
|
@@ -120,9 +120,12 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
120
120
|
return (0, formatters_1.formatToParts)(_this.ast, _this.locales, _this.formatters, _this.formats, values, undefined, _this.message);
|
|
121
121
|
};
|
|
122
122
|
this.resolvedOptions = function () { return ({
|
|
123
|
-
locale:
|
|
123
|
+
locale: _this.resolvedLocale.toString(),
|
|
124
124
|
}); };
|
|
125
125
|
this.getAst = function () { return _this.ast; };
|
|
126
|
+
// Defined first because it's used to build the format pattern.
|
|
127
|
+
this.locales = locales;
|
|
128
|
+
this.resolvedLocale = IntlMessageFormat.resolveLocale(locales);
|
|
126
129
|
if (typeof message === 'string') {
|
|
127
130
|
this.message = message;
|
|
128
131
|
if (!IntlMessageFormat.__parse) {
|
|
@@ -131,6 +134,7 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
131
134
|
// Parse string messages into an AST.
|
|
132
135
|
this.ast = IntlMessageFormat.__parse(message, {
|
|
133
136
|
ignoreTag: opts === null || opts === void 0 ? void 0 : opts.ignoreTag,
|
|
137
|
+
locale: this.resolvedLocale,
|
|
134
138
|
});
|
|
135
139
|
}
|
|
136
140
|
else {
|
|
@@ -142,8 +146,6 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
142
146
|
// Creates a new object with the specified `formats` merged with the default
|
|
143
147
|
// formats.
|
|
144
148
|
this.formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
|
|
145
|
-
// Defined first because it's used to build the format pattern.
|
|
146
|
-
this.locales = locales;
|
|
147
149
|
this.formatters =
|
|
148
150
|
(opts && opts.formatters) || createDefaultFormatters(this.formatterCache);
|
|
149
151
|
}
|
|
@@ -159,6 +161,13 @@ var IntlMessageFormat = /** @class */ (function () {
|
|
|
159
161
|
configurable: true
|
|
160
162
|
});
|
|
161
163
|
IntlMessageFormat.memoizedDefaultLocale = null;
|
|
164
|
+
IntlMessageFormat.resolveLocale = function (locales) {
|
|
165
|
+
var supportedLocales = Intl.NumberFormat.supportedLocalesOf(locales);
|
|
166
|
+
if (supportedLocales.length > 0) {
|
|
167
|
+
return new Intl.Locale(supportedLocales[0]);
|
|
168
|
+
}
|
|
169
|
+
return new Intl.Locale(typeof locales === 'string' ? locales : locales[0]);
|
|
170
|
+
};
|
|
162
171
|
IntlMessageFormat.__parse = icu_messageformat_parser_1.parse;
|
|
163
172
|
// Default format options used as the prototype of the `formats` provided to the
|
|
164
173
|
// constructor. These are used when constructing the internal Intl.NumberFormat
|