refactor: 迁移 i18n 系统从 react-i18next 到 chrome.i18n

- 移除 react-i18next、i18next 及相关依赖
- 删除旧的 i18n/ 目录和 useLazyTranslation 工具
- 新增 utils/chromeI18n.ts 类型安全 wrapper(useI18n Hook + getMessage)
- 生成 public/_locales/{zh,en}/messages.json(298 个翻译 key)
- 批量更新 39+ 组件文件的导入和翻译调用
- 转换翻译键格式:namespace:key → namespace_key
- 修复 ErrorBoundary/PageErrorBoundary 从 withTranslation HOC 改为直接调用 getMessage
- 更新 vitest.setup.ts mock 加载实际翻译文本
- 修复 11 个测试文件的断言以匹配中文翻译
- TypeScript、ESLint、547 项测试全部通过

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
雨霖铃
2026-05-28 19:21:54 +08:00
parent 64e23994a6
commit aa23a263fe
94 changed files with 2987 additions and 1844 deletions
+6 -6
View File
@@ -2,7 +2,7 @@
* JWT 解析工具
*/
import i18n from '@/i18n';
import { getMessage } from '@/utils/chromeI18n';
export interface JwtHeader {
alg: string;
@@ -43,7 +43,7 @@ export function decodeBase64Url(str: string): string {
const pad = base64.length % 4;
if (pad) {
if (pad === 1) {
throw new Error(i18n.t('jwt:errors.invalidBase64String'));
throw new Error(getMessage('jwt_errors_invalidBase64String'));
}
base64 += new Array(5 - pad).join('=');
}
@@ -59,7 +59,7 @@ export function decodeBase64Url(str: string): string {
return decoder.decode(bytes);
} catch (e) {
throw new Error(
i18n.t('jwt:errors.failedToDecode') + (e instanceof Error ? e.message : String(e)),
getMessage('jwt_errors_failedToDecode') + (e instanceof Error ? e.message : String(e)),
{ cause: e },
);
}
@@ -78,7 +78,7 @@ export function parseJwt(token: string): JwtResult {
payload: null,
signature: '',
raw: { header: '', payload: '', signature: '' },
error: i18n.t('jwt:errors.invalidFormat'),
error: getMessage('jwt_errors_invalidFormat'),
};
}
@@ -99,7 +99,7 @@ export function parseJwt(token: string): JwtResult {
result.header = JSON.parse(headerJson);
} catch (e) {
result.error =
i18n.t('jwt:errors.parseHeaderFailed') + (e instanceof Error ? e.message : String(e));
getMessage('jwt_errors_parseHeaderFailed') + (e instanceof Error ? e.message : String(e));
return result;
}
@@ -108,7 +108,7 @@ export function parseJwt(token: string): JwtResult {
result.payload = JSON.parse(payloadJson);
} catch (e) {
result.error =
i18n.t('jwt:errors.parsePayloadFailed') + (e instanceof Error ? e.message : String(e));
getMessage('jwt_errors_parsePayloadFailed') + (e instanceof Error ? e.message : String(e));
return result;
}