dsh-peak-hours 1.12.1 → 1.12.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.12.2 — 2026-10-30
4
+
5
+ ### 修正
6
+
7
+ - **设置页卡片显示英文**:语言包用错了 API。`register(ns, { zh, en })` 这个两参形式只存在于 typed 重载(命名空间必须在 `LocaleNamespaceMap` 合并表里);我们的命名空间不在合并表里,真实签名是 `register(ns, localeId, dict)`。两参调用会抛「locale 不是 BCP 47」,又被我自己的 try/catch 吞掉 —— 字典从未注册成功,`bind()` 出来的译文一路回落到内置英文兜底。现在按语言列表逐个用三参注册(`zh-CN` / `en`),并补了一条「中文环境下设置页卡片必须是中文」的用例。
8
+
3
9
  ## 1.12.1 — 2026-10-30
4
10
 
5
11
  ### 修正
package/client.js CHANGED
@@ -866,16 +866,34 @@ window.__ModuleLoader__.load({
866
866
  apply(ctx) {
867
867
  ctx.effect(ensureStyle, 'dsh-peak-hours-style');
868
868
 
869
- // 语言包晚到也不影响:locale 可用时立刻补注册并接管文案。
869
+ // 语言包:untyped 版 register 是 (ns, localeId, dict) 三参;
870
+ // 两参的 { zh, en } 形式只存在于 typed 重载(LocaleNamespaceMap 里有该 ns),
871
+ // 我们的 ns 不在合并表里,用两参会抛 "locale 不是 BCP 47",字典就永远注册不上。
870
872
  ctx.inject(['locale'], (c) => {
871
- if (!c.locale || typeof c.locale.register !== 'function') return;
873
+ const loc = c && c.locale;
874
+ if (!loc || typeof loc.register !== 'function') return;
875
+ let ids = [];
872
876
  try {
873
- c.locale.register(NS, { zh: ZH, en: EN });
877
+ const snap =
878
+ typeof loc.getSnapshot === 'function' ? loc.getSnapshot() : loc.getLocale();
879
+ ids = (snap && snap.locales ? snap.locales : []).map((l) => l.id);
874
880
  } catch {
875
- /* 已注册过(例如热重载),沿用现有字典 */
881
+ /* 拿不到语言列表就用内置推断 */
882
+ }
883
+ const pick = (re, fallback) => ids.find((id) => re.test(id)) || fallback;
884
+ const packs = [
885
+ [pick(/^zh/i, 'zh-CN'), ZH],
886
+ [pick(/^en/i, 'en'), EN],
887
+ ];
888
+ for (const [id, dict] of packs) {
889
+ try {
890
+ loc.register(NS, id, dict);
891
+ } catch {
892
+ /* 已注册过(例如热重载),沿用现有字典 */
893
+ }
876
894
  }
877
895
  try {
878
- const bound = c.locale.bind(NS);
896
+ const bound = loc.bind(NS);
879
897
  if (typeof bound === 'function') translate = bound;
880
898
  } catch {
881
899
  /* 保留内置兜底 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-peak-hours",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "type": "module",
5
5
  "description": "Sidebar badge that marks the current DeepSeek peak-pricing window (24-hour schedule bar, countdown, click to copy) plus a settings card that splits your logged usage into peak / off-peak tokens and compares what it actually cost against all-peak and all-off-peak.",
6
6
  "license": "MIT",