@huanlin/dsh-plugin-interpreters 0.2.2 → 0.2.3
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/client.js +17 -7
- package/lib/types/client/index.js +22 -8
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -905,13 +905,23 @@ var dicts = {
|
|
|
905
905
|
var inject = ["slots", "locale", "connection"];
|
|
906
906
|
function apply(ctx) {
|
|
907
907
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), "dsh-interpreters: dictionaries");
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
()
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
908
|
+
ctx.effect(() => {
|
|
909
|
+
let dispose;
|
|
910
|
+
const sync = () => {
|
|
911
|
+
dispose?.();
|
|
912
|
+
dispose = void 0;
|
|
913
|
+
const store = ctx.get("betterLocale");
|
|
914
|
+
if (store !== void 0) {
|
|
915
|
+
dispose = store.register(NS, dicts);
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
sync();
|
|
919
|
+
const unsubscribe = ctx.locale.subscribe(sync);
|
|
920
|
+
return () => {
|
|
921
|
+
unsubscribe();
|
|
922
|
+
dispose?.();
|
|
923
|
+
};
|
|
924
|
+
}, "interpreters: better-locale override dicts");
|
|
915
925
|
const controller = new InterpretersCardController();
|
|
916
926
|
const useSnapshot = bindSnapshotSelector(controller.store);
|
|
917
927
|
ctx.effect(() => {
|
|
@@ -32,14 +32,28 @@ export const inject = ['slots', 'locale', 'connection'];
|
|
|
32
32
|
*/
|
|
33
33
|
export function apply(ctx) {
|
|
34
34
|
ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'dsh-interpreters: dictionaries');
|
|
35
|
-
// Opt-in third-language overrides through @huanlin/dsh-plugin-better-locale
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
// Opt-in third-language overrides through @huanlin/dsh-plugin-better-locale.
|
|
36
|
+
// Activation-order-safe: ctx.get('betterLocale') is a non-reactive read, so
|
|
37
|
+
// if better-locale activates after us, the initial read returns undefined.
|
|
38
|
+
// We subscribe to ctx.locale — better-locale bumps its revision on activation
|
|
39
|
+
// (persisted override) and on every override switch — and re-check on each bump.
|
|
40
|
+
ctx.effect(() => {
|
|
41
|
+
let dispose;
|
|
42
|
+
const sync = () => {
|
|
43
|
+
dispose?.();
|
|
44
|
+
dispose = undefined;
|
|
45
|
+
const store = ctx.get('betterLocale');
|
|
46
|
+
if (store !== undefined) {
|
|
47
|
+
dispose = store.register(NS, dicts);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
sync();
|
|
51
|
+
const unsubscribe = ctx.locale.subscribe(sync);
|
|
52
|
+
return () => {
|
|
53
|
+
unsubscribe();
|
|
54
|
+
dispose?.();
|
|
55
|
+
};
|
|
56
|
+
}, 'interpreters: better-locale override dicts');
|
|
43
57
|
// The store reads/writes the interpreters config over the plugin's
|
|
44
58
|
// self-hosted HTTP route (`/interpreters/api/get` + `/interpreters/api/set`).
|
|
45
59
|
const controller = new InterpretersCardController();
|