@discord/intl 0.10.2 → 0.10.3-canary.b2d8368

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.
@@ -20,7 +20,7 @@ export declare class IntlManager {
20
20
  intl: IntlShape;
21
21
  formatConfig: FormatConfig;
22
22
  _localeSubscriptions: Set<(locale: string) => void>;
23
- constructor(defaultLocale?: string);
23
+ constructor(initialLocale?: string, defaultLocale?: string);
24
24
  /**
25
25
  * Add a set of formatter implementations to this manager, making each available as a direct
26
26
  * property
@@ -10,7 +10,7 @@ const format_config_1 = require("./format-config");
10
10
  */
11
11
  exports.DEFAULT_LOCALE = 'en-US';
12
12
  class IntlManager {
13
- constructor(defaultLocale = exports.DEFAULT_LOCALE) {
13
+ constructor(initialLocale = exports.DEFAULT_LOCALE, defaultLocale = exports.DEFAULT_LOCALE) {
14
14
  /**
15
15
  * Subscribe to changes in the current locale for this manager.
16
16
  */
@@ -18,8 +18,8 @@ class IntlManager {
18
18
  this._localeSubscriptions.add(callback);
19
19
  return () => this._localeSubscriptions.delete(callback);
20
20
  };
21
+ this.currentLocale = initialLocale;
21
22
  this.defaultLocale = defaultLocale;
22
- this.currentLocale = defaultLocale;
23
23
  this.formatConfig = format_config_1.DEFAULT_FORMAT_CONFIG;
24
24
  this.intl = (0, intl_1.createIntl)({
25
25
  formats: format_config_1.DEFAULT_FORMAT_CONFIG,
@@ -24,7 +24,8 @@ class MessageLoader {
24
24
  this._localeLoadingPromises = {};
25
25
  this._parseCache = {};
26
26
  this._subscribers = new Set();
27
- this._loadLocale(this.defaultLocale);
27
+ // TODO: Bring this back as an option to pre-load the locale.
28
+ // this._loadLocale(this.defaultLocale);
28
29
  this.fallbackMessage = new message_1.InternalIntlMessage([], this.defaultLocale);
29
30
  // In cases where hot module replacement is available, set up cache clearing whenever the
30
31
  // targets change so that values are always replaced.
@@ -122,9 +123,13 @@ class MessageLoader {
122
123
  }
123
124
  _loadLocale(locale) {
124
125
  return __awaiter(this, void 0, void 0, function* () {
125
- var _a;
126
+ var _a, _b;
127
+ // If the locale is already set in `messages`, then it doesn't need to be loaded again.
128
+ if (this.messages[locale] != null)
129
+ return;
126
130
  // Don't re-load a locale that's already in progress.
127
131
  if (((_a = this._localeLoadingPromises[locale]) === null || _a === void 0 ? void 0 : _a.current) != null) {
132
+ yield ((_b = this._localeLoadingPromises[locale]) === null || _b === void 0 ? void 0 : _b.current);
128
133
  return;
129
134
  }
130
135
  // Safety check in case the locale map doesn't include a require for the
@@ -140,9 +145,6 @@ class MessageLoader {
140
145
  return;
141
146
  }
142
147
  }
143
- // If the locale is already set in `messages`, then it doesn't need to be loaded again.
144
- if (this.messages[locale] != null)
145
- return;
146
148
  const current = this.localeImportMap[locale]();
147
149
  this._localeLoadingPromises[locale] = { initialized: false, current };
148
150
  this.messages[locale] = (yield current).default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl",
3
- "version": "0.10.2",
3
+ "version": "0.10.3-canary.b2d8368",
4
4
  "license": "MIT",
5
5
  "description": "Client runtime for managing messages and translations in a React project.",
6
6
  "main": "./dist/index.js",
@@ -14,12 +14,16 @@
14
14
  "dist",
15
15
  "src"
16
16
  ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/discord/discord-intl"
20
+ },
17
21
  "dependencies": {
18
22
  "@formatjs/icu-skeleton-parser": "1.8.2",
19
23
  "@formatjs/intl": "^2.10.1",
20
24
  "@intrnl/xxhash64": "^0.1.2",
21
25
  "intl-messageformat": "^10.5.11",
22
- "@discord/intl-ast": "0.10.2"
26
+ "@discord/intl-ast": "0.10.3"
23
27
  },
24
28
  "devDependencies": {
25
29
  "@swc/cli": "^0.3.12",
@@ -27,17 +31,7 @@
27
31
  "typescript": "*"
28
32
  },
29
33
  "peerDependencies": {
30
- "@rspack/core": "0.x || 1.x",
31
- "react": "> 16",
32
- "webpack": "^5.0.0"
33
- },
34
- "peerDependenciesMeta": {
35
- "@rspack/core": {
36
- "optional": true
37
- },
38
- "webpack": {
39
- "optional": true
40
- }
34
+ "react": "> 16"
41
35
  },
42
36
  "scripts": {
43
37
  "build": "tsc",
@@ -45,9 +45,9 @@ export class IntlManager {
45
45
 
46
46
  _localeSubscriptions: Set<(locale: string) => void>;
47
47
 
48
- constructor(defaultLocale: string = DEFAULT_LOCALE) {
48
+ constructor(initialLocale: string = DEFAULT_LOCALE, defaultLocale: string = DEFAULT_LOCALE) {
49
+ this.currentLocale = initialLocale;
49
50
  this.defaultLocale = defaultLocale;
50
- this.currentLocale = defaultLocale;
51
51
  this.formatConfig = DEFAULT_FORMAT_CONFIG;
52
52
  this.intl = createIntl({
53
53
  formats: DEFAULT_FORMAT_CONFIG,
@@ -96,7 +96,8 @@ export class MessageLoader {
96
96
  this._parseCache = {};
97
97
  this._subscribers = new Set();
98
98
 
99
- this._loadLocale(this.defaultLocale);
99
+ // TODO: Bring this back as an option to pre-load the locale.
100
+ // this._loadLocale(this.defaultLocale);
100
101
  this.fallbackMessage = new InternalIntlMessage([], this.defaultLocale);
101
102
 
102
103
  // In cases where hot module replacement is available, set up cache clearing whenever the
@@ -204,8 +205,12 @@ export class MessageLoader {
204
205
  }
205
206
 
206
207
  async _loadLocale(locale: LocaleId) {
208
+ // If the locale is already set in `messages`, then it doesn't need to be loaded again.
209
+ if (this.messages[locale] != null) return;
210
+
207
211
  // Don't re-load a locale that's already in progress.
208
212
  if (this._localeLoadingPromises[locale]?.current != null) {
213
+ await this._localeLoadingPromises[locale]?.current;
209
214
  return;
210
215
  }
211
216
 
@@ -224,9 +229,6 @@ export class MessageLoader {
224
229
  }
225
230
  }
226
231
 
227
- // If the locale is already set in `messages`, then it doesn't need to be loaded again.
228
- if (this.messages[locale] != null) return;
229
-
230
232
  const current = this.localeImportMap[locale]();
231
233
  this._localeLoadingPromises[locale] = { initialized: false, current };
232
234
  this.messages[locale] = (await current).default;