@mfeflow/i18n 0.1.0 → 0.3.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/dist/index.d.ts +3 -1
- package/dist/index.js +9 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -26,12 +26,14 @@ interface I18nState {
|
|
|
26
26
|
}
|
|
27
27
|
declare global {
|
|
28
28
|
var mfeflowI18n: I18nState | undefined;
|
|
29
|
+
var mfeflowI18nPending: Promise<I18n> | undefined;
|
|
29
30
|
}
|
|
30
31
|
/** Stored choice, then the first browser language we support (exact or base), then the default. */
|
|
31
32
|
export declare function detectLanguage(supported: readonly string[], stored: string | undefined, preferred: readonly string[], fallback: string): string;
|
|
32
33
|
/**
|
|
33
34
|
* Creates the page's single i18next instance. Call once, in the shell, before
|
|
34
|
-
* rendering. Calling it again returns the existing instance
|
|
35
|
+
* rendering. Calling it again returns the existing instance, or the one being
|
|
36
|
+
* created, so two calls in the same tick make one instance.
|
|
35
37
|
*/
|
|
36
38
|
export declare function initI18n(options: InitI18nOptions): Promise<I18n>;
|
|
37
39
|
/** The page's i18next instance. Throws if the shell has not called `initI18n`. */
|
package/dist/index.js
CHANGED
|
@@ -20,8 +20,14 @@ function applyDocumentLanguage(instance, root, lng) {
|
|
|
20
20
|
el.lang = lng;
|
|
21
21
|
el.dir = instance.dir(lng);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
if (globalThis.mfeflowI18n) return globalThis.mfeflowI18n.instance;
|
|
23
|
+
function initI18n(options) {
|
|
24
|
+
if (globalThis.mfeflowI18n) return Promise.resolve(globalThis.mfeflowI18n.instance);
|
|
25
|
+
const pending = globalThis.mfeflowI18nPending ??= create(options).finally(()=>{
|
|
26
|
+
globalThis.mfeflowI18nPending = void 0;
|
|
27
|
+
});
|
|
28
|
+
return pending;
|
|
29
|
+
}
|
|
30
|
+
async function create(options) {
|
|
25
31
|
const codes = options.languages.map((l)=>l.code);
|
|
26
32
|
if (!codes.includes(options.defaultLanguage)) throw new Error(`Default language "${options.defaultLanguage}" is not in the language list`);
|
|
27
33
|
const storage = options.storage ?? createStorage('shell');
|
|
@@ -82,5 +88,6 @@ async function loadNamespace(instance, namespace, loader, language = instance.la
|
|
|
82
88
|
}
|
|
83
89
|
function resetI18nForTests() {
|
|
84
90
|
globalThis.mfeflowI18n = void 0;
|
|
91
|
+
globalThis.mfeflowI18nPending = void 0;
|
|
85
92
|
}
|
|
86
93
|
export { LANGUAGE_STORAGE_KEY, detectLanguage, getI18n, getLanguages, initI18n, loadNamespace, resetI18nForTests };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mfeflow/i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "i18n for micro-frontends: one i18next instance owned by the shell, each remote lazy-loads its own namespace from its own deploy, RTL and persisted language.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"micro-frontend",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"provenance": true
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mfeflow/storage": "0.
|
|
50
|
+
"@mfeflow/storage": "0.3.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"i18next": "^26.0.0",
|