@discord/intl-loader-core 0.1.2 → 0.2.0-canary.641ab2f

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/transformer.js +22 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@discord/intl-loader-core",
3
- "version": "0.1.2",
3
+ "version": "0.2.0-canary.641ab2f",
4
4
  "license": "MIT",
5
5
  "description": "Core utilities for writing loaders and transformers using @discord/intl",
6
6
  "author": "Jon Egeland",
@@ -19,7 +19,7 @@
19
19
  "chokidar": "^3.6.0",
20
20
  "debug": "^4.3.6",
21
21
  "fast-glob": "^3.3.2",
22
- "@discord/intl-message-database": "0.1.2"
22
+ "@discord/intl-message-database": "0.2.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/debug": "^4.1.12"
@@ -28,8 +28,8 @@
28
28
  * const {i18n} = require('@discord/intl');
29
29
  * const _keys = ["a9fn23"];
30
30
  * const _locales = {"en-US": () => require('./messages/en-US.messages.json')};
31
- * const loader = createLoader(_keys, _locales);
32
- * export default loader.getBinds();
31
+ * export const messagesLoader = createLoader(_keys, _locales);
32
+ * export default messagesLoader.getBinds();
33
33
  * ```
34
34
  *
35
35
  * Notice how the message keys have been hashed into short keys, and the
@@ -43,6 +43,24 @@
43
43
  * import someModuleMessages from 'SomeModule.messages.js';
44
44
  * i18n.format(someModuleMessages["a9fn23"], {values: "i'm a value!"});
45
45
  * ```
46
+ *
47
+ * The transformed file also contains a named export for `messagesLoader`,
48
+ * which consumers can use to query and update the loading state for the
49
+ * messages managed by that loader, including waiting for a locale to be
50
+ * loaded, kicking off new loads, and more:
51
+ *
52
+ * ```typescript
53
+ * import {messagesLoader} from 'SomeModule.messages.js';
54
+ * // Wait for the loader to be initialized with default messages
55
+ * await messagesLoader.waitForDefaultLocaleLoaded();
56
+ * // Wait for a specific locale to load, starting the load if it
57
+ * // is not yet in progress.
58
+ * await messagesLoader.waitForLocaleLoaded('fr');
59
+ * // In hot-reloading environments, use the second `requireCurrent`
60
+ * // parameter to wait for the latest data, even if a value already
61
+ * // exists.
62
+ * const loaded = messagesLoader.isLocaleLoaded('fr', true);
63
+ * ```
46
64
  */
47
65
  class MessageDefinitionsTransformer {
48
66
  /**
@@ -105,9 +123,9 @@ class MessageDefinitionsTransformer {
105
123
  `const _keys = ${JSON.stringify(this.options.messageKeys)};`,
106
124
  `const _locales = ${this.getLocaleRequireMap()};`,
107
125
  `const _defaultLocale = ${JSON.stringify(this.options.defaultLocale)};`,
108
- 'const loader = createLoader(_keys, _locales, _defaultLocale);',
126
+ 'export const messagesLoader = createLoader(_keys, _locales, _defaultLocale);',
109
127
  ...this.debugModeSetup(),
110
- 'export default loader.getBinds();',
128
+ 'export default messagesLoader.getBinds();',
111
129
  ].join('\n');
112
130
  }
113
131
  }