Skip to content

Add English/Chinese UI internationalization#5

Open
wendaining wants to merge 24 commits into
aadeshrao123:masterfrom
wendaining:master
Open

Add English/Chinese UI internationalization#5
wendaining wants to merge 24 commits into
aadeshrao123:masterfrom
wendaining:master

Conversation

@wendaining

Copy link
Copy Markdown

Summary

This PR adds a lightweight i18n layer for the Tauri UI and translates the existing interface into English and Simplified Chinese.

Changes include:

  • Add i18n.js for locale loading, key lookup, parameter interpolation, DOM translation, and persisted language selection.
  • Add en.json and zh.json translation files with matching nested key structures.
  • Wire static UI copy through data-i18n, data-i18n-placeholder, data-i18n-title, and data-i18n-html.
  • Update dynamic UI rendering in app.js to use t(...) for user-facing text.
  • Add Settings -> General language toggle buttons for English and Chinese.
  • Default new installs to English when no ui_language setting exists.
  • Fix language switching so translated DOM updates happen after async page refresh work completes.
  • Sync custom dropdown labels after translated <option> text changes.
  • Add I18N.md with translation authoring guidelines for future contributors.
  • Fix NSIS uninstall cleanup so selecting "Delete app data" removes Focuser's real ProjectDirs data directory, including saved ui_language and block rules.

Notes

The uninstall cleanup fix is included because stale ui_language and saved block data made fresh-install i18n validation misleading: after uninstalling with "Delete app data", the app could still reopen with the previous language and rules.

Testing

  • node --check crates/focuser-ui/ui/app.js
  • node --check crates/focuser-ui/ui/i18n.js
  • Simulated fresh i18n initialization with no saved ui_language; verified locale defaults to en and dashboard.title resolves to Dashboard.
  • cargo fmt --all -- --check
  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace
  • cargo tauri build --config '{"bundle":{"createUpdaterArtifacts":false}}'

The Tauri build disables updater artifact generation locally because signing requires TAURI_SIGNING_PRIVATE_KEY.

wendaining added 19 commits June 8, 2026 19:24
- Add data-i18n attributes to all hardcoded text in index.html (web page headings, buttons, placeholders, labels, import dropdown, schedule controls, statistics panels)
- Replace hardcoded English strings with t() calls throughout app.js (pomodoro modal, preview, presets, allowance rows, exceptions, block list cards, dashboard empty states)
- Add missing translation keys: websites import/export dropdown, placeholder texts, common.noOptions, statistics.cycleUnit
- Ensure modal titles, confirm dialog buttons, and sidebar status text use i18n
- Chinese translations updated for all new keys
…detect

New users should always see English first. Language can be manually
switched to Chinese in Settings. This prevents a jarring experience
for international users and ensures consistent default behavior.
…r navigateTo

The root cause: _applyToDOM() was called BEFORE navigateTo(). When
navigateTo regenerated page content, the new DOM elements kept their
English fallback text and were never translated.

Fix:
- In setLocale: call navigateTo first (generates new DOM), then
  _applyToDOM (translates the freshly generated static elements)
- Remove duplicate ui.navigateTo in the click handler (setLocale
  already handles navigation)
- Use requestAnimationFrame to ensure DOM paint before translation
Close the Tauri get_setting fallback block so locale normalization and translation JSON loading run after a saved ui_language value is read successfully.
Make navigateTo await its page refresh work so setLocale applies translations after dynamic DOM updates finish. Also sync custom dropdown labels after option text is translated.
When the NSIS delete-app-data checkbox is selected, remove the real Windows ProjectDirs paths used by focuser-ui and focuser-service for focuser.db. Tauri's generated cleanup only removes bundle-id based directories, which left block rules and ui_language behind.
Move ProjectDirs cleanup into the NSIS post-uninstall hook and skip it during update mode, so data is only removed after the app files and running-app checks complete.
Document how JSON translation keys map to data-i18n attributes and t() calls, including key structure, placeholders, locale parity, and review checklist for future i18n work.
@wendaining
wendaining marked this pull request as ready for review June 8, 2026 14:14
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.

1 participant