Skip to content

fix(i18n): persist manual language selection across restarts - #544

Merged
Blankll merged 2 commits into
masterfrom
fix/lang-persistence-and-parity-tests
Nov 13, 2026
Merged

Blankll merged 2 commits into
masterfrom
fix/lang-persistence-and-parity-tests

Conversation

@Blankll

@Blankll Blankll commented Nov 11, 2026

Copy link
Copy Markdown
Member

Follow-up on the review of #542 (zh-TW).

Fix: language choice was never persisted

getStoredLocale() read localStorage['lang'], which nothing in the codebase ever wrote — so a language picked in settings silently reverted to OS auto-detection on the next launch. This was pre-existing (affected zhCN too); for zh-TW users it was masked because auto-detection now happens to resolve to zhTW.

getStoredLocale() now:

  1. validates the lang value (previously cast unchecked),
  2. falls back to the pinia-persisted app.languageType (pinia-plugin-persistedstate default key = store id, verified from the plugin source), so existing users' past choices take effect retroactively — no picker change needed,
  3. degrades gracefully to auto-detection on a corrupted blob.

Tests

  • tests/lang/zhTW.test.ts merged into tests/lang/parity.test.ts: key parity + placeholder checks are now parametrized over zhCN / zhTW, and both get two-direction assertions (en→locale and locale→en no-extra-keys) — stronger than the previous zhCN one-direction check. Adding a future locale is one array entry.
  • tests/lang/index.test.ts extended with the behavior feat(i18n): add Traditional Chinese (zh-TW) #542 introduced but didn't cover: it.each over zh-TW / zh-Hant-TW / zh-Hant / zh-HK / zh-MO → cn, bare zh / en-US → en, plus the three persistence-fallback paths (valid zhTW, invalid value, corrupted JSON).

Verification

  • npx jest — 70 suites / 1983 tests pass
  • npx tsc --noEmit — clean
  • npx eslint on changed files — clean

getStoredLocale() read localStorage['lang'], which nothing ever wrote,
so a language picked in settings silently reverted to OS auto-detection
on the next launch (pre-existing, affecting zhCN as well).

Now it validates the value and falls back to the pinia-persisted
app.languageType, so existing choices take effect retroactively and a
corrupted blob degrades gracefully to auto-detection.

Also consolidates the zh-TW parity test into tests/lang/parity.test.ts
(two-direction key parity + placeholder checks parametrized over both
locales) and covers the new locale auto-detection and persistence
fallback paths in tests/lang/index.test.ts.
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.89%. Comparing base (c112325) to head (bbd6958).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #544      +/-   ##
==========================================
+ Coverage   71.88%   71.89%   +0.01%     
==========================================
  Files         169      169              
  Lines       29735    29743       +8     
  Branches     1479     1482       +3     
==========================================
+ Hits        21376    21385       +9     
  Misses       7909     7909              
+ Partials      450      449       -1     
Files with missing lines Coverage Δ
src/lang/index.ts 100.00% <100.00%> (+5.00%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Blankll
Blankll merged commit b55ad66 into master Nov 13, 2026
9 checks passed
@Blankll
Blankll deleted the fix/lang-persistence-and-parity-tests branch November 13, 2026 01:42
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