@sunshaobei/dsh-session-manager 3.1.2 → 3.1.4
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/client.js +19 -12
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -224,21 +224,28 @@ window.__ModuleLoader__.load({
|
|
|
224
224
|
let hostTranslate;
|
|
225
225
|
|
|
226
226
|
function attachHostLocale(ctx) {
|
|
227
|
-
hostLocale =
|
|
227
|
+
try { hostLocale = ctx?.get?.('locale'); } catch { hostLocale = undefined; }
|
|
228
228
|
if (!hostLocale || typeof hostLocale.register !== 'function' || typeof hostLocale.bind !== 'function') return;
|
|
229
|
+
let unsubLocale;
|
|
229
230
|
try {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
hostLocale.register(LOCALE_NS, MESSAGES);
|
|
232
|
+
const bindNow = () => {
|
|
233
|
+
try {
|
|
234
|
+
const bound = hostLocale.bind(LOCALE_NS);
|
|
235
|
+
// Trust the service only once OUR keys resolve through it — translate()
|
|
236
|
+
// returns the raw key when the namespace carries no dictionary.
|
|
237
|
+
if (bound('recycleBin') !== 'recycleBin') hostTranslate = bound;
|
|
238
|
+
} catch { /* keep the built-in table */ }
|
|
239
|
+
};
|
|
240
|
+
bindNow();
|
|
241
|
+
// 语言切换时重绑(同 mcp-manager 的 subscribe 模式)
|
|
242
|
+
if (typeof hostLocale.subscribe === 'function' && typeof hostLocale.getSnapshot === 'function') {
|
|
243
|
+
unsubLocale = hostLocale.subscribe(bindNow);
|
|
244
|
+
}
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.warn('[dsh-session-manager] locale 注册失败:', error);
|
|
235
247
|
}
|
|
236
|
-
|
|
237
|
-
const bound = hostLocale.bind(LOCALE_NS);
|
|
238
|
-
// Trust the service only once OUR keys resolve through it — translate()
|
|
239
|
-
// returns the raw key when the namespace carries no dictionary.
|
|
240
|
-
if (bound('recycleBin') !== 'recycleBin') hostTranslate = bound;
|
|
241
|
-
} catch { /* keep the built-in table */ }
|
|
248
|
+
ctx.effect?.(() => () => { if (unsubLocale) unsubLocale(); }, 'session-trash: locale dictionaries');
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
function browserLocale() {
|
package/package.json
CHANGED