refactor(i18n): 移除 chrome.i18n 国际化,统一使用中文硬编码
移除 chromeI18n 工具、_locales 翻译文件和 manifest default_locale 配置, 将所有 UI 文案改为直接硬编码中文,并更新相关测试与文档。
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
# i18n 开发指南
|
||||
|
||||
## 概述
|
||||
|
||||
项目使用 Chrome 扩展标准的 `chrome.i18n` API 进行本地化,通过 `src/utils/chromeI18n.ts` 提供类型安全的 React Hook 包装。
|
||||
|
||||
## 配置
|
||||
|
||||
- **翻译文件**: `public/_locales/{zh_CN,en}/messages.json`(Chrome 扩展标准格式)
|
||||
- **默认语言**: `zh_CN`(在 `wxt.config.ts` 的 `manifest.default_locale` 中配置)
|
||||
|
||||
## 使用方式
|
||||
|
||||
```typescript
|
||||
import { useI18n } from '@/utils/chromeI18n';
|
||||
```
|
||||
|
||||
## 翻译键格式
|
||||
|
||||
- **直接 key**: `t('dashboard_title')` → 查找 `dashboard_title`
|
||||
- **命名空间格式(兼容旧用法)**: `t('common:buttons.search')` → 查找 `common_buttons_search`
|
||||
- **带命名空间参数**: `useI18n(['common', 'features'])`,会自动尝试 `common_key`、`features_key`
|
||||
|
||||
## 占位符支持
|
||||
|
||||
```typescript
|
||||
t('router_notFoundDescription', { entryPointType: 'popup' });
|
||||
```
|
||||
|
||||
## Hook 返回值
|
||||
|
||||
```typescript
|
||||
{ t, i18n: { language, changeLanguage }, isLoaded }
|
||||
```
|
||||
|
||||
## 回退策略
|
||||
|
||||
当翻译 key 未命中时,返回 key 本身(开发模式下在控制台记录 warning)
|
||||
|
||||
## 限制
|
||||
|
||||
`chrome.i18n` 无法动态切换语言,语言跟随浏览器设置,切换后需刷新页面
|
||||
Reference in New Issue
Block a user