Repository navigation
feat(i18n): English UI layer with reactive language switching - #7
Merged
Merged
Conversation
Add a lightweight i18n layer to lib/client.js so the whole web panel can be displayed in English while keeping Chinese fully intact: - zh strings stay as-is and double as dictionary keys; a 271-entry EN map covers all 408 wrapped string sites - language is auto-detected from navigator.language (zh -> Chinese, otherwise English); a toggle button next to Refresh switches instantly and persists the choice in localStorage (dsh-usage-lang) - PNG report, calendar hover tooltips and canvas tables are translated too; data-facing comparisons (e.g. the total-row key) intentionally stay raw so host-side values keep matching - host-side (lib/index.js) log/error messages are unchanged in this pass; proposed as follow-up work Verified: node --check passes; bundle loads through a stubbed ModuleLoader; every t() call site resolves in the dictionary (0 missing).
… locale dates
Review follow-up on the initial i18n commit:
1. Language toggle is now fully reactive and network-independent:
- module-level listener registry + useLang() hook (React state)
- setLang() persists and notifies subscribers; panels re-render
instantly even if /usage/api never resolves
- SUBTABS hold raw zh keys and are translated at render time
(also removes the t-shadowing inside the map callback)
- BalancePanel subscribes too; external slots labels are frozen at
registration by design and refresh on page reload (noted in the
button tooltip and README)
2. Balance host responses carry semantic keys instead of Chinese
presentation strings:
- balance.js emits labelKey/hintKey/meaningKey/sourceNoteKey/
balanceLabelKey (+ credentialHint keys); numeric values and API
field names stay raw
- both locales for those keys live in the client (__BAL_ZH/__BAL_EN
rendered through tb())
- successful payloads no longer contain CJK presentation text;
covered by new unit tests (12 total, all passing)
3. Locale-aware dates and weekdays:
- dayLabel/fmtMonthLabel/dailyStatsTitle/weekdayLabels helpers
- zh keeps 2026年8月22日 style; en renders "Aug 22, 2026",
"August 2026" and Mo..Su headers (Sunday no longer collides with
the date-suffix key)
Verified: node --check on lib/*.js; node --test test/balance.test.js
(12 passing); every t()/tb() call site resolves in its dictionary;
bundle smoke-loads through a stubbed ModuleLoader.
…nt messages, docs
1. Missing-credential errors no longer leak internal hint keys:
- PROVIDERS.credentialHint renamed to credentialHintKey (semantic)
- index.js builds the message from technical credential names via a
new missingCredentialError() helper in balance.js
("未找到 DEEPSEEK_API_KEY,请配置后重试", errorCode: missing-credential)
2. Transient UI messages are now reactive:
- export/import/picker status messages and client-side validation
errors are stored as semantic descriptors ({k}, {k,tail}, {seq},
errorKey) and translated at render time through msgText()
- switching language instantly re-renders existing status lines
3. READMEs state the slots-label reload caveat (synced with CHANGELOG
and the toggle tooltip).
4. Tests & debug hook:
- exports.__i18n (t/tb/msgText/setLang/date formatters)
- new test/client-i18n.test.js (7 tests): instant switch + storage
persistence across mounts, date/weekday rendering, transient
message locales, balance key coverage in both locales,
missing-credential error shape
All green: node --test test/balance.test.js (12), test/client-i18n.test.js (7);
node --check on lib/client.js, lib/balance.js, lib/index.js.
Owner
|
Thank you, my dear friend! Our team has wanted to add an English interface for a long time now. Thank you for your edits and additions. We'll keep creating more in the future |
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
- PR #7 (@ayleen): English UI layer with reactive language switching; balance semantic keys - PR #8 (@wuhuqif176): Bailian/Qwen Token Plan quota query in balance panel - bump to v1.13.0; credit both contributors in README/README.zh/CHANGELOG
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
- PR #7 (@ayleen): English UI layer with reactive language switching; balance semantic keys - PR #8 (@wuhuqif176): Bailian/Qwen Token Plan quota query in balance panel - bump to v1.13.0; credit both contributors in README/README.zh/CHANGELOG
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
…een) The login-only noreply form ([email protected]) is not resolved to the ayleen account by GitHub's contributors graph. Use the id+login form so both the repo Contributors graph and git blame attribute the PR #7 i18n commits to @ayleen consistently.
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
- PR #7 (@ayleen): English UI layer with reactive language switching; balance semantic keys - PR #8 (@wuhuqif176): Bailian/Qwen Token Plan quota query in balance panel - bump to v1.13.0; credit both contributors in README/README.zh/CHANGELOG
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
feiyang-dev
pushed a commit
that referenced
this pull request
Aug 27, 2026
…een) The login-only noreply form ([email protected]) is not resolved to the ayleen account by GitHub's contributors graph. Use the id+login form so both the repo Contributors graph and git blame attribute the PR #7 i18n commits to @ayleen consistently.
Contributor
Author
|
@feiyang-dev |
Owner
Thank you, my dear friend. If you find any issues here in the future, please let me know immediately, and I will address them when I have time. Thank you for your experience and support! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(i18n): English UI layer with reactive language switching
English
What this does
Adds a lightweight i18n layer so the whole web panel can be displayed in English while keeping Chinese fully intact — no strings are removed, Chinese remains the fallback and the dictionary keys.
zh→ Chinese, anything else → English).localStorage(dsh-usage-lang).useLang()subscription). Toggling re-renders panels immediately and does not depend on any network request. SUBTABS / transient status messages / client-side validation errors are translated at render time, so even already-visible text follows the current locale.Implementation notes
t(key)resolves via a 260-entry EN map (408 wrapped sites)labelKey/hintKey/meaningKey/sourceNoteKey/balanceLabelKey,credentialHintKey); both locales live client-side (tb())dayLabel/fmtMonthLabel/dailyStatsTitle/weekdayLabels— zh keeps2026年8月22日, en rendersAug 22, 2026,August 2026, Mo–Su headers未找到 DEEPSEEK_API_KEY,请配置后重试,errorCode: missing-credential) — internal keys can no longer leak into user-facing messagesTesting
The new suite loads the real bundle through a stubbed ModuleLoader and covers: instant switch + storage persistence across mounts, date/weekday rendering, transient-message locales, balance-key coverage in both locales, and the missing-credential error shape.
Compatibility
balanceProvidersAPI fieldcredentialHintwas renamed tocredentialHintKey(it now carries a semantic key by design).中文
为 Web 面板新增轻量 i18n 层:完整保留中文,同时支持英文界面。
localStorage2026年8月22日,英文输出Aug 22, 2026、August 2026与 Mo–Su 表头测试:
test/balance.test.js(12 通过)+ 新增test/client-i18n.test.js(7 通过)。Commits:
d2eb6e4feat(i18n): English UI layer with auto-detection and manual toggle028aa4afix(i18n): address review — reactive language, semantic balance keys, locale dates