← Back to PRs

#21619: fix(i18n): load saved locale translations on page refresh

by zerone0x open 2026-02-20 05:15 View on GitHub →
app: web-ui size: S experienced-contributor
## Summary Dashboard language setting doesn't persist after page refresh. The dropdown shows the correct locale (e.g. 简体中文), but all content renders in English. ## Root Cause `I18nManager.loadLocale()` reads the saved locale from localStorage and sets `this.locale`, but never loads the corresponding translation file. Only English translations are available at construction time (`{ en }`). So `t()` always falls back to English for non-English locales on page load. ## Fix - Extract translation loading into a shared `loadTranslations()` method - Call it eagerly from `loadLocale()` when a non-English locale is detected - `setLocale()` now reuses the same method (deduplicates the import logic) - `notify()` is called after eager load so Lit controllers re-render with the correct locale ## Testing All 4 existing i18n tests pass: ``` ✓ chromium src/i18n/test/translate.test.ts (4 tests) 19ms ``` Fixes #21567 <!-- greptile_comment --> <h3>Greptile Summary</h3> Refactored i18n initialization to eagerly load saved locale translations on page refresh. Previously, `loadLocale()` read the saved locale from localStorage but never loaded the corresponding translation files, causing `t()` to always fall back to English. The fix extracts translation loading into a shared `loadTranslations()` method that is called both during initialization (for non-English locales) and when changing locales via `setLocale()`. The async loading pattern with `notify()` ensures Lit controllers re-render when translations finish loading. - Extracted duplicate import logic into `loadTranslations()` method - Added eager loading in `loadLocale()` for non-English locales - Maintained backward compatibility with existing test suite - Used fire-and-forget pattern (`void`) for async initialization, relying on reactive `notify()` to trigger re-renders when ready <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Clean refactoring that extracts duplicate code, preserves existing test coverage (all 4 tests pass), and follows established patterns. The async loading approach with reactive notifications is appropriate for the Lit-based UI. No breaking changes or security concerns. - No files require special attention <sub>Last reviewed commit: e3d6fc0</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs