Skip to content

fix: language toggle doesn't update dynamically rendered components#6

Merged
zihenghe04 merged 5 commits into
zihenghe04:masterfrom
ashleyleslie1:fix/i18n-language-toggle
Apr 7, 2026
Merged

fix: language toggle doesn't update dynamically rendered components#6
zihenghe04 merged 5 commits into
zihenghe04:masterfrom
ashleyleslie1:fix/i18n-language-toggle

Conversation

@ashleyleslie1

@ashleyleslie1 ashleyleslie1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes several i18n and theme issues where dynamically rendered components don't update on language or theme toggle.

Language toggle fixes

  • Default language now uses navigator.language instead of hardcoded 'zh', so non-Chinese users see English on first visit
  • toggleLang() now re-renders all dynamic components: rhythm bars, work mode, model DNA, efficiency trend, insights, overview, report, git stats, MCP stats, tools
  • lastUp timestamp switches between "Updated" / "更新于" on toggle (with null-safe getElementById)
  • Translated hardcoded 'msgs' and '/day' strings

Theme toggle fixes

  • toggleTheme() now re-renders all dynamic components so chart colors, text, and tooltips update on dark/light switch
  • Added theme:dk?'dark':'light' to 5 ApexCharts tooltip configs that were missing it (fixes white-on-white tooltips in dark mode)

Windows compatibility

  • Force UTF-8 stdout/stderr at startup (fixes crash from Chinese print statements on Windows cp1252)
  • open(HISTORY_FILE, encoding='utf-8', errors='replace') (fixes startup crash on Windows)

Test plan

  • Language toggle zh → en: all components update immediately
  • Language toggle en → zh: all components update immediately
  • Fresh visit (cleared localStorage): defaults to English for non-Chinese browsers
  • Theme toggle dark → light: all charts, tooltips, donut text update
  • Theme toggle light → dark: same
  • Tooltip readability in dark mode on all chart types
  • Tested on Windows 11, Python 3.13.7, Chrome

On Windows, Python defaults to the system encoding (cp1252) when opening
files without an explicit encoding parameter. Since Claude Code writes
history.jsonl as UTF-8, this causes a UnicodeDecodeError on startup:

  UnicodeEncodeError: 'charmap' codec can't encode characters

This matches the encoding pattern already used throughout the rest of
server.py for JSONL file reads.
- Default language now detects browser locale instead of hardcoding 'zh',
  so non-Chinese users see English on first visit
- Language toggle now re-renders all dynamically built components
  (rhythm bars, work mode, model DNA, efficiency, insights, overview)
  that were previously stuck in the initial language
- lastUp timestamp updates on toggle with null-safe getElementById
…n re-renders

- Force UTF-8 stdout/stderr at startup for Windows compatibility
- Include open(HISTORY_FILE) encoding fix from PR zihenghe04#5
- Add tooltip theme to all ApexCharts instances (fixes white-on-white in dark mode)
- Re-render report, git stats, MCP stats, tools on language toggle
- Translate hardcoded 'msgs' and '/day' strings
toggleTheme() only called renderCharts(), leaving all other ApexCharts
instances (tools, MCP, efficiency, overview donuts) stuck with the
previous theme's colors. Added re-renders for all dynamic components.
@zihenghe04 zihenghe04 merged commit 336968f into zihenghe04:master Apr 7, 2026
@zihenghe04

Copy link
Copy Markdown
Owner

Thanks for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants