Files
new-api/web/src/lib/index.ts
t0ng7u 2e994abdd9 🌍 feat: implement complete i18n for Dashboard module
Migrate Dashboard module from hardcoded text to full internationalization
support with Chinese and English translations.

## Changes Made

### Dashboard Components i18n Implementation
- **Dashboard main page** (`index.tsx`): Added i18n for page title, welcome message,
  search button, tab labels, and toast notifications
- **StatsCards** (`stats-cards.tsx`): Implemented i18n for 4 grouped cards with
  8 data metrics (account data, usage stats, resource consumption, performance metrics)
- **Overview** (`overview.tsx`): Added i18n for chart titles, tooltips, and error states
- **ModelUsageChart** (`model-usage-chart.tsx`): Implemented i18n for chart content
  and status messages
- **ModelMonitoringStats** (`model-monitoring-stats.tsx`): Added i18n for monitoring
  statistics cards and descriptions
- **ModelMonitoringTable** (`model-monitoring-table.tsx`): Implemented i18n for table
  headers, pagination, search functionality, and action menus

### Language Files Updates
- **Chinese** (`zh.json`): Added comprehensive Dashboard translations with proper
  key structure and interpolation support
- **English** (`en.json`): Added complete English translations with consistent
  terminology and interpolation variables

### Key Structure Improvements
- Organized i18n keys in logical hierarchy: `dashboard.stats.*`, `dashboard.overview.*`,
  `dashboard.model_usage.*`, `dashboard.monitoring.*`, `dashboard.search.*`
- Added common UI elements to `common.*` namespace for reusability
- Support for interpolation variables (e.g., `{{name}}`, `{{count}}`, `{{percentage}}`)

### Bug Fixes
- **Fixed duplicate JSON keys**: Resolved conflicts between `dashboard.search` (string)
  and `dashboard.search` (object) by renaming to `dashboard.search_button`
- **Fixed duplicate overview keys**: Resolved conflicts between `dashboard.overview`
  (string) and `dashboard.overview` (object) by renaming to `dashboard.overview_tab`
- Updated component references to use corrected i18n keys

### Technical Features
- Full React i18next integration with `useTranslation` hook
- Maintains accessibility standards and semantic HTML structure
- Consistent error handling and loading states across all components
- Support for plural forms and complex interpolation scenarios

## Breaking Changes
None - All changes are additive and maintain backward compatibility.

## Testing
-  JSON validation for both language files
-  No linter errors in Dashboard components
-  No duplicate keys in translation files
-  All i18n keys properly referenced in components

Closes: Dashboard i18n migration task
2025-09-26 13:10:50 +08:00

108 lines
1.7 KiB
TypeScript

/**
* 工具函数统一导出
* 提供便捷的导入方式
*/
// 通用工具
export { cn, sleep, getPageNumbers } from './utils'
// 颜色工具
export {
stringToColor,
stringToRgbColor,
modelToColor,
getRatioColor,
getGroupColor,
generateHexColor,
isDarkColor,
} from './colors'
// 格式化工具
export {
timestamp2string,
timestamp2string1,
getRelativeTime,
formatDateString,
formatDateTimeString,
renderText,
formatQuota,
formatNumber,
formatTokens,
formatPercentage,
formatBytes,
getTodayStartTimestamp,
removeTrailingSlash,
formatPrice,
formatApiCalls,
truncateText,
formatCurrency,
formatChartTimestamp,
formatValue,
formatBalance,
calculateUsagePercentage,
} from './formatters'
// 验证工具
export {
verifyJSON,
verifyJSONPromise,
toBoolean,
isValidEmail,
isValidUrl,
isValidPhone,
validatePasswordStrength,
isValidIP,
isValidPort,
isValidDomain,
isValidUsername,
isValidApiKey,
isValidModelName,
isInRange,
isPositiveInteger,
isNonNegativeNumber,
deepEqual,
sanitizeText,
} from './validators'
// 剪贴板工具
export {
copy,
paste,
isClipboardSupported,
copyJSON,
copyAsCSV,
copyLink,
copyCode,
} from './clipboard'
// 对象比较工具
export {
compareObjects,
getDifference,
deepMerge,
deepClone,
isEmpty,
pick,
omit,
flatten,
unflatten,
} from './comparisons'
// 认证相关
export {
setStoredUser,
getStoredUser,
getStoredUserId,
clearStoredUser,
isAdmin,
} from './auth'
// Cookie相关
export { setCookie, getCookie, removeCookie } from './cookies'
// HTTP客户端
export { http } from './http'
// 错误处理
export { handleServerError } from './handle-server-error'