@discord/intl-loader-core 0.2.0 → 0.2.1-canary.d971c43
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/package.json +2 -2
- package/src/transformer.js +24 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/intl-loader-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-canary.d971c43",
|
|
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.2.0"
|
|
22
|
+
"@discord/intl-message-database": "0.2.1-rc.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/debug": "^4.1.12"
|
package/src/transformer.js
CHANGED
|
@@ -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
|
|
32
|
-
* export default
|
|
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
|
/**
|
|
@@ -50,6 +68,7 @@ class MessageDefinitionsTransformer {
|
|
|
50
68
|
*/
|
|
51
69
|
constructor(options) {
|
|
52
70
|
this.options = options;
|
|
71
|
+
this.loaderName = 'messagesLoader';
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
/**
|
|
@@ -87,7 +106,7 @@ class MessageDefinitionsTransformer {
|
|
|
87
106
|
if (!this.options.debug) return [];
|
|
88
107
|
|
|
89
108
|
return [
|
|
90
|
-
|
|
109
|
+
`${this.loaderName}.withDebugValues(${JSON.stringify(this.options.messageKeys)}, ${JSON.stringify(this.options.localeMap)})`,
|
|
91
110
|
];
|
|
92
111
|
}
|
|
93
112
|
|
|
@@ -105,9 +124,9 @@ class MessageDefinitionsTransformer {
|
|
|
105
124
|
`const _keys = ${JSON.stringify(this.options.messageKeys)};`,
|
|
106
125
|
`const _locales = ${this.getLocaleRequireMap()};`,
|
|
107
126
|
`const _defaultLocale = ${JSON.stringify(this.options.defaultLocale)};`,
|
|
108
|
-
|
|
127
|
+
`export const ${this.loaderName} = createLoader(_keys, _locales, _defaultLocale);`,
|
|
109
128
|
...this.debugModeSetup(),
|
|
110
|
-
|
|
129
|
+
`export default ${this.loaderName}.getBinds();`,
|
|
111
130
|
].join('\n');
|
|
112
131
|
}
|
|
113
132
|
}
|