intl-messageformat 9.11.3 → 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/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
  }
@@ -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,MAAM,GAAG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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: Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
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
@@ -101,7 +101,7 @@ originalMessage) {
101
101
  ? formats.time[el.style]
102
102
  : isDateTimeSkeleton(el.style)
103
103
  ? el.style.parsedOptions
104
- : undefined;
104
+ : formats.time.medium;
105
105
  result.push({
106
106
  type: PART_TYPE.literal,
107
107
  value: formatters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intl-messageformat",
3
- "version": "9.11.3",
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",
@@ -31,9 +31,9 @@
31
31
  "module": "lib/index.js",
32
32
  "types": "index.d.ts",
33
33
  "dependencies": {
34
- "@formatjs/ecma402-abstract": "1.11.2",
34
+ "@formatjs/ecma402-abstract": "1.11.4",
35
35
  "@formatjs/fast-memoize": "1.2.1",
36
- "@formatjs/icu-messageformat-parser": "2.0.17",
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,MAAM,GAAG,MAAM,EAAoC,EAC5D,eAAe,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAClC,IAAI,CAAC,EAAE,OAAO;IAgChB,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,OAAO,EAAE,OAAO,KAAK,GAAG,SAAS,CAAQ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AM,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: Intl.NumberFormat.supportedLocalesOf(_this.locales)[0],
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
package/src/formatters.js CHANGED
@@ -105,7 +105,7 @@ originalMessage) {
105
105
  ? formats.time[el.style]
106
106
  : (0, icu_messageformat_parser_1.isDateTimeSkeleton)(el.style)
107
107
  ? el.style.parsedOptions
108
- : undefined;
108
+ : formats.time.medium;
109
109
  result.push({
110
110
  type: PART_TYPE.literal,
111
111
  value: formatters