@sunshaobei/dsh-session-manager 3.1.3 → 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 -14
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -224,23 +224,28 @@ window.__ModuleLoader__.load({
|
|
|
224
224
|
let hostTranslate;
|
|
225
225
|
|
|
226
226
|
function attachHostLocale(ctx) {
|
|
227
|
-
|
|
228
|
-
hostLocale = (ctx && ctx.locale && typeof ctx.locale.register === 'function') ? ctx.locale : undefined;
|
|
229
|
-
if (!hostLocale && typeof ctx?.get === 'function') { try { hostLocale = ctx.get('locale'); } catch { /* keep undefined */ } }
|
|
227
|
+
try { hostLocale = ctx?.get?.('locale'); } catch { hostLocale = undefined; }
|
|
230
228
|
if (!hostLocale || typeof hostLocale.register !== 'function' || typeof hostLocale.bind !== 'function') return;
|
|
229
|
+
let unsubLocale;
|
|
231
230
|
try {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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);
|
|
237
247
|
}
|
|
238
|
-
|
|
239
|
-
const bound = hostLocale.bind(LOCALE_NS);
|
|
240
|
-
// Trust the service only once OUR keys resolve through it — translate()
|
|
241
|
-
// returns the raw key when the namespace carries no dictionary.
|
|
242
|
-
if (bound('recycleBin') !== 'recycleBin') hostTranslate = bound;
|
|
243
|
-
} catch { /* keep the built-in table */ }
|
|
248
|
+
ctx.effect?.(() => () => { if (unsubLocale) unsubLocale(); }, 'session-trash: locale dictionaries');
|
|
244
249
|
}
|
|
245
250
|
|
|
246
251
|
function browserLocale() {
|
package/package.json
CHANGED