refactor: 优化 i18n 类型安全与渲染性能
- 导出 TranslationKey 类型,翻译 key 拼写错误编译期即报错 - zh.ts 使用 TranslationKey 约束,确保中英文 key 同步 - useMemo 包装 context value,避免不必要的全局重渲染 - ConfirmDialog confirmText 默认值改用 t() 而非硬编码英文 - SchemaProperties 递归组件改为 prop 传递 t,减少 useContext 调用 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useTheme } from '../lib/theme';
|
||||
import { useI18n } from '../lib/i18n';
|
||||
import { useI18n, type TranslationKey } from '../lib/i18n';
|
||||
|
||||
const icons = {
|
||||
light: (
|
||||
@@ -31,7 +31,7 @@ export default function ThemeToggle() {
|
||||
<button
|
||||
key={key}
|
||||
onClick={() => setTheme(key)}
|
||||
title={t(`theme.${key}`)}
|
||||
title={t(`theme.${key}` as TranslationKey)}
|
||||
className={`flex items-center justify-center w-8 h-7 rounded-md transition-all duration-150 ${
|
||||
theme === key
|
||||
? 'bg-bg-elevated text-text-primary shadow-sm'
|
||||
|
||||
Reference in New Issue
Block a user