@jiyr0119/dsh-service-console 0.6.0 → 0.7.1
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/dsh.plugin.json +1 -1
- package/lib/client/i18n.js +59 -0
- package/lib/client.js +391 -165
- package/lib/host/config.js +19 -5
- package/lib/host/lifecycle.js +1 -0
- package/lib/host/process-inspector.js +2 -1
- package/lib/host/protection.js +41 -0
- package/lib/host/service-registry.js +14 -5
- package/lib/host/service-tool.js +158 -0
- package/lib/index.js +59 -28
- package/lib/types/client/ServiceConsole.d.ts +18 -8
- package/lib/types/client/dictionaries.d.ts +153 -2
- package/lib/types/client/i18n.d.ts +30 -0
- package/lib/types/client/index.d.ts +26 -7
- package/lib/types/host/config.d.ts +1 -0
- package/lib/types/host/process-inspector.d.ts +2 -0
- package/lib/types/host/protection.d.ts +21 -0
- package/lib/types/host/service-registry.d.ts +2 -1
- package/lib/types/host/service-tool.d.ts +6 -0
- package/lib/types/host/types.d.ts +2 -0
- package/manifest.json +1 -1
- package/package.json +6 -1
package/dsh.plugin.json
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/client/i18n.ts
|
|
2
|
+
/**
|
|
3
|
+
* 幂等注册词典:逐语种注册;单条失败(如 already has locale)跳过,
|
|
4
|
+
* 不影响其余语种与后续绑定。返回 disposer(整体可安全清理)。
|
|
5
|
+
*/
|
|
6
|
+
function registerDictionaries(locale, ns, dicts) {
|
|
7
|
+
const offs = [];
|
|
8
|
+
for (const pair of dicts) {
|
|
9
|
+
const code = pair[0];
|
|
10
|
+
const dict = pair[1];
|
|
11
|
+
try {
|
|
12
|
+
const off = locale.register(ns, code, dict);
|
|
13
|
+
if (typeof off === "function") offs.push(off);
|
|
14
|
+
} catch {}
|
|
15
|
+
}
|
|
16
|
+
return () => {
|
|
17
|
+
for (const off of offs) try {
|
|
18
|
+
off();
|
|
19
|
+
} catch {}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 绑定翻译函数:稳定外层 + 每次取最新 bound(旧版 bind 可能缓存语种)。
|
|
24
|
+
* 变量插值手工兜底(旧版 bound 可能不支持 params)。
|
|
25
|
+
*/
|
|
26
|
+
function bindTranslator(locale, ns) {
|
|
27
|
+
const make = () => {
|
|
28
|
+
let bound;
|
|
29
|
+
try {
|
|
30
|
+
bound = locale.bind(ns);
|
|
31
|
+
} catch {
|
|
32
|
+
bound = (key) => key;
|
|
33
|
+
}
|
|
34
|
+
return (key, params) => {
|
|
35
|
+
let s;
|
|
36
|
+
try {
|
|
37
|
+
s = bound(key);
|
|
38
|
+
} catch {
|
|
39
|
+
s = key;
|
|
40
|
+
}
|
|
41
|
+
if (typeof s !== "string" || s === "") s = key;
|
|
42
|
+
if (params) for (const k of Object.keys(params)) s = s.split("{" + k + "}").join(String(params[k]));
|
|
43
|
+
return s;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
let t = make();
|
|
47
|
+
return {
|
|
48
|
+
t: (key, params) => t(key, params),
|
|
49
|
+
subscribe: (fn) => {
|
|
50
|
+
const off = locale.subscribe(() => {
|
|
51
|
+
t = make();
|
|
52
|
+
fn();
|
|
53
|
+
});
|
|
54
|
+
return typeof off === "function" ? off : () => {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { bindTranslator, registerDictionaries };
|