i18n and UI fix
This commit is contained in:
47
.sisyphus/notepads/i18n-integration/issues.md
Normal file
47
.sisyphus/notepads/i18n-integration/issues.md
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
## [2026-03-14] Locale Not Synced Between Processes
|
||||
|
||||
### 问题描述
|
||||
Renderer process 和 Main process 的 locale 状态没有同步。
|
||||
|
||||
### 复现步骤
|
||||
1. 用户在 UI 中切换语言 (例如从 zh-CN 到 en-US)
|
||||
2. localeStore 更新 localStorage,i18next 切换语言
|
||||
3. 但是 Main process 的 `config.json` 仍然是旧值
|
||||
4. Main process 的错误消息使用旧语言
|
||||
|
||||
### 根本原因
|
||||
- `localeStore.setLocale()` 只更新 Zustand state
|
||||
- 没有调用 `window.api.setLocale()` 同步到 Main process
|
||||
|
||||
### 解决方案
|
||||
需要在以下位置添加同步逻辑:
|
||||
|
||||
1. **localeStore.ts**: 修改 `setLocale` action
|
||||
```typescript
|
||||
setLocale: async (locale) => {
|
||||
set({ locale });
|
||||
await window.api.setLocale({ locale });
|
||||
}
|
||||
```
|
||||
|
||||
2. **App.tsx**: 在初始化时从 Main process 读取 locale
|
||||
```typescript
|
||||
useEffect(() => {
|
||||
const initLocale = async () => {
|
||||
const result = await window.api.getLocale();
|
||||
if (result.success) {
|
||||
useLocaleStore.getState().setLocale(result.data);
|
||||
i18n.changeLanguage(result.data);
|
||||
}
|
||||
};
|
||||
initLocale();
|
||||
}, []);
|
||||
```
|
||||
|
||||
### 影响范围
|
||||
- `src/renderer/src/stores/localeStore.ts`
|
||||
- `src/renderer/src/App.tsx` 或 `src/renderer/src/main.tsx`
|
||||
|
||||
### 优先级
|
||||
高 - 影响用户体验,Main process 错误消息语言不一致
|
||||
Reference in New Issue
Block a user