Files
testing-tool/.github/I18N.md
T

43 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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` 无法动态切换语言,语言跟随浏览器设置,切换后需刷新页面